You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: EXAMPLES.md
+23-17Lines changed: 23 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -219,66 +219,70 @@ This makes ORTs a good fit for SPAs that want a refresh-token renewal path whose
219
219
220
220
### Enabling Online Access
221
221
222
-
Set `onlineAccess: true` together with `useDpop: true`:
222
+
Set `refreshTokenMode: 'online'` together with`useRefreshTokens: true` and`useDpop: true`:
223
223
224
224
```js
225
225
constauth0=awaitcreateAuth0Client({
226
226
domain:'<AUTH0_DOMAIN>',
227
227
clientId:'<AUTH0_CLIENT_ID>',
228
-
onlineAccess:true,
228
+
useRefreshTokens:true, // required — online access is a refresh-token grant
229
+
refreshTokenMode:'online',
229
230
useDpop:true, // required — DPoP is mandatory for online access
230
231
authorizationParams: {
231
232
redirect_uri:'<MY_CALLBACK_URL>'
232
233
}
233
234
});
234
235
```
235
236
237
+
`refreshTokenMode` is a sub-option of `useRefreshTokens`. It defaults to `'offline'` (the rotating [offline refresh tokens](#refresh-tokens) described above); setting it to `'online'` opts into Online Refresh Tokens.
238
+
236
239
Enabling this option causes the SDK to:
237
240
238
241
- Send the `online_access` scope to the authorization server (instead of `offline_access`). You do **not** need to add it to `authorizationParams.scope` yourself — the SDK injects it.
239
242
- Route token renewal through the `refresh_token` grant against `/oauth/token` (the same path used by offline refresh tokens), rather than a hidden iframe.
240
243
- Store the non-rotating ORT in the existing cache and reuse it on every refresh, never replacing it.
241
244
242
245
> [!NOTE]
243
-
> Online access is **opt-in**. When `onlineAccess` is unset or `false`, the SDK behaves exactly as before.
246
+
> Online access is **opt-in**. When `refreshTokenMode` is unset or `'offline'`, the SDK behaves exactly as before.
244
247
245
248
> [!NOTE]
246
249
> This feature requires the `online_refresh_tokens` flag to be enabled for your tenant and `allow_online_access` to be enabled on the resource server (on by default).
247
250
248
-
### `onlineAccess` vs. `useRefreshTokens`
251
+
### `refreshTokenMode: 'offline'` vs. `'online'`
249
252
250
-
The two options request **different, mutually exclusive**refresh-token types, and you should set only one:
253
+
`refreshTokenMode` selects which refresh-token type the refresh-token grant uses. It is a sub-option of `useRefreshTokens` (which must be `true` for either mode) and defaults to `'offline'`:
Because `useRefreshTokens` injects `offline_access` — which conflicts with `online_access` — do **not** set both. In TypeScript, calling `createAuth0Client` with `useRefreshTokens` alongside `onlineAccess: true` is a compile-time error.
263
+
The two modes inject mutually exclusive scopes (`offline_access` vs. `online_access`), so the SDK emits only one — it never sends both. You select between them with `refreshTokenMode`, not by combining flags.
260
264
261
265
### Configuration validation
262
266
263
267
The SDK enforces the DPoP requirement at two layers:
264
268
265
-
1.**Compile-time (TypeScript).** When you call `createAuth0Client` with `onlineAccess` set to the literal `true`, the compiler requires `useDpop: true` and forbids `useRefreshTokens`:
269
+
1.**Compile-time (TypeScript).** When you call `createAuth0Client` with `refreshTokenMode` set to the literal `'online'`, the compiler requires both `useRefreshTokens: true` and `useDpop: true`:
266
270
267
271
```ts
268
-
// ❌ compile error: `useDpop` is required when `onlineAccess: true`
> The compile-time check only narrows when `onlineAccess` is a**literal**`true`. A dynamically-typed value (e.g. `onlineAccess: someBoolean`), an `as any` cast, or plain JavaScript all bypass it — which is why the runtime check below exists too.
283
+
> The compile-time check only narrows when `refreshTokenMode` is the**literal**`'online'`. A dynamically-typed value (e.g. `refreshTokenMode: someString`), an `as any` cast, or plain JavaScript all bypass it — which is why the runtime check below exists too.
280
284
281
-
2.**Runtime (all consumers, including plain JS).** The `Auth0Client` constructor throws an `InvalidConfigurationError` when `onlineAccess: true` but `useDpop` is `false` or unset. The error's message tells you to set `useDpop: true`:
285
+
2.**Runtime (all consumers, including plain JS).** The `Auth0Client` constructor throws an `InvalidConfigurationError` when `refreshTokenMode: 'online'` but `useRefreshTokens` or `useDpop` is not `true`. The error's `suggestion` tells you exactly which option to set:
Pass `onlineAccess: true` (together with the required `useDpop: true`) to use **Online Refresh Tokens** — non-rotating refresh tokens bound to the Auth0 session lifetime. The SDK injects the `online_access` scope and routes renewal through the refresh-token grant.
119
+
Set `refreshTokenMode: 'online'` (together with the required`useRefreshTokens: true` and`useDpop: true`) to use **Online Refresh Tokens** — non-rotating refresh tokens bound to the Auth0 session lifetime. The SDK injects the `online_access` scope and routes renewal through the refresh-token grant.
120
120
121
121
```js
122
122
constauth0=awaitcreateAuth0Client({
123
123
domain:'<AUTH0_DOMAIN>',
124
124
clientId:'<AUTH0_CLIENT_ID>',
125
-
onlineAccess:true,
125
+
useRefreshTokens:true,
126
+
refreshTokenMode:'online',
126
127
useDpop:true,
127
128
authorizationParams: {
128
129
redirect_uri:'<MY_CALLBACK_URL>'
129
130
}
130
131
});
131
132
```
132
133
133
-
DPoP is mandatory and must be set explicitly; do not set `useRefreshTokens` (it requests `offline_access`, which conflicts with online access). See [Online Access](https://github.com/auth0/auth0-spa-js/blob/main/EXAMPLES.md#online-access-online-refresh-tokens) in EXAMPLES.md for the full guide.
134
+
`refreshTokenMode` is a sub-option of `useRefreshTokens`: it defaults to `'offline'` (the rotating refresh tokens described above) and must be set to `'online'` for Online Refresh Tokens. Online mode requires both `useRefreshTokens: true` and `useDpop: true`. See [Online Access](https://github.com/auth0/auth0-spa-js/blob/main/EXAMPLES.md#online-access-online-refresh-tokens) in EXAMPLES.md for the full guide.
0 commit comments