|
| 1 | +# Identity Server 4 |
| 2 | + |
| 3 | +This library supports authenticating for Identity Server 4 out of the box. Some quirks: |
| 4 | + |
| 5 | +1. In order to enable refresh tokens, `offline_access` must be passed in as a scope variable |
| 6 | +2. In order to revoke the access token, we must sent client id in the method body of the request. |
| 7 | + This is not part of the OAuth spec. |
| 8 | + |
| 9 | +```js |
| 10 | +// Note "offline_access" scope is required to get a refresh token |
| 11 | +const config = { |
| 12 | + issuer: 'https://demo.identityserver.io', |
| 13 | + clientId: 'native.code', |
| 14 | + redirectUrl: 'io.identityserver.demo:/oauthredirect', |
| 15 | + scopes: ['openid', 'profile', 'offline_access'] |
| 16 | +}; |
| 17 | + |
| 18 | +// Log in to get an authentication token |
| 19 | +const authState = await authorize(config); |
| 20 | + |
| 21 | +// Refresh token |
| 22 | +const refreshedState = await refresh(config, { |
| 23 | + refreshToken: authState.refreshToken, |
| 24 | +}); |
| 25 | + |
| 26 | +// Revoke token, note that Identity Server expects a client id on revoke |
| 27 | +await revoke(config, { |
| 28 | + tokenToRevoke: refreshedState.refreshToken, |
| 29 | + sendClientId: true |
| 30 | +}); |
| 31 | +``` |
| 32 | + |
| 33 | +<details> |
| 34 | + <summary>Example server configuration</summary> |
| 35 | + |
| 36 | +``` |
| 37 | +var client = new Client |
| 38 | +{ |
| 39 | + ClientId = "native.code", |
| 40 | + ClientName = "Native Client (Code with PKCE)", |
| 41 | + RequireClientSecret = false, |
| 42 | + RedirectUris = { "io.identityserver.demo:/oauthredirect" }, |
| 43 | + AllowedGrantTypes = GrantTypes.Code, |
| 44 | + RequirePkce = true, |
| 45 | + AllowedScopes = { "openid", "profile" }, |
| 46 | + AllowOfflineAccess = true |
| 47 | +}; |
| 48 | +``` |
| 49 | + |
| 50 | +</details> |
0 commit comments