diff --git a/src/auth/PhutilAuthAdapterOAuthGoogle.php b/src/auth/PhutilAuthAdapterOAuthGoogle.php --- a/src/auth/PhutilAuthAdapterOAuthGoogle.php +++ b/src/auth/PhutilAuthAdapterOAuthGoogle.php @@ -14,11 +14,21 @@ } public function getAccountID() { - return $this->getOAuthAccountData('email'); + $emails = $this->getOAuthAccountData('emails', array()); + foreach ($emails as $email) { + if (idx($email, 'type') == 'account') { + return idx($email, 'value'); + } + } + + throw new Exception( + pht( + 'Expected to retrieve an "account" email from Google Plus API call ', + 'to identify account, but failed.')); } public function getAccountEmail() { - return $this->getOAuthAccountData('email'); + return $this->getAccountID(); } public function getAccountName() { @@ -38,7 +48,20 @@ } public function getAccountRealName() { - return $this->getOAuthAccountData('name'); + $name = $this->getOAuthAccountData('name', array()); + + // TODO: This could probably be made cleaner by looking up the API, but + // this should work to unbreak logins. + + $parts = array(); + $parts[] = idx($name, 'givenName'); + unset($name['givenName']); + $parts[] = idx($name, 'familyName'); + unset($name['familyName']); + $parts = array_merge($parts, $name); + $parts = array_filter($parts); + + return implode(' ', $parts); } protected function getAuthenticateBaseURI() { @@ -51,8 +74,8 @@ public function getScope() { $scopes = array( - 'https://www.googleapis.com/auth/userinfo.email', - 'https://www.googleapis.com/auth/userinfo.profile', + 'email', + 'profile', ); return implode(' ', $scopes); @@ -71,7 +94,7 @@ } protected function loadOAuthAccountData() { - $uri = new PhutilURI('https://www.googleapis.com/oauth2/v1/userinfo'); + $uri = new PhutilURI('https://www.googleapis.com/plus/v1/people/me'); $uri->setQueryParam('access_token', $this->getAccessToken()); $future = new HTTPSFuture($uri);