From d0f4554dbeb0179408e54077c3ffbcfafa7b0b98 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 24 Feb 2020 13:21:07 -0800 Subject: [PATCH] Read both email addresses and Google Account IDs from Google OAuth Summary: Ref T13493. Google returns a lower-quality account identifier ("email") and a higher-quality account identifier ("id"). We currently read only "email". Change the logic to read both "email" and "id", so that if Google ever moves away from "email" the transition will be a bit easier. Test Plan: Linked/unlinked a Google account, looked at the external account identifier table. Maniphest Tasks: T13493 Differential Revision: https://secure.phabricator.com/D21028 --- .../auth/adapter/PhutilGoogleAuthAdapter.php | 19 +++++++++++++++++-- .../auth/provider/PhabricatorAuthProvider.php | 7 ------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/applications/auth/adapter/PhutilGoogleAuthAdapter.php b/src/applications/auth/adapter/PhutilGoogleAuthAdapter.php index 11c10087ba..54eaf3337c 100644 --- a/src/applications/auth/adapter/PhutilGoogleAuthAdapter.php +++ b/src/applications/auth/adapter/PhutilGoogleAuthAdapter.php @@ -13,8 +13,23 @@ final class PhutilGoogleAuthAdapter extends PhutilOAuthAuthAdapter { return 'google.com'; } - public function getAccountID() { - return $this->getAccountEmail(); + protected function newAccountIdentifiers() { + $identifiers = array(); + + $account_id = $this->getOAuthAccountData('id'); + if ($account_id !== null) { + $account_id = sprintf( + 'id(%s)', + $account_id); + $identifiers[] = $this->newAccountIdentifier($account_id); + } + + $email = $this->getAccountEmail(); + if ($email !== null) { + $identifiers[] = $this->newAccountIdentifier($email); + } + + return $identifiers; } public function getAccountEmail() { diff --git a/src/applications/auth/provider/PhabricatorAuthProvider.php b/src/applications/auth/provider/PhabricatorAuthProvider.php index cfc028441c..735dd42b4b 100644 --- a/src/applications/auth/provider/PhabricatorAuthProvider.php +++ b/src/applications/auth/provider/PhabricatorAuthProvider.php @@ -204,13 +204,6 @@ abstract class PhabricatorAuthProvider extends Phobject { get_class($this))); } - if (count($identifiers) !== 1) { - throw new Exception( - pht( - 'Unexpected number of account identifiers returned (by class "%s").', - get_class($this))); - } - $config = $this->getProviderConfig(); $viewer = PhabricatorUser::getOmnipotentUser();