Skip to content

Commit 777a626

Browse files
author
Michael Salinger
committed
Fixed migration guide
1 parent 916c1e7 commit 777a626

File tree

1 file changed

+79
-63
lines changed

1 file changed

+79
-63
lines changed

docs/misc/migrating-v2-to-v3.rst

Lines changed: 79 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,99 +2,115 @@
22
Migrating from 2.x to 3.x
33
===========================
44

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.
66

7-
## Middlewares
7+
-----------
8+
Middlewares
9+
-----------
810

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:
1012

13+
+-------------------+------------------------------------------------+
1114
| oauth2-server 2.x | oauth2-server 3.x |
12-
|-------------------|------------------------------------------------|
15+
+===================+================================================+
1316
| authorise | authenticate |
17+
+-------------------+------------------------------------------------+
1418
| authCodeGrant | authorize |
19+
+-------------------+------------------------------------------------+
1520
| grant | token |
21+
+-------------------+------------------------------------------------+
1622
| errorHandler | **removed** (now handled by external wrappers) |
17-
| lockdown | **removed** (specific to _Express_ middleware) |
23+
+-------------------+------------------------------------------------+
24+
| lockdown | **removed** (specific to *Express* middleware) |
25+
+-------------------+------------------------------------------------+
1826

19-
## Server options
27+
--------------
28+
Server options
29+
--------------
2030

2131
The following server options can be set when instantiating the OAuth service:
2232

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.
3242

3343
The following server options have been removed in v3.0.0
3444

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).
4050

41-
## Model specification
51+
-------------------
52+
Model specification
53+
-------------------
4254

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`)
4465

45-
* `generateAuthorizationCode()` is **optional** and should return a _String.
66+
* `getAuthCode()` was renamed to `getAuthorizationCode(code)` and should return:
4667

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`)
4872

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`)
5577

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:
6179

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`)
6585

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.
7289

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.
7593

76-
* `getUserFromClient(client)` should return an object:
77-
* No longer requires that `id` be returned.
94+
* `grantTypeAllowed()` was **removed**. You can instead:
7895

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()`
8298

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:
84102

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`)
86109

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:
94111

95-
* `saveAuthCode()` was renamed to `saveAuthorizationCode(code, client, user)` and should return:
96-
* `authorizationCode` (_String_)
112+
* `authorizationCode` (`String`)
97113

98-
* `validateScope(user, client, scope)` should return a _Boolean_.
114+
* `validateScope(user, client, scope)` should return a `Boolean`.
99115

100116
The full model specification is [also available](https://oauth2-server.readthedocs.io/en/latest/model/spec.html).

0 commit comments

Comments
 (0)