|
| 1 | +--- |
| 2 | +title: OpenIDConnect |
| 3 | +description: OpenID Connect 1.0 is a simple identity layer on top of the OAuth 2.0 protocol. It enables Clients to verify the identity of the End-User based on the authentication performed by an Authorization Server, as well as to obtain basic profile information about the End-User in an interoperable and REST-like manner. |
| 4 | +position: 23 |
| 5 | +category: Schemes |
| 6 | +--- |
| 7 | + |
| 8 | +[Source Code](https://github.com/nuxt-community/auth-module/blob/dev/src/schemes/openIDConnect.ts) |
| 9 | + |
| 10 | +As the OpenID Connect is a layer on top of the OAuth 2.0 protocol, this scheme extends the OAuth 2.0 scheme. |
| 11 | + |
| 12 | +Please see the [OAuth2 scheme](./oauth2) for more information. |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +```js |
| 17 | +this.$auth.loginWith('openIDConnect') |
| 18 | +``` |
| 19 | + |
| 20 | +Additional arguments can be passed through to the OpenID Connect provider using the `params` key of the second argument: |
| 21 | + |
| 22 | +```js |
| 23 | +this.$auth.loginWith('openIDConnect', { params: { another_post_key: 'value' } }) |
| 24 | +``` |
| 25 | + |
| 26 | +## Options |
| 27 | +Minimal configuration: |
| 28 | +```js |
| 29 | +auth: { |
| 30 | + strategies: { |
| 31 | + oidc: { |
| 32 | + scheme: 'openIDConnect', |
| 33 | + clientId: 'CLIENT_ID', |
| 34 | + endpoints: { |
| 35 | + configuration: 'https://accounts.google.com/.well-known/openid-configuration', |
| 36 | + }, |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +Default configuration: |
| 43 | +```js |
| 44 | +auth: { |
| 45 | + strategies: { |
| 46 | + oidc: { |
| 47 | + scheme: 'openIDConnect', |
| 48 | + endpoints: { |
| 49 | + configuration: 'https://accounts.google.com/.well-known/openid-configuration', |
| 50 | + }, |
| 51 | + idToken: { |
| 52 | + property: 'id_token', |
| 53 | + maxAge: 60 * 60 * 24 * 30, |
| 54 | + prefix: '_id_token.', |
| 55 | + expirationPrefix: '_id_token_expiration.' |
| 56 | + }, |
| 57 | + responseType: 'code', |
| 58 | + grantType: 'authorization_code', |
| 59 | + scope: ['openid', 'profile', 'offline_access'], |
| 60 | + codeChallengeMethod: 'S256', |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +### `endpoints` |
| 67 | + |
| 68 | +Each endpoint is used to make requests using axios. They are basically extending Axios [Request Config](https://github.com/axios/axios#request-config). |
| 69 | + |
| 70 | +#### `configuration` |
| 71 | + |
| 72 | +**REQUIRED** - Endpoint to request the provider's metadata document to automatically set the endpoints. A metadata document that contains most of the OpenID Provider's information, such as the URLs to use and the location of the service's public signing keys. You can find this document by appending the discovery document path (/.well-known/openid-configuration) to the authority URL (https://example.com). |
| 73 | + |
| 74 | +Eg. `https://example.com/.well-known/openid-configuration` |
| 75 | + |
| 76 | +More info: https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig |
| 77 | + |
| 78 | +Each endpoint defined in the OAuth2 scheme can also be used in the OpenID Connect scheme configuration. This will override the information provided by the configuration document. |
| 79 | + |
| 80 | +### `clientId` |
| 81 | + |
| 82 | +**REQUIRED** - OpenID Connect client id. |
| 83 | + |
| 84 | +### `scope` |
| 85 | + |
| 86 | +- Default: `['openid', 'profile', 'offline_access']` |
| 87 | + |
| 88 | +OpenID Connect access scopes. |
| 89 | + |
| 90 | +### `token` |
| 91 | + |
| 92 | +Access token |
| 93 | + |
| 94 | +#### `property` |
| 95 | + |
| 96 | +- Default: `access_token` |
| 97 | + |
| 98 | +`property` can be used to specify which field of the response JSON to be used for value. It can be `false` to directly use API response or being more complicated like `auth.access_token`. |
| 99 | + |
| 100 | +#### `type` |
| 101 | + |
| 102 | +- Default: `Bearer` |
| 103 | + |
| 104 | +It will be used in `Authorization` header of axios requests. |
| 105 | + |
| 106 | +#### `maxAge` |
| 107 | + |
| 108 | +- Default: `1800` |
| 109 | + |
| 110 | +Here you set the expiration time of the token, in **seconds**. |
| 111 | +This time will be used if for some reason we couldn't decode the token to get the expiration date. |
| 112 | + |
| 113 | +Should be same as login page or relative path to welcome screen. ([example](https://github.com/nuxt-community/auth-module/blob/dev/examples/demo/pages/callback.vue)) |
| 114 | + |
| 115 | +By default is set to 30 minutes. |
| 116 | + |
| 117 | +### `idToken` |
| 118 | + |
| 119 | +The OpenIDConnect scheme will save both the access and ID token. This because to end the user-session at the authorization server, the ID token needs to be part of the logout request via the required parameter `id_token_hint`. |
| 120 | + |
| 121 | +#### `property` |
| 122 | + |
| 123 | +- Default: `id_token` |
| 124 | + |
| 125 | +`property` can be used to specify which field of the response JSON to be used for value. It can be `false` to directly use API response or being more complicated like `auth.id_token`. |
| 126 | + |
| 127 | +#### `maxAge` |
| 128 | + |
| 129 | +- Default: `1800` |
| 130 | + |
| 131 | +Here you set the expiration time of the ID token, in **seconds**. |
| 132 | +This time will be used if for some reason we couldn't decode the ID token to get the expiration date. |
| 133 | + |
| 134 | +By default is set to 30 minutes. |
| 135 | + |
| 136 | +### `refreshToken` |
| 137 | + |
| 138 | +#### `property` |
| 139 | + |
| 140 | +- Default: `refresh_token` |
| 141 | + |
| 142 | +`property` can be used to specify which field of the response JSON to be used for value. It can be `false` to directly use API response or being more complicated like `auth.refresh_token`. |
| 143 | + |
| 144 | +#### `maxAge` |
| 145 | + |
| 146 | +- Default: `60 * 60 * 24 * 30` |
| 147 | + |
| 148 | +Here you set the expiration time of the refresh token, in **seconds**. |
| 149 | +This time will be used if for some reason we couldn't decode the token to get the expiration date. |
| 150 | + |
| 151 | +By default is set to 30 days. |
| 152 | + |
| 153 | +### `responseType` |
| 154 | + |
| 155 | +- Default: `code` |
| 156 | + |
| 157 | +Set to `code` for authorization code flow. |
| 158 | + |
| 159 | +### `grantType` |
| 160 | + |
| 161 | +- Default: `authorization_code` |
| 162 | + |
| 163 | +Set to `authorization_code` for authorization code flow. |
| 164 | + |
| 165 | +### `redirectUri` |
| 166 | + |
| 167 | +Should be same as login page or relative path to welcome screen. ([example](https://github.com/nuxt-community/auth-module/blob/dev/examples/demo/pages/callback.vue)) |
| 168 | + |
| 169 | +By default it will be inferred from `redirect.callback` option. (Defaults to `/login`) |
| 170 | + |
| 171 | +### `logoutRedirectUri` |
| 172 | + |
| 173 | +Should be an absolute path to the welcome screen |
| 174 | + |
| 175 | +### `codeChallengeMethod` |
| 176 | + |
| 177 | +By default is 'implicit' which is the current workflow implementation. In order to support PKCE ('pixy') protocol, valid options include 'S256' and 'plain'. ([read more](https://tools.ietf.org/html/rfc7636)) |
| 178 | + |
| 179 | +Default: `S256` |
| 180 | + |
| 181 | +### `acrValues` |
| 182 | + |
| 183 | +Provides metadata to supply additional information to the authorization server. ([read more](https://ldapwiki.com/wiki/Acr_values)) |
| 184 | + |
| 185 | +### `autoLogout` |
| 186 | + |
| 187 | +- Default: `false` |
| 188 | + |
| 189 | +If the token has expired, it will prevent the token from being refreshed on load the page and force logout the user. |
0 commit comments