|
2 | 2 | Migrating from 2.x to 3.x
|
3 | 3 | ===========================
|
4 | 4 |
|
5 |
| -.. todo:: Copy `Migrating article`_ from GitHub Wiki. |
| 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 |
| -.. _Migrating article: https://github.com/oauthjs/node-oauth2-server/wiki/Migrating-from-2.x-to-3.x |
| 7 | +## Middlewares |
8 | 8 |
|
| 9 | + The naming of the exposed middlewares has changed to match the OAuth2 _RFC_ more closely. Please refer to the table below: |
| 10 | + |
| 11 | +| oauth2-server 2.x | oauth2-server 3.x | |
| 12 | +|-------------------|------------------------------------------------| |
| 13 | +| authorise | authenticate | |
| 14 | +| authCodeGrant | authorize | |
| 15 | +| grant | token | |
| 16 | +| errorHandler | **removed** (now handled by external wrappers) | |
| 17 | +| lockdown | **removed** (specific to _Express_ middleware) | |
| 18 | +
|
| 19 | +## Server options |
| 20 | + |
| 21 | +The following server options can be set when instantiating the OAuth service: |
| 22 | + |
| 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. |
| 32 | + |
| 33 | +The following server options have been removed in v3.0.0 |
| 34 | + |
| 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). |
| 40 | + |
| 41 | +## Model specification |
| 42 | + |
| 43 | + * `generateAccessToken(client, user, scope)` is **optional** and should return a _String. |
| 44 | + |
| 45 | + * `generateAuthorizationCode()` is **optional** and should return a _String. |
| 46 | + |
| 47 | + * `generateRefreshToken(client, user, scope)` is **optional** and should return a _String. |
| 48 | + |
| 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_) |
| 55 | + |
| 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_) |
| 61 | + |
| 62 | + * `getClient(clientId, clientSecret)` should return an object with, at minimum: |
| 63 | + * `redirectUris` (_Array_) |
| 64 | + * `grants` (_Array_) |
| 65 | + |
| 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_) |
| 72 | + |
| 73 | + * `getUser(username, password)` should return an object: |
| 74 | + * No longer requires that `id` be returned. |
| 75 | + |
| 76 | + * `getUserFromClient(client)` should return an object: |
| 77 | + * No longer requires that `id` be returned. |
| 78 | + |
| 79 | + * `grantTypeAllowed()` was **removed**. You can instead: |
| 80 | + * Return _falsy_ in your `getClient()` |
| 81 | + * Throw an error in your `getClient()` |
| 82 | + |
| 83 | + * `revokeAuthorizationCode(code)` is **required** and should return true |
| 84 | + |
| 85 | + * `revokeToken(token)` is **required** and should return true |
| 86 | + |
| 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_) |
| 94 | + |
| 95 | + * `saveAuthCode()` was renamed to `saveAuthorizationCode(code, client, user)` and should return: |
| 96 | + * `authorizationCode` (_String_) |
| 97 | + |
| 98 | + * `validateScope(user, client, scope)` should return a _Boolean_. |
| 99 | + |
| 100 | +The full model specification is [also available](https://oauth2-server.readthedocs.io/en/latest/model/spec.html). |
0 commit comments