1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-20 02:38:39 +01:00

Handle refreshing profile image with expired OAuth token

Summary:
If OAuth token is expired then refreshing profile image doesn't work.
This diffs solves it this way:

- Hide Refresh Profile Image button with expired token.
- Display Refresh Token with expired token.
- Update token after logging-in.

Test Plan:
Wait until token expires.
/settings/page/facebook/ - no Refresh Profile Image button.
Refresh Token.
Refresh Profile Image.

Reviewers: epriestley, jungejason

Reviewed By: epriestley

CC: michalburger1, aran, Koolvin

Differential Revision: https://secure.phabricator.com/D2281
This commit is contained in:
vrana 2012-04-18 21:30:40 -07:00
parent 204b6694af
commit 9be054443f
2 changed files with 44 additions and 22 deletions

View file

@ -91,6 +91,7 @@ final class PhabricatorOAuthLoginController
return id(new AphrontDialogResponse())->setDialog($dialog); return id(new AphrontDialogResponse())->setDialog($dialog);
} else { } else {
$this->saveOAuthInfo($oauth_info); // Refresh token.
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())
->setURI('/settings/page/'.$provider_key.'/'); ->setURI('/settings/page/'.$provider_key.'/');
} }

View file

@ -26,6 +26,28 @@ final class PhabricatorUserOAuthSettingsPanelController
return $this; return $this;
} }
private function prepareAuthForm(AphrontFormView $form) {
$provider = $this->provider;
$auth_uri = $provider->getAuthURI();
$client_id = $provider->getClientID();
$redirect_uri = $provider->getRedirectURI();
$minimum_scope = $provider->getMinimumScope();
$form
->setAction($auth_uri)
->setMethod('GET')
->addHiddenInput('redirect_uri', $redirect_uri)
->addHiddenInput('client_id', $client_id)
->addHiddenInput('scope', $minimum_scope);
foreach ($provider->getExtraAuthParameters() as $key => $value) {
$form->addHiddenInput($key, $value);
}
return $form;
}
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $user = $request->getUser();
@ -56,27 +78,15 @@ final class PhabricatorUserOAuthSettingsPanelController
'Phabricator account. You can link an account, which will allow you '. 'Phabricator account. You can link an account, which will allow you '.
'to use it to log into Phabricator.</p>'); 'to use it to log into Phabricator.</p>');
$auth_uri = $provider->getAuthURI(); $this->prepareAuthForm($form);
$client_id = $provider->getClientID();
$redirect_uri = $provider->getRedirectURI();
$minimum_scope = $provider->getMinimumScope();
$form
->setAction($auth_uri)
->setMethod('GET')
->addHiddenInput('redirect_uri', $redirect_uri)
->addHiddenInput('client_id', $client_id)
->addHiddenInput('scope', $minimum_scope);
foreach ($provider->getExtraAuthParameters() as $key => $value) {
$form->addHiddenInput($key, $value);
}
$form $form
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue('Link '.$provider_name." Account \xC2\xBB")); ->setValue('Link '.$provider_name." Account \xC2\xBB"));
} else { } else {
$expires = $oauth_info->getTokenExpires();
$form $form
->appendChild( ->appendChild(
'<p class="aphront-form-instructions">Your account is linked with '. '<p class="aphront-form-instructions">Your account is linked with '.
@ -97,11 +107,14 @@ final class PhabricatorUserOAuthSettingsPanelController
id(new AphrontFormStaticControl()) id(new AphrontFormStaticControl())
->setLabel($provider_name.' URI') ->setLabel($provider_name.' URI')
->setValue($oauth_info->getAccountURI()) ->setValue($oauth_info->getAccountURI())
) );
->appendChild(
if (!$expires || $expires > time()) {
$form->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue('Refresh Profile Image from '.$provider_name) ->setValue('Refresh Profile Image from '.$provider_name)
); );
}
if (!$provider->isProviderLinkPermanent()) { if (!$provider->isProviderLinkPermanent()) {
$unlink = 'Unlink '.$provider_name.' Account'; $unlink = 'Unlink '.$provider_name.' Account';
@ -119,15 +132,14 @@ final class PhabricatorUserOAuthSettingsPanelController
$forms['Unlink Account'] = $unlink_form; $forms['Unlink Account'] = $unlink_form;
} }
$expires = $oauth_info->getTokenExpires();
if ($expires) { if ($expires) {
if ($expires <= time()) { if ($expires <= time()) {
$expires = "Expired"; $expires_text = "Expired";
} else { } else {
$expires = phabricator_datetime($expires, $user); $expires_text = phabricator_datetime($expires, $user);
} }
} else { } else {
$expires = 'No Information Available'; $expires_text = 'No Information Available';
} }
$scope = $oauth_info->getTokenScope(); $scope = $oauth_info->getTokenScope();
@ -150,12 +162,21 @@ final class PhabricatorUserOAuthSettingsPanelController
->appendChild( ->appendChild(
id(new AphrontFormStaticControl()) id(new AphrontFormStaticControl())
->setLabel('Expires') ->setLabel('Expires')
->setValue($expires)) ->setValue($expires_text))
->appendChild( ->appendChild(
id(new AphrontFormStaticControl()) id(new AphrontFormStaticControl())
->setLabel('Scope') ->setLabel('Scope')
->setValue($scope)); ->setValue($scope));
if ($expires <= time()) {
$this->prepareAuthForm($token_form);
$token_form
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Refresh '.$provider_name.' Token')
);
}
$forms['Account Token Information'] = $token_form; $forms['Account Token Information'] = $token_form;
} }