Identification by Google
The identification form can automatically accept a user who is connected with a Google account with an email address registered in the DB. The registration form can directly obtain the email address and optionally the first name and the last name of a user who is connected with a Google account.
Configuration
Google Console - https://console.cloud.google.com
Go to APIs & Services.
Click on the project selector to the right of the logo Google Cloud. Click on NEW PROJECT.
Create a project for the website, e.g. sitename
.
Select the new project.
Go to OAuth consent screen.
Select External. Press CREATE.
Fill in the required information on the page OAuth consent screen. Save the page Scopes with no sensitive scopes. Add the email of a test user.Go to Credentials. Click on CREATE CREDENTIALS. Click on OAuth Client Id.
Create a credential for a Web application, e.g.sitename
.
Specify the URL of the web site in Authorized JavaScript origins, e.g. https://www.sitename.com, and a local URL for the development stie, e.g. https://local.sitename.com.
Configure the parameter $googleclientid
in config.inc with the Client ID of the key.
Installation of the code from Google
Verify the Google ID token on your server side
Install Composer:
$ sudo apt install composer
At the root of the website, edit the file compose.json:
{
"require": {
"google/apiclient": "^2.15"
},
"scripts": {
"pre-autoload-dump": "Google\\Task\\Composer::cleanup"
},
"extra": {
"google/apiclient-services": [
"Oauth2"
]
}
}
Install the API keeping just the Oauth2 component:
$ composer update
All the code is in the directory vendor.
NOTE: Add the file composer.json to Git. Add the directory vendor and the file composer.lock in .gitignore.
If you use rsync
to sync the development site with the production site, exclude the folder vendor and the file composer.lock and run a composer update
on the production site after an update of the file composer.json.
Test
Try to log in the website with Google using the test email.
IMPORTANT: The parameter $with_google
in the blocks login
and register
is true
if $googlecreditid
isn't false
.
Google Console - https://console.cloud.google.com
Go to APIs & Services. Select the project. Go to OAuth consent screen.
Click on PUBLISH APP. Press CONFIRM.
Click on PREPARE FOR VERIFICATION. Check and save all the pages. Press SUBMIT FOR VERIFICATION.
Comments