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); }