Differential D14050 Diff 33968 src/applications/oauthserver/controller/PhabricatorOAuthServerTestController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/oauthserver/controller/PhabricatorOAuthServerTestController.php
<?php | <?php | ||||
final class PhabricatorOAuthServerTestController | final class PhabricatorOAuthServerTestController | ||||
extends PhabricatorOAuthServerController { | extends PhabricatorOAuthServerController { | ||||
private $id; | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $this->getViewer(); | |||||
public function shouldRequireLogin() { | $id = $request->getURIData('id'); | ||||
return true; | |||||
} | |||||
public function willProcessRequest(array $data) { | |||||
$this->id = $data['id']; | |||||
} | |||||
public function processRequest() { | |||||
$request = $this->getRequest(); | |||||
$viewer = $request->getUser(); | |||||
$panels = array(); | |||||
$results = array(); | |||||
$client = id(new PhabricatorOAuthServerClientQuery()) | $client = id(new PhabricatorOAuthServerClientQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($this->id)) | ->withIDs(array($id)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$client) { | if (!$client) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$view_uri = $client->getViewURI(); | $view_uri = $client->getViewURI(); | ||||
// Look for an existing authorization. | // Look for an existing authorization. | ||||
$authorization = id(new PhabricatorOAuthClientAuthorizationQuery()) | $authorization = id(new PhabricatorOAuthClientAuthorizationQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withUserPHIDs(array($viewer->getPHID())) | ->withUserPHIDs(array($viewer->getPHID())) | ||||
->withClientPHIDs(array($client->getPHID())) | ->withClientPHIDs(array($client->getPHID())) | ||||
->executeOne(); | ->executeOne(); | ||||
if ($authorization) { | if ($authorization) { | ||||
$dialog = id(new AphrontDialogView()) | return $this->newDialog() | ||||
->setUser($viewer) | |||||
->setTitle(pht('Already Authorized')) | ->setTitle(pht('Already Authorized')) | ||||
->appendParagraph( | ->appendParagraph( | ||||
pht( | pht( | ||||
'You have already authorized this application to access your '. | 'You have already authorized this application to access your '. | ||||
'account.')) | 'account.')) | ||||
->addCancelButton($view_uri, pht('Close')); | ->addCancelButton($view_uri, pht('Close')); | ||||
return id(new AphrontDialogResponse())->setDialog($dialog); | |||||
} | } | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$server = id(new PhabricatorOAuthServer()) | $server = id(new PhabricatorOAuthServer()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setClient($client); | ->setClient($client); | ||||
$scope = array(); | $scope = array(); | ||||
$authorization = $server->authorizeClient($scope); | $authorization = $server->authorizeClient($scope); | ||||
$id = $authorization->getID(); | $id = $authorization->getID(); | ||||
$panel_uri = '/settings/panel/oauthorizations/?id='.$id; | $panel_uri = '/settings/panel/oauthorizations/?id='.$id; | ||||
return id(new AphrontRedirectResponse())->setURI($panel_uri); | return id(new AphrontRedirectResponse())->setURI($panel_uri); | ||||
} | } | ||||
// TODO: It would be nice to put scope options in this dialog, maybe? | // TODO: It would be nice to put scope options in this dialog, maybe? | ||||
$dialog = id(new AphrontDialogView()) | return $this->newDialog() | ||||
->setUser($viewer) | |||||
->setTitle(pht('Authorize Application?')) | ->setTitle(pht('Authorize Application?')) | ||||
->appendParagraph( | ->appendParagraph( | ||||
pht( | pht( | ||||
'This will create an authorization, permitting %s to access '. | 'This will create an authorization, permitting %s to access '. | ||||
'your account.', | 'your account.', | ||||
phutil_tag('strong', array(), $client->getName()))) | phutil_tag('strong', array(), $client->getName()))) | ||||
->addCancelButton($view_uri) | ->addCancelButton($view_uri) | ||||
->addSubmitButton(pht('Authorize Application')); | ->addSubmitButton(pht('Authorize Application')); | ||||
return id(new AphrontDialogResponse())->setDialog($dialog); | |||||
} | } | ||||
} | } |