Skip to content

Commit c915156

Browse files
authored
Merge pull request #124 from BuildingSMART/feature/OAuth2Rework
Removing BCF API OAuth2 specifics
2 parents 767259b + 059e00a commit c915156

File tree

4 files changed

+123
-135
lines changed

4 files changed

+123
-135
lines changed

OAuth2Examples.md

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# BCF API OAuth2 Example
2+
3+
This example describes an example OAuth2 workflow using the _Authorization Code Grant_ flow as per [section 4.1 of the OAuth2 specification](https://tools.ietf.org/html/rfc6749#section-4.1). Uris of required endpoints are assumed to have been obtained from the authentication resource as described in [section 3.2 of the BCF API specification](https://github.com/BuildingSMART/BCF-API#321-obtaining-authentication-information).
4+
5+
For this example, it is assumed that the client has been registered with the server in advance and has been issued valid credentials in the form of `client_id` and `client_secret`.
6+
7+
## Client Request
8+
9+
To initiate the workflow, the client sends the user to the **"oauth2\_auth_url"** with the following parameters added:
10+
11+
|parameter|value|
12+
|-------------|------|
13+
|response_type|`code` as string literal|
14+
|client_id|your client id|
15+
|state|unique user defined value|
16+
17+
Example URL:
18+
19+
GET https://example.com/bcf/oauth2/auth?response_type=code&client_id=<your_client_id>&state=<user_defined_string>
20+
21+
_On Windows operating systems, it is possible to open the systems default browser by using the url to start a new process._
22+
23+
Example redirected URL:
24+
25+
https://YourWebsite.com/retrieveCode?code=<server_generated_code>&state=<user_defined_string>
26+
27+
The BCF API server will ask the user to confirm that the client may access resources on his behalf. On authorization, the server redirects to an url that has been defined by the client author in advance. The generated `code` parameter will be appended as query parameter. Additionally, the `state` parameter is included in the redirection, it may be used to match server responses to client requests issued by your application.
28+
29+
If the user denies client access, there will be an `error` query parameter in the redirection indicating an error reason as described in [section 4.1.2.1 of the OAuth2 specification](https://tools.ietf.org/html/rfc6749#section-4.1.2.1).
30+
31+
## Token Request
32+
33+
With the obtained _authorization code_, the client is able to request an access token from the server. The **"oauth2\_token_url"** from the authentication resource is used to send token requests to, for example:
34+
35+
POST https://example.com/bcf/oauth2/token
36+
37+
**Parameters**
38+
39+
|parameter|type|description|
40+
|---------|----|-----------|
41+
|access_token|string|The issued OAuth2 token|
42+
|token_type|string|Always `bearer`|
43+
|expires_in|integer|The lifetime of the access token in seconds|
44+
|refresh_token|string|The issued OAuth2 refresh token, one-time-usable only|
45+
46+
The POST request should be done via HTTP Basic Authorization with your applications `client_id` as the username and your `client_secret` as the password.
47+
48+
**Example Request**
49+
50+
POST https://example.com/bcf/oauth2/token?grant_type=authorization_code&code=<your_access_code>
51+
52+
The access token will be returned as JSON in the response body and is an arbitrary string, guaranteed to not exceed 255 characters length.
53+
54+
**Example Response**
55+
56+
Response Code: 201 - Created
57+
Body:
58+
{
59+
"access_token": "Zjk1YjYyNDQtOTgwMy0xMWU0LWIxMDAtMTIzYjkzZjc1Y2Jh",
60+
"token_type": "bearer",
61+
"expires_in": "3600",
62+
"refresh_token": "MTRiMjkzZTYtOTgwNC0xMWU0LWIxMDAtMTIzYjkzZjc1Y2Jh"
63+
}
64+
65+
## Refresh Token Request
66+
67+
The process to retrieve a refresh token is exactly the same as retrieving a token via the code workflow except the `refresh_token` is sent instead of the `code` parameter and the `refresh_token` grant type is used.
68+
69+
**Example Request**
70+
71+
POST https://example.com/bcf/oauth2/token?grant_type=refresh_token&refresh_token=<your_refresh_token>
72+
73+
The access token will be returned as JSON in the response body and is an arbitrary string, guaranteed to not exceed 255 characters length.
74+
75+
**Example Response**
76+
77+
Response Code: 201 - Created
78+
Body:
79+
{
80+
"access_token": "Zjk1YjYyNDQtOTgwMy0xMWU0LWIxMDAtMTIzYjkzZjc1Y2Jh",
81+
"token_type": "bearer",
82+
"expires_in": "3600",
83+
"refresh_token": "MTRiMjkzZTYtOTgwNC0xMWU0LWIxMDAtMTIzYjkzZjc1Y2Jh"
84+
}
85+
86+
The refresh token can only be used once to retrieve a token and a new refresh token.
87+
88+
## Requesting Resources
89+
90+
When requesting other resources the access token must be passed via the `Authorization` header using the `Bearer` scheme (e.g. `Authorization: Bearer Zjk1YjYyNDQtOTgwMy0xMWU0LWIxMDAtMTIzYjkzZjc1Y2Jh`).

README.md

+25-110
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@
2929
* [3.1 Versions Service](#31-versions-service)
3030
* [3.2 Authentication Services](#32-authentication-services)
3131
+ [3.2.1 Obtaining Authentication Information](#321-obtaining-authentication-information)
32-
+ [3.2.2 OAuth2 Protocol Flow - Client Request](#322-oauth2-protocol-flow---client-request)
33-
+ [3.2.3 OAuth2 Protocol Flow - Token Request](#323-oauth2-protocol-flow---token-request)
34-
+ [3.2.4 OAuth2 Protocol Flow - Refresh Token Request](#324-oauth2-protocol-flow---refresh-token-request)
35-
+ [3.2.5 OAuth2 Protocol Flow - Dynamic Client Registration](#325-oauth2-protocol-flow---dynamic-client-registration)
36-
+ [3.2.6 OAuth2 Protocol Flow - Requesting Resources](#326-oauth2-protocol-flow---requesting-resources)
32+
+ [3.2.2 OAuth2 Example](#322-oauth2-example)
33+
+ [3.2.3 OAuth2 Protocol Flow - Dynamic Client Registration](#323-oauth2-protocol-flow---dynamic-client-registration)
3734
* [3.3 User Services](#33-user-services)
3835
+ [3.3.1 Get current user](#331-get-current-user)
3936
- [4. BCF Services](#4-bcf-services)
@@ -299,22 +296,31 @@ Authentication is based on the [OAuth 2.0 Protocol](http://tools.ietf.org/html/d
299296

300297
**Resource URL (public resource)**
301298

302-
GET /bcf/auth
299+
GET /bcf/{version}/auth
303300

304301
**Parameters**
305302

306303
|Parameter|Type|Description|Required|
307304
|---------|----|-----------|--------|
308-
|oauth2_auth_url|string|URL to authorisation page|false|
305+
|oauth2_auth_url|string|URL to authorization page (used for Authorization Code Grant and Implicit Grant OAuth2 flows)|false|
309306
|oauth2_token_url|string|URL for token requests|false|
310307
|oauth2_dynamic_client_reg_url|string|URL for automated client registration|false|
311308
|http_basic_supported|boolean|Indicates if Http Basic Authentication is supported|false|
309+
|supported_oauth2_flows|string[]|array of supported OAuth2 flows|
312310

313311
If `oauth2_auth_url` is present, then `oauth2_token_url` must also be present and vice versa. If properties are not present in the response, clients should assume that the functionality is not supported by the server, e.g. a missing `http_basic_supported` property would indicate that Http basic authentication is not available on the server.
314312

313+
OAuth2 flows are described in detail in the [OAuth2 specification](https://tools.ietf.org/html/rfc6749). BCF API servers may support the following workflows:
314+
* `authorization_code_grant` - [4.1 - Authorization Code Grant](https://tools.ietf.org/html/rfc6749#section-4.1)
315+
* `implicit_grant` - [4.2 - Implicit Grant](https://tools.ietf.org/html/rfc6749#section-4.2)
316+
* `resource_owner_password_credentials_grant` - [4.3 - Resource Owner Password Credentials Grant](https://tools.ietf.org/html/rfc6749#section-4.3)
317+
318+
The [OAuth2 Client Credentials Grant (section 4.4)](https://tools.ietf.org/html/rfc6749#section-4.4) is not supported since it does not contain any user identity.
319+
Also the [Extension Grants (section 4.5)](https://tools.ietf.org/html/rfc6749#section-4.5) are not supported.
320+
315321
**Example Request**
316322

317-
GET /bcf/auth
323+
GET /bcf/2.1/auth
318324

319325
**Example Response**
320326

@@ -324,120 +330,33 @@ If `oauth2_auth_url` is present, then `oauth2_token_url` must also be present an
324330
"oauth2_auth_url": "https://example.com/bcf/oauth2/auth",
325331
"oauth2_token_url": "https://example.com/bcf/oauth2/token",
326332
"oauth2_dynamic_client_reg_url": "https://example.com/bcf/oauth2/reg",
327-
"http_basic_supported": true
328-
}
329-
330-
### 3.2.2 OAuth2 Protocol Flow - Client Request
331-
332-
The Client uses the **"oauth2\_auth_url"** and adds the following parameters to it.
333-
334-
|parameter|value|
335-
|-------------|------|
336-
|response_type|`code` as string literal|
337-
|client_id|your client id|
338-
|state|unique user defined value|
339-
340-
Example URL:
341-
342-
GET https://example.com/bcf/oauth2/auth?response_type=code&client_id=<your_client_id>&state=<user_defined_string>
343-
344-
Example redirected URL:
345-
346-
https://YourWebsite.com/retrieveCode?code=<server_generated_code>&state=<user_defined_string>
347-
348-
Tip:
349-
You can use the state parameter to transport custom information.
350-
351-
**Open a browser window or redirect the user to this resource.** This redirects back to the specified redirect URI with the provided state and the authorization code as a query parameter if the user allows your app to access the account, the value "access_denied" in the error query parameter if the user denies access.
352-
353-
### 3.2.3 OAuth2 Protocol Flow - Token Request
354-
355-
[token_GET.json](Schemas_draft-03/Authentication/token_GET.json)
356-
357-
The Client uses the **"oauth2\_token_url"** to request a token. Example:
358-
359-
POST https://example.com/bcf/oauth2/token
360-
361-
**Parameters**
362-
363-
|parameter|type|description|
364-
|---------|----|-----------|
365-
|access_token|string|The issued OAuth2 token|
366-
|token_type|string|Always `bearer`|
367-
|expires_in|integer|The lifetime of the access token in seconds|
368-
|refresh_token|string|The issued OAuth2 refresh token, one-time-usable only|
369-
370-
The POST request can be done via HTTP Basic Authorization with your applications `client_id` as the username and your `client_secret` as the password.
371-
372-
**Example Request**
373-
374-
POST https://example.com/bcf/oauth2/token?grant_type=authorization_code&code=<your_access_code>
375-
376-
Alternatively all parameters may be passed in the token request body instead of using Url parameters. The expected `Content-Type` for this request is `application/x-www-form-urlencoded`.
377-
378-
POST https://example.com/bcf/oauth2/token
379-
Body:
380-
grant_type=authorization_code&code=<your_access_code>&client_id=<client_id>&client_secret=<client_secret>
381-
382-
The access token will be returned as JSON in the response body and is an arbitrary string, guaranteed to not exceed 255 characters length.
383-
384-
**Example Response**
385-
386-
Response Code: 201 - Created
387-
Body:
388-
{
389-
"access_token": "Zjk1YjYyNDQtOTgwMy0xMWU0LWIxMDAtMTIzYjkzZjc1Y2Jh",
390-
"token_type": "bearer",
391-
"expires_in": "3600",
392-
"refresh_token": "MTRiMjkzZTYtOTgwNC0xMWU0LWIxMDAtMTIzYjkzZjc1Y2Jh"
333+
"http_basic_supported": true,
334+
"supported_oauth2_flows": [
335+
"authorization_code_grant",
336+
"implicit_grant",
337+
"resource_owner_password_credentials_grant"
338+
]
393339
}
394340

395-
### 3.2.4 OAuth2 Protocol Flow - Refresh Token Request
396-
397-
[token_GET.json](Schemas_draft-03/Authentication/token_GET.json)
341+
### 3.2.2 OAuth2 Example
398342

399-
The process to retrieve a refresh token is exactly the same as retrieving a token via the code workflow except the `refresh_token` is sent instead of the `code` parameter and the `refresh_token` grant type is used.
400-
401-
**Example Request**
343+
An example for the OAuth2 Authorization Grant workflow [can be found here](OAuth2Examples.md).
402344

403-
POST https://example.com/bcf/oauth2/token?grant_type=refresh_token&refresh_token=<your_refresh_token>
404-
405-
Alternatively all parameters may be passed in the token request body instead of using Url parameters.
406-
407-
POST https://example.com/bcf/oauth2/token
408-
Body:
409-
grant_type=refresh_token&refresh_token=<your_refresh_token>&client_id=<client_id>&client_secret=<client_secret>
410-
411-
The access token will be returned as JSON in the response body and is an arbitrary string, guaranteed to not exceed 255 characters length.
412-
413-
**Example Response**
414-
415-
Response Code: 201 - Created
416-
Body:
417-
{
418-
"access_token": "Zjk1YjYyNDQtOTgwMy0xMWU0LWIxMDAtMTIzYjkzZjc1Y2Jh",
419-
"token_type": "bearer",
420-
"expires_in": "3600",
421-
"refresh_token": "MTRiMjkzZTYtOTgwNC0xMWU0LWIxMDAtMTIzYjkzZjc1Y2Jh"
422-
}
423-
424-
The refresh token can only be used once to retrieve a token and a new refresh token.
425-
426-
### 3.2.5 OAuth2 Protocol Flow - Dynamic Client Registration
345+
### 3.2.3 OAuth2 Protocol Flow - Dynamic Client Registration
427346

428347
[dynRegClient\_POST.json](Schemas_draft-03/Authentication/dynRegClient_POST.json)
429348

430349
[dynRegClient\_GET.json](Schemas_draft-03/Authentication/dynRegClient_GET.json)
431350

432351
The following part describes the optional dynamic registration process of a client. BCF-Servers may offer additional processes registering clients, for example allowing a client application developer to register his client on the servers website.
433352

434-
The resource Url for this service is server specific and is returned as `oauth2_dynamic_client_reg_url` in the `GET /bcf/auth` resource.
353+
The resource url for this service is server specific and is returned as `oauth2_dynamic_client_reg_url` in the `GET /bcf/{version}/auth` resource.
435354

436355
Register a new client :
437356

438357
**Parameters**
439358

440-
JSON encoded body using the "application/json" content type.
359+
JSON encoded body using the `application/json` content type.
441360

442361
|parameter|type|description|
443362
|---------|----|-----------|
@@ -466,10 +385,6 @@ JSON encoded body using the "application/json" content type.
466385
"client_secret": "ZWFzdXJlLg=="
467386
}
468387

469-
### 3.2.6 OAuth2 Protocol Flow - Requesting Resources
470-
471-
When requesting other resources the access token must be passed via the `Authorization` header using the Bearer scheme (e.g. `Authorization: Bearer Zjk1YjYyNDQtOTgwMy0xMWU0LWIxMDAtMTIzYjkzZjc1Y2Jh`).
472-
473388
----------
474389

475390
## 3.3 User Services

Schemas_draft-03/Authentication/auth_GET.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
"http_basic_supported": {
1818
"type": ["boolean",
1919
"null"]
20+
},
21+
"supported_oauth2_flows": {
22+
"type": ["array",
23+
"null"],
24+
"items": {
25+
"type": ["string"]
26+
}
2027
}
2128
}
22-
}
29+
}

Schemas_draft-03/Authentication/token_GET.json

-24
This file was deleted.

0 commit comments

Comments
 (0)