Preserve "next" URI by using OAuth 'state' parameter
Summary: When a user clicks a link like /T32 and has to login, redirect them to the resource once they've authenticated if possible. OAuth has a param specifically for this, called 'state', so use it if possible. Facebook supports it but Github does not. Test Plan: logged in with facebook after viewing /D20 Reviewed By: aran Reviewers: aran CC: aran, epriestley Differential Revision: 61
This commit is contained in:
@@ -30,6 +30,11 @@ class PhabricatorLoginController extends PhabricatorAuthController {
|
||||
return id(new AphrontRedirectResponse())->setURI('/');
|
||||
}
|
||||
|
||||
$next_uri = $this->getRequest()->getPath();
|
||||
if ($next_uri == '/login/') {
|
||||
$next_uri = null;
|
||||
}
|
||||
|
||||
$password_auth = PhabricatorEnv::getEnvConfig('auth.password-auth-enabled');
|
||||
|
||||
$forms = array();
|
||||
@@ -76,6 +81,7 @@ class PhabricatorLoginController extends PhabricatorAuthController {
|
||||
$form
|
||||
->setUser($request->getUser())
|
||||
->setAction('/login/')
|
||||
->addHiddenInput('next', $next_uri)
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel('Username/Email')
|
||||
@@ -97,6 +103,8 @@ class PhabricatorLoginController extends PhabricatorAuthController {
|
||||
$forms['Phabricator Login'] = $form;
|
||||
}
|
||||
|
||||
$oauth_state = $next_uri;
|
||||
|
||||
$providers = array(
|
||||
PhabricatorOAuthProvider::PROVIDER_FACEBOOK,
|
||||
PhabricatorOAuthProvider::PROVIDER_GITHUB,
|
||||
@@ -140,6 +148,7 @@ class PhabricatorLoginController extends PhabricatorAuthController {
|
||||
->addHiddenInput('client_id', $client_id)
|
||||
->addHiddenInput('redirect_uri', $redirect_uri)
|
||||
->addHiddenInput('scope', $minimum_scope)
|
||||
->addHiddenInput('state', $oauth_state)
|
||||
->setUser($request->getUser())
|
||||
->setMethod('GET')
|
||||
->appendChild(
|
||||
|
||||
Reference in New Issue
Block a user