Path: blob/master/src/applications/oauthserver/controller/client/PhabricatorOAuthClientTestController.php
12242 views
<?php12final class PhabricatorOAuthClientTestController3extends PhabricatorOAuthClientController {45public function handleRequest(AphrontRequest $request) {6$viewer = $this->getViewer();7$id = $request->getURIData('id');89$client = id(new PhabricatorOAuthServerClientQuery())10->setViewer($viewer)11->withIDs(array($id))12->executeOne();13if (!$client) {14return new Aphront404Response();15}1617$done_uri = $client->getViewURI();1819if ($request->isFormPost()) {20$server = id(new PhabricatorOAuthServer())21->setUser($viewer)22->setClient($client);2324// Create an authorization if we don't already have one.25$authorization = id(new PhabricatorOAuthClientAuthorizationQuery())26->setViewer($viewer)27->withUserPHIDs(array($viewer->getPHID()))28->withClientPHIDs(array($client->getPHID()))29->executeOne();30if (!$authorization) {31$scope = array();32$authorization = $server->authorizeClient($scope);33}3435$access_token = $server->generateAccessToken();3637$form = id(new AphrontFormView())38->setViewer($viewer)39->appendInstructions(40pht(41'Keep this token private, it allows any bearer to access '.42'your account on behalf of this application.'))43->appendChild(44id(new AphrontFormTextControl())45->setLabel(pht('Token'))46->setValue($access_token->getToken()));4748return $this->newDialog()49->setTitle(pht('OAuth Access Token'))50->appendForm($form)51->addCancelButton($done_uri, pht('Close'));52}5354// TODO: It would be nice to put scope options in this dialog, maybe?5556return $this->newDialog()57->setTitle(pht('Authorize Application?'))58->appendParagraph(59pht(60'This will create an authorization and OAuth token, permitting %s '.61'to access your account.',62phutil_tag('strong', array(), $client->getName())))63->addCancelButton($done_uri)64->addSubmitButton(pht('Authorize Application'));65}66}676869