From 7ac5abb97934f7399b67762aa98f59f667711bf3 Mon Sep 17 00:00:00 2001 From: Evan Priestley Date: Tue, 15 Jul 2014 13:39:56 -0700 Subject: [PATCH] Recover from a broken external OAuth2 account Summary: Currently, the external accounts page can die in a fire if an OAuth2 link is bad. Instead of exploding, just fail the specific link. Test Plan: Faked an error and got "invalid token" instead of an exception. Reviewers: btrahan, chad Reviewed By: chad Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D9937 --- .../provider/PhabricatorAuthProviderOAuth2.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/applications/auth/provider/PhabricatorAuthProviderOAuth2.php b/src/applications/auth/provider/PhabricatorAuthProviderOAuth2.php index 0388e475f2..a2d9ecc831 100644 --- a/src/applications/auth/provider/PhabricatorAuthProviderOAuth2.php +++ b/src/applications/auth/provider/PhabricatorAuthProviderOAuth2.php @@ -239,8 +239,17 @@ abstract class PhabricatorAuthProviderOAuth2 PHUIObjectItemView $item, PhabricatorExternalAccount $account) { - // Get a valid token, possibly refreshing it. - $oauth_token = $this->getOAuthAccessToken($account); + // Get a valid token, possibly refreshing it. If we're unable to refresh + // it, render a message to that effect. The user may be able to repair the + // link by manually reconnecting. + + $is_invalid = false; + try { + $oauth_token = $this->getOAuthAccessToken($account); + } catch (Exception $ex) { + $oauth_token = null; + $is_invalid = true; + } $item->addAttribute(pht('OAuth2 Account')); @@ -256,6 +265,8 @@ abstract class PhabricatorAuthProviderOAuth2 pht( 'Active OAuth Token')); } + } else if ($is_invalid) { + $item->addAttribute(pht('Invalid OAuth Access Token')); } else { $item->addAttribute(pht('No OAuth Access Token')); }