Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/oauthserver/controller/client/PhabricatorOAuthClientTestController.php
12242 views
1
<?php
2
3
final class PhabricatorOAuthClientTestController
4
extends PhabricatorOAuthClientController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $this->getViewer();
8
$id = $request->getURIData('id');
9
10
$client = id(new PhabricatorOAuthServerClientQuery())
11
->setViewer($viewer)
12
->withIDs(array($id))
13
->executeOne();
14
if (!$client) {
15
return new Aphront404Response();
16
}
17
18
$done_uri = $client->getViewURI();
19
20
if ($request->isFormPost()) {
21
$server = id(new PhabricatorOAuthServer())
22
->setUser($viewer)
23
->setClient($client);
24
25
// Create an authorization if we don't already have one.
26
$authorization = id(new PhabricatorOAuthClientAuthorizationQuery())
27
->setViewer($viewer)
28
->withUserPHIDs(array($viewer->getPHID()))
29
->withClientPHIDs(array($client->getPHID()))
30
->executeOne();
31
if (!$authorization) {
32
$scope = array();
33
$authorization = $server->authorizeClient($scope);
34
}
35
36
$access_token = $server->generateAccessToken();
37
38
$form = id(new AphrontFormView())
39
->setViewer($viewer)
40
->appendInstructions(
41
pht(
42
'Keep this token private, it allows any bearer to access '.
43
'your account on behalf of this application.'))
44
->appendChild(
45
id(new AphrontFormTextControl())
46
->setLabel(pht('Token'))
47
->setValue($access_token->getToken()));
48
49
return $this->newDialog()
50
->setTitle(pht('OAuth Access Token'))
51
->appendForm($form)
52
->addCancelButton($done_uri, pht('Close'));
53
}
54
55
// TODO: It would be nice to put scope options in this dialog, maybe?
56
57
return $this->newDialog()
58
->setTitle(pht('Authorize Application?'))
59
->appendParagraph(
60
pht(
61
'This will create an authorization and OAuth token, permitting %s '.
62
'to access your account.',
63
phutil_tag('strong', array(), $client->getName())))
64
->addCancelButton($done_uri)
65
->addSubmitButton(pht('Authorize Application'));
66
}
67
}
68
69