From e826842179b78e7ece7a3dda3ed74b3c7c3cd526 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 24 Jun 2013 15:57:39 -0700 Subject: [PATCH] Show more information about OAuth tokens in the Account Settings -> External Accounts screen Summary: Ref T1536. - Allow providers to customize the look of external accounts. - For username/password auth, don't show the account view (it's confusing and not useful). - For OAuth accounts, show token status. Test Plan: {F47374} {F47375} Reviewers: btrahan, chad Reviewed By: btrahan CC: aran Maniphest Tasks: T1536 Differential Revision: https://secure.phabricator.com/D6289 --- .../auth/provider/PhabricatorAuthProvider.php | 18 +++++++++++ .../provider/PhabricatorAuthProviderOAuth.php | 30 +++++++++++++++++++ .../PhabricatorAuthProviderPassword.php | 7 +++++ ...abricatorSettingsPanelExternalAccounts.php | 13 +------- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/applications/auth/provider/PhabricatorAuthProvider.php b/src/applications/auth/provider/PhabricatorAuthProvider.php index faa878d4a8..e73cda8e36 100644 --- a/src/applications/auth/provider/PhabricatorAuthProvider.php +++ b/src/applications/auth/provider/PhabricatorAuthProvider.php @@ -320,4 +320,22 @@ abstract class PhabricatorAuthProvider { return; } + public function willRenderLinkedAccount( + PhabricatorUser $viewer, + PhabricatorObjectItemView $item, + PhabricatorExternalAccount $account) { + + $account_view = id(new PhabricatorAuthAccountView()) + ->setExternalAccount($account) + ->setAuthProvider($this); + + $item->appendChild( + phutil_tag( + 'div', + array( + 'class' => 'mmr mml mst mmb', + ), + $account_view)); + } + } diff --git a/src/applications/auth/provider/PhabricatorAuthProviderOAuth.php b/src/applications/auth/provider/PhabricatorAuthProviderOAuth.php index 16b45d53cb..97c2687edb 100644 --- a/src/applications/auth/provider/PhabricatorAuthProviderOAuth.php +++ b/src/applications/auth/provider/PhabricatorAuthProviderOAuth.php @@ -343,4 +343,34 @@ abstract class PhabricatorAuthProviderOAuth extends PhabricatorAuthProvider { return null; } + public function willRenderLinkedAccount( + PhabricatorUser $viewer, + PhabricatorObjectItemView $item, + PhabricatorExternalAccount $account) { + + // Get a valid token, possibly refreshing it. + $oauth_token = $this->getOAuthAccessToken($account); + + $item->addAttribute(pht('OAuth2 Account')); + + if ($oauth_token) { + $oauth_expires = $account->getProperty('oauth.token.access.expires'); + if ($oauth_expires) { + $item->addAttribute( + pht( + 'Active OAuth Token (Expires: %s)', + phabricator_datetime($oauth_expires, $viewer))); + } else { + $item->addAttribute( + pht( + 'Active OAuth Token')); + } + } else { + $item->addAttribute(pht('No OAuth Access Token')); + } + + parent::willRenderLinkedAccount($viewer, $item, $account); + } + + } diff --git a/src/applications/auth/provider/PhabricatorAuthProviderPassword.php b/src/applications/auth/provider/PhabricatorAuthProviderPassword.php index 0ed88fd599..e5a40752b0 100644 --- a/src/applications/auth/provider/PhabricatorAuthProviderPassword.php +++ b/src/applications/auth/provider/PhabricatorAuthProviderPassword.php @@ -239,4 +239,11 @@ final class PhabricatorAuthProviderPassword return null; } + public function willRenderLinkedAccount( + PhabricatorUser $viewer, + PhabricatorObjectItemView $item, + PhabricatorExternalAccount $account) { + return; + } + } diff --git a/src/applications/settings/panel/PhabricatorSettingsPanelExternalAccounts.php b/src/applications/settings/panel/PhabricatorSettingsPanelExternalAccounts.php index 6cf3f42da9..755fb1edd6 100644 --- a/src/applications/settings/panel/PhabricatorSettingsPanelExternalAccounts.php +++ b/src/applications/settings/panel/PhabricatorSettingsPanelExternalAccounts.php @@ -77,21 +77,10 @@ final class PhabricatorSettingsPanelExternalAccounts ->setDisabled(!$can_unlink) ->setHref('/auth/unlink/'.$account->getProviderKey().'/')); - $account_view = id(new PhabricatorAuthAccountView()) - ->setExternalAccount($account); - if ($provider) { - $account_view->setAuthProvider($provider); + $provider->willRenderLinkedAccount($viewer, $item, $account); } - $item->appendChild( - phutil_tag( - 'div', - array( - 'class' => 'mmr mml mst mmb', - ), - $account_view)); - $linked->addItem($item); }