Permalink
Browse files

Updated Google module to use OAuth 2.0 identity APIs instead of Googl…

…e Plus APIs which are getting deprecated as Google Plus is shut down.
  • Loading branch information...
sergeychernyshev committed Feb 4, 2019
1 parent 9402559 commit c40e642c6de797d27f99a4cf07001a7ccfcee376
Showing with 17 additions and 13 deletions.
  1. +5 −7 modules/google/index.php
  2. +12 −6 users_config.sample.php
@@ -13,7 +13,7 @@ class GoogleAuthenticationModule extends OAuth2AuthenticationModule
protected $userCredentialsClass = 'GoogleUserCredentials';
public function __construct($oAuth2ClientID, $oAuth2ClientSecret,
$scopes = 'profile'
$scopes = 'https://www.googleapis.com/auth/userinfo.profile'
) {
parent::__construct(
'Google',
@@ -73,7 +73,7 @@ public function getIdentity($oauth2_client_id) {
$credentials = $this->getOAuth2Credentials($oauth2_client_id);
try {
$result = $credentials->makeOAuth2Request('https://www.googleapis.com/plus/v1/people/me');
$result = $credentials->makeOAuth2Request('https://www.googleapis.com/oauth2/v2/userinfo');
} catch (OAuth2Exception $ex) {
return null;
}
@@ -106,17 +106,15 @@ public function getIdentity($oauth2_client_id) {
}
$user_info = $data;
if (array_key_exists('id', $user_info) && array_key_exists('displayName', $user_info)
) {
$user_info['name'] = $user_info['displayName'];
} else {
UserTools::debug("Don't have ID or displayName: " . var_export($user_info, true));
if (!array_key_exists('id', $user_info) || !array_key_exists('name', $user_info)) {
UserTools::debug("Don't have ID or name: " . var_export($user_info, true));
return null;
}
if (array_key_exists('emails', $user_info) && count($user_info['emails'] > 0)) {
$user_info['email'] = $user_info['emails'][0]['value'];
}
return $user_info;
}
@@ -89,19 +89,25 @@
*
* And then uncomment lines below and copy Client ID and Client Secret
* Optional 3rd parameter is an array of API scopes you need authorization for.
* See Google's explanation for scopes here: https://developers.google.com/+/web/api/rest/oauth#authorization-scopes
* See Google's explanation for scopes here: https://developers.google.com/identity/protocols/googlescopes
* See up-to-date list of APIs and scopes here: https://developers.google.com/oauthplayground/
* (One of /Google Contacts API scope is required and is included by default)
*
* Google Oauth2 "https://www.googleapis.com/auth/userinfo.profile" scope is required
* and included by default, but you need to explicitly specify it if you add other scopes.
*
* You can also add "https://www.googleapis.com/auth/userinfo.email" scope
* if you want to get user's email address.
*
* Your personal OAuth authorizations are recorded here to be used for debugging:
* https://myaccount.google.com/permissions
*/
#UserConfig::loadModule('google');
#new GoogleAuthenticationModule(
# '...OAuth2.client.id.goes.here...',
# '...OAuth2.clientsecret.goes.here...',
# array(
# 'profile',
# 'email',
# 'https://www.googleapis.com/auth/plus.login',
# 'https://www.googleapis.com/auth/plus.profile.emails.read'
# 'https://www.googleapis.com/auth/userinfo.profile',
# 'https://www.googleapis.com/auth/userinfo.email',
# )
#);

0 comments on commit c40e642

Please sign in to comment.