|
2 | 2 | Migrating from 2.x to 3.x
|
3 | 3 | ===========================
|
4 | 4 |
|
5 |
| -This module is now promise-based but allows for *ES6 generators*, *async/await* (using _[babel](https://babeljs.io)_ or node v7.6+), *node-style* callbacks and *promises* in your model. |
| 5 | +This module is now promise-based but allows for **ES6 generators**, **async/await** (using *[babel](https://babeljs.io)* or node v7.6+), **node-style** callbacks and **promises** in your model. |
6 | 6 |
|
7 |
| -## Middlewares |
| 7 | +----------- |
| 8 | +Middlewares |
| 9 | +----------- |
8 | 10 |
|
9 |
| - The naming of the exposed middlewares has changed to match the OAuth2 _RFC_ more closely. Please refer to the table below: |
| 11 | +The naming of the exposed middlewares has changed to match the OAuth2 _RFC_ more closely. Please refer to the table below: |
10 | 12 |
|
| 13 | ++-------------------+------------------------------------------------+ |
11 | 14 | | oauth2-server 2.x | oauth2-server 3.x |
|
12 |
| -|-------------------|------------------------------------------------| |
| 15 | ++===================+================================================+ |
13 | 16 | | authorise | authenticate |
|
| 17 | ++-------------------+------------------------------------------------+ |
14 | 18 | | authCodeGrant | authorize |
|
| 19 | ++-------------------+------------------------------------------------+ |
15 | 20 | | grant | token |
|
| 21 | ++-------------------+------------------------------------------------+ |
16 | 22 | | errorHandler | **removed** (now handled by external wrappers) |
|
17 |
| -| lockdown | **removed** (specific to _Express_ middleware) | |
| 23 | ++-------------------+------------------------------------------------+ |
| 24 | +| lockdown | **removed** (specific to *Express* middleware) | |
| 25 | ++-------------------+------------------------------------------------+ |
18 | 26 |
|
19 |
| -## Server options |
| 27 | +-------------- |
| 28 | +Server options |
| 29 | +-------------- |
20 | 30 |
|
21 | 31 | The following server options can be set when instantiating the OAuth service:
|
22 | 32 |
|
23 |
| - * `addAcceptedScopesHeader`: **default true** Add the `X-Accepted-OAuth-Scopes` header with a list of scopes that will be accepted |
24 |
| - * `addAuthorizedScopesHeader`: **default true** Add the `X-OAuth-Scopes` header with a list of scopes that the user is authorized for |
25 |
| - * `allowBearerTokensInQueryString`: **default false** Determine if the bearer token can be included in the query string (i.e. `?access_token=`) for validation calls |
26 |
| - * `allowEmptyState`: **default false** If true, `state` can be empty or not passed. If false, `state` is required. |
27 |
| - * `authorizationCodeLifetime`: **default 300** Default number of milliseconds that the authorization code is active for |
28 |
| - * `accessTokenLifetime`: **default 3600** Default number of milliseconds that an access token is valid for |
29 |
| - * `refreshTokenLifetime`: **default 1209600** Default number of milliseconds that a refresh token is valid for |
30 |
| - * `allowExtendedTokenAttributes`: **default false** Allows additional attributes (such as `id_token`) to be included in token responses. |
31 |
| - * `requireClientAuthentication`: **default true for all grant types** Allow ability to set client/secret authentication to `false` for a specific grant type. |
| 33 | +* `addAcceptedScopesHeader`: **default true** Add the `X-Accepted-OAuth-Scopes` header with a list of scopes that will be accepted |
| 34 | +* `addAuthorizedScopesHeader`: **default true** Add the `X-OAuth-Scopes` header with a list of scopes that the user is authorized for |
| 35 | +* `allowBearerTokensInQueryString`: **default false** Determine if the bearer token can be included in the query string (i.e. `?access_token=`) for validation calls |
| 36 | +* `allowEmptyState`: **default false** If true, `state` can be empty or not passed. If false, `state` is required. |
| 37 | +* `authorizationCodeLifetime`: **default 300** Default number of milliseconds that the authorization code is active for |
| 38 | +* `accessTokenLifetime`: **default 3600** Default number of milliseconds that an access token is valid for |
| 39 | +* `refreshTokenLifetime`: **default 1209600** Default number of milliseconds that a refresh token is valid for |
| 40 | +* `allowExtendedTokenAttributes`: **default false** Allows additional attributes (such as `id_token`) to be included in token responses. |
| 41 | +* `requireClientAuthentication`: **default true for all grant types** Allow ability to set client/secret authentication to `false` for a specific grant type. |
32 | 42 |
|
33 | 43 | The following server options have been removed in v3.0.0
|
34 | 44 |
|
35 |
| - * `grants`: **removed** (now returned by the _getClient_ method). |
36 |
| - * `debug`: **removed** (not the responsibility of this module). |
37 |
| - * `clientIdRegex`: **removed** (the _getClient_ method can return _undefined_ or throw an error). |
38 |
| - * `passthroughErrors`: **removed** (not the responsibility of this module). |
39 |
| - * `continueAfterResponse`: **removed** (not the responsibility of this module). |
| 45 | +* `grants`: **removed** (now returned by the `getClient` method). |
| 46 | +* `debug`: **removed** (not the responsibility of this module). |
| 47 | +* `clientIdRegex`: **removed** (the `getClient` method can return `undefined` or throw an error). |
| 48 | +* `passthroughErrors`: **removed** (not the responsibility of this module). |
| 49 | +* `continueAfterResponse`: **removed** (not the responsibility of this module). |
40 | 50 |
|
41 |
| -## Model specification |
| 51 | +------------------- |
| 52 | +Model specification |
| 53 | +------------------- |
42 | 54 |
|
43 |
| - * `generateAccessToken(client, user, scope)` is **optional** and should return a _String. |
| 55 | +* `generateAccessToken(client, user, scope)` is **optional** and should return a `String`. |
| 56 | +* `generateAuthorizationCode()` is **optional** and should return a `String`. |
| 57 | +* `generateRefreshToken(client, user, scope)` is **optional** and should return a `String`. |
| 58 | +* `getAccessToken(token)` should return an object with: |
| 59 | + |
| 60 | + * `accessToken` (`String`) |
| 61 | + * `accessTokenExpiresAt` (`Date`) |
| 62 | + * `client` (`Object`), containing at least an `id` property that matches the supplied client |
| 63 | + * `scope` (optional `String`) |
| 64 | + * `user` (`Object`) |
44 | 65 |
|
45 |
| - * `generateAuthorizationCode()` is **optional** and should return a _String. |
| 66 | +* `getAuthCode()` was renamed to `getAuthorizationCode(code)` and should return: |
46 | 67 |
|
47 |
| - * `generateRefreshToken(client, user, scope)` is **optional** and should return a _String. |
| 68 | + * `client` (`Object`), containing at least an `id` property that matches the supplied client |
| 69 | + * `expiresAt` (`Date`) |
| 70 | + * `redirectUri` (optional `String`) |
| 71 | + * `user` (`Object`) |
48 | 72 |
|
49 |
| - * `getAccessToken(token)` should return an object with: |
50 |
| - * `accessToken` (_String_) |
51 |
| - * `accessTokenExpiresAt` (_Date_) |
52 |
| - * `client` (_Object_), containing at least an `id` property that matches the supplied client |
53 |
| - * `scope` (optional _String_) |
54 |
| - * `user` (_Object_) |
| 73 | +* `getClient(clientId, clientSecret)` should return an object with, at minimum: |
| 74 | + |
| 75 | + * `redirectUris` (`Array`) |
| 76 | + * `grants` (`Array`) |
55 | 77 |
|
56 |
| - * `getAuthCode()` was renamed to `getAuthorizationCode(code)` and should return: |
57 |
| - * `client` (_Object_), containing at least an `id` property that matches the supplied client |
58 |
| - * `expiresAt` (_Date_) |
59 |
| - * `redirectUri` (optional _String_) |
60 |
| - * `user` (_Object_) |
| 78 | +* `getRefreshToken(token)` should return an object with: |
61 | 79 |
|
62 |
| - * `getClient(clientId, clientSecret)` should return an object with, at minimum: |
63 |
| - * `redirectUris` (_Array_) |
64 |
| - * `grants` (_Array_) |
| 80 | + * `refreshToken` (`String`) |
| 81 | + * `client` (`Object`), containing at least an `id` property that matches the supplied client |
| 82 | + * `refreshTokenExpiresAt` (optional `Date`) |
| 83 | + * `scope` (optional `String`) |
| 84 | + * `user` (`Object`) |
65 | 85 |
|
66 |
| - * `getRefreshToken(token)` should return an object with: |
67 |
| - * `refreshToken` (_String_) |
68 |
| - * `client` (_Object_), containing at least an `id` property that matches the supplied client |
69 |
| - * `refreshTokenExpiresAt` (optional _Date_) |
70 |
| - * `scope` (optional _String_) |
71 |
| - * `user` (_Object_) |
| 86 | +* `getUser(username, password)` should return an object: |
| 87 | + |
| 88 | + * No longer requires that `id` be returned. |
72 | 89 |
|
73 |
| - * `getUser(username, password)` should return an object: |
74 |
| - * No longer requires that `id` be returned. |
| 90 | +* `getUserFromClient(client)` should return an object: |
| 91 | + |
| 92 | + * No longer requires that `id` be returned. |
75 | 93 |
|
76 |
| - * `getUserFromClient(client)` should return an object: |
77 |
| - * No longer requires that `id` be returned. |
| 94 | +* `grantTypeAllowed()` was **removed**. You can instead: |
78 | 95 |
|
79 |
| - * `grantTypeAllowed()` was **removed**. You can instead: |
80 |
| - * Return _falsy_ in your `getClient()` |
81 |
| - * Throw an error in your `getClient()` |
| 96 | + * Return *falsy* in your `getClient()` |
| 97 | + * Throw an error in your `getClient()` |
82 | 98 |
|
83 |
| - * `revokeAuthorizationCode(code)` is **required** and should return true |
| 99 | +* `revokeAuthorizationCode(code)` is **required** and should return true |
| 100 | +* `revokeToken(token)` is **required** and should return true |
| 101 | +* `saveAccessToken()` was renamed to `saveToken(token, client, user)` and should return: |
84 | 102 |
|
85 |
| - * `revokeToken(token)` is **required** and should return true |
| 103 | + * `accessToken` (`String`) |
| 104 | + * `accessTokenExpiresAt` (`Date`) |
| 105 | + * `client` (`Object`) |
| 106 | + * `refreshToken` (optional `String`) |
| 107 | + * `refreshTokenExpiresAt` (optional `Date`) |
| 108 | + * `user` (`Object`) |
86 | 109 |
|
87 |
| - * `saveAccessToken()` was renamed to `saveToken(token, client, user)` and should return: |
88 |
| - * `accessToken` (_String_) |
89 |
| - * `accessTokenExpiresAt` (_Date_) |
90 |
| - * `client` (_Object_) |
91 |
| - * `refreshToken` (optional _String_) |
92 |
| - * `refreshTokenExpiresAt` (optional _Date_) |
93 |
| - * `user` (_Object_) |
| 110 | +* `saveAuthCode()` was renamed to `saveAuthorizationCode(code, client, user)` and should return: |
94 | 111 |
|
95 |
| - * `saveAuthCode()` was renamed to `saveAuthorizationCode(code, client, user)` and should return: |
96 |
| - * `authorizationCode` (_String_) |
| 112 | + * `authorizationCode` (`String`) |
97 | 113 |
|
98 |
| - * `validateScope(user, client, scope)` should return a _Boolean_. |
| 114 | +* `validateScope(user, client, scope)` should return a `Boolean`. |
99 | 115 |
|
100 | 116 | The full model specification is [also available](https://oauth2-server.readthedocs.io/en/latest/model/spec.html).
|
0 commit comments