Skip to content

Commit cd30946

Browse files
committed
OAuth Server -- add a doc and link to it in a few places
Summary: add a big ole HELP tab and make "scope" link to the specific sub-section about scope Test Plan: read my doc a few times, it basically english verified links looked correct and should work right once this is all in production Reviewers: epriestley Reviewed By: epriestley CC: aran, epriestley Maniphest Tasks: T910 Differential Revision: https://secure.phabricator.com/D1752
1 parent b5da96f commit cd30946

File tree

5 files changed

+137
-1
lines changed

5 files changed

+137
-1
lines changed

src/applications/oauthserver/controller/base/PhabricatorOAuthServerController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ public function buildStandardPageResponse($view, array $data) {
4747
$nav->appendChild($view);
4848

4949
$page->appendChild($nav);
50+
$doc_href = PhabricatorEnv::getDoclink(
51+
'article/Using_the_Phabricator_OAuth_Server.html'
52+
);
53+
$page->setTabs(
54+
array(
55+
'help' => array(
56+
'name' => 'Help',
57+
'href' => $doc_href,
58+
),
59+
),
60+
null);
5061

5162
$response = new AphrontWebpageResponse();
5263
return $response->setContent($page->render());

src/applications/oauthserver/controller/base/__init__.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
phutil_require_module('phabricator', 'aphront/response/webpage');
1010
phutil_require_module('phabricator', 'applications/base/controller/base');
11+
phutil_require_module('phabricator', 'infrastructure/env');
1112
phutil_require_module('phabricator', 'view/form/error');
1213
phutil_require_module('phabricator', 'view/layout/sidenavfilter');
1314

src/applications/oauthserver/controller/clientauthorization/list/PhabricatorOAuthClientAuthorizationListController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public function processRequest() {
5454
$current_user);
5555
$updated = phabricator_datetime($authorization->getDateModified(),
5656
$current_user);
57+
$scope_doc_href = PhabricatorEnv::getDoclink(
58+
'article/Using_the_Phabricator_OAuth_Server.html#scopes'
59+
);
5760
$row = array(
5861
phutil_render_tag(
5962
'a',
@@ -65,7 +68,7 @@ public function processRequest() {
6568
phutil_render_tag(
6669
'a',
6770
array(
68-
'href' => 'TODO - link to scope about',
71+
'href' => $scope_doc_href,
6972
),
7073
$authorization->getScopeString()
7174
),

src/applications/oauthserver/controller/clientauthorization/list/__init__.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
phutil_require_module('phabricator', 'applications/oauthserver/controller/clientauthorization/base');
1010
phutil_require_module('phabricator', 'applications/oauthserver/storage/client');
1111
phutil_require_module('phabricator', 'applications/oauthserver/storage/clientauthorization');
12+
phutil_require_module('phabricator', 'infrastructure/env');
1213
phutil_require_module('phabricator', 'view/control/table');
1314
phutil_require_module('phabricator', 'view/form/error');
1415
phutil_require_module('phabricator', 'view/layout/panel');
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
@title Using the Phabricator OAuth Server
2+
@group developer
3+
4+
How to use the Phabricator OAuth Server.
5+
6+
= Overview =
7+
8+
Phabricator includes an OAuth Server which supports the
9+
##Authorization Code Grant## flow as described in the OAuth 2.0
10+
specification:
11+
12+
http://tools.ietf.org/html/draft-ietf-oauth-v2-23
13+
14+
This functionality can allow clients to integrate with a given
15+
Phabricator instance in a secure way with granular data access.
16+
For example, Phabricator can be used as a central identity store for any
17+
clients that implement OAuth 2.0.
18+
19+
= Vocabulary =
20+
21+
- **Access token** - a token which allows a client to ask for data on
22+
behalf of a resource owner. A given client will only be able to access
23+
data included in the scope(s) the resource owner authorized that client for.
24+
- **Authorization code** - a short-lived code which allows an authenticated
25+
client to ask for an access token on behalf of some resource owner.
26+
- **Client** - this is the application or system asking for data from the
27+
OAuth Server on behalf of the resource owner.
28+
- **Resource owner** - this is the user the client and OAuth Server are
29+
concerned with on a given request.
30+
- **Scope** - this defines a specific piece of granular data a client can
31+
or can not access on behalf of a user. For example, if authorized for the
32+
"whoami" scope on behalf of a given resource owner, the client can get the
33+
results of Conduit.whoami for that resource owner when authenticated with
34+
a valid access token.
35+
36+
= Setup - Creating a Client =
37+
38+
# Visit https://phabricator.example.com/oauthserver/client/create/
39+
# Fill out the form
40+
# Profit
41+
42+
= Obtaining an Authorization Code =
43+
44+
POST or GET https://phabricator.example.com/oauthserver/auth/ with the
45+
following parameters:
46+
47+
- Required - **client_id** - the id of the newly registered client.
48+
- Required - **response_type** - the desired type of authorization code
49+
response. Only code is supported at this time.
50+
- Optional - **redirect_uri** - override the redirect_uri the client
51+
registered. This redirect_uri must have the same fully-qualified domain
52+
and have at least the same query parameters as the redirect_uri the client
53+
registered, as well as have no fragments.
54+
- Optional - **scope** - specify what scope(s) the client needs access to
55+
in a space-delimited list.
56+
- Optional - **state** - an opaque value the client can send to the server
57+
for programmatic excellence. Some clients use this value to implement XSRF
58+
protection or for debugging purposes.
59+
60+
If done correctly and the resource owner has not yet authorized the client
61+
for the desired scope, then the resource owner will be presented with an
62+
interface to authorize the client for the desired scope. The OAuth Server
63+
will redirect to the pertinent redirect_uri with an authorization code or
64+
an error indicating the resource owner did not authorize the client, depending.
65+
66+
If done correctly and the resource owner has already authorized the client for
67+
the desired scope, then the OAuth Server will redirect to the pertinent
68+
redirect_uri with a valid authorization code.
69+
70+
If there is an error, the OAuth Server will return a descriptive error
71+
message. This error will be presented to the resource owner on the
72+
Phabricator domain if there is reason to believe there is something fishy
73+
with the client. For example, if there is an issue with the redirect_uri.
74+
Otherwise, the OAuth Server will redirect to the pertinent redirect_uri
75+
and include the pertinent error information.
76+
77+
= Obtaining an Access Token =
78+
79+
POST or GET https://phabricator.example.com/oauthserver/token/
80+
with the following parameters:
81+
82+
- Required - **client_id** - the id of the client
83+
- Required - **client_secret** - the secret of the client.
84+
This is used to authenticate the client.
85+
- Required - **code** - the authorization code obtained earlier.
86+
- Required - **grant_type** - the desired type of access grant.
87+
Only token is supported at this time.
88+
- Optional - **redirect_uri** - should be the exact same redirect_uri as
89+
the redirect_uri specified to obtain the authorization code. If no
90+
redirect_uri was specified to obtain the authorization code then this
91+
should not be specified.
92+
93+
If done correctly, the OAuth Server will redirect to the pertinent
94+
redirect_uri with an access token.
95+
96+
If there is an error, the OAuth Server will return a descriptive error
97+
message.
98+
99+
= Using an Access Token =
100+
101+
Simply include a query param with the key of "access_token" and the value
102+
as the earlier obtained access token. For example:
103+
104+
https://phabricator.example.com/api/user.whoami?access_token=ykc7ly7vtibj334oga4fnfbuvnwz4ocp
105+
106+
If the token has expired or is otherwise invalid, the client will receive
107+
an error indicating as such. In these cases, the client should re-initiate
108+
the entire ##Authorization Code Grant## flow.
109+
110+
NOTE: See "Scopes" section below for more information on what data is
111+
currently exposed through the OAuth Server.
112+
113+
= Scopes =
114+
115+
There are only two scopes supported at this time.
116+
117+
- **offline_access** - allows an access token to work indefinitely without
118+
expiring.
119+
- **whoami** - allows the client to access the results of Conduit.whoami on
120+
behalf of the resource owner.

0 commit comments

Comments
 (0)