Skip to content

Commit e2a4151

Browse files
docs: update Online Access configuration to use refreshTokenMode
1 parent 458e6d3 commit e2a4151

2 files changed

Lines changed: 27 additions & 20 deletions

File tree

EXAMPLES.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -219,66 +219,70 @@ This makes ORTs a good fit for SPAs that want a refresh-token renewal path whose
219219
220220
### Enabling Online Access
221221

222-
Set `onlineAccess: true` together with `useDpop: true`:
222+
Set `refreshTokenMode: 'online'` together with `useRefreshTokens: true` and `useDpop: true`:
223223

224224
```js
225225
const auth0 = await createAuth0Client({
226226
domain: '<AUTH0_DOMAIN>',
227227
clientId: '<AUTH0_CLIENT_ID>',
228-
onlineAccess: true,
228+
useRefreshTokens: true, // required — online access is a refresh-token grant
229+
refreshTokenMode: 'online',
229230
useDpop: true, // required — DPoP is mandatory for online access
230231
authorizationParams: {
231232
redirect_uri: '<MY_CALLBACK_URL>'
232233
}
233234
});
234235
```
235236

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+
236239
Enabling this option causes the SDK to:
237240

238241
- 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.
239242
- Route token renewal through the `refresh_token` grant against `/oauth/token` (the same path used by offline refresh tokens), rather than a hidden iframe.
240243
- Store the non-rotating ORT in the existing cache and reuse it on every refresh, never replacing it.
241244

242245
> [!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.
244247
245248
> [!NOTE]
246249
> 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).
247250
248-
### `onlineAccess` vs. `useRefreshTokens`
251+
### `refreshTokenMode: 'offline'` vs. `'online'`
249252

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'`:
251254

252-
| | `useRefreshTokens: true` | `onlineAccess: true` |
255+
| | `refreshTokenMode: 'offline'` (default) | `refreshTokenMode: 'online'` |
253256
| --- | --- | --- |
257+
| Requires | `useRefreshTokens: true` | `useRefreshTokens: true` + `useDpop: true` |
254258
| Scope injected | `offline_access` | `online_access` |
255259
| Token lifetime | Independent of the session (survives logout until revoked/expired) | Bound to the Auth0 session |
256260
| Rotation | Rotating (a new RT is issued on each refresh) | Non-rotating (same RT reused) |
257261
| DPoP | Optional | **Required** (`useDpop: true`) |
258262

259-
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.
260264

261265
### Configuration validation
262266

263267
The SDK enforces the DPoP requirement at two layers:
264268

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`:
266270

267271
```ts
268-
// ❌ compile error: `useDpop` is required when `onlineAccess: true`
269-
createAuth0Client({ domain, clientId, onlineAccess: true });
272+
// ❌ compile error: `useRefreshTokens: true` and `useDpop: true` are required when `refreshTokenMode: 'online'`
273+
createAuth0Client({ domain, clientId, refreshTokenMode: 'online' });
270274

271-
// ❌ compile error: `useRefreshTokens` conflicts with `onlineAccess`
272-
createAuth0Client({ domain, clientId, onlineAccess: true, useDpop: true, useRefreshTokens: true });
275+
// ❌ compile error: `useDpop: true` is still required
276+
createAuth0Client({ domain, clientId, refreshTokenMode: 'online', useRefreshTokens: true });
273277

274278
// ✅ valid
275-
createAuth0Client({ domain, clientId, onlineAccess: true, useDpop: true });
279+
createAuth0Client({ domain, clientId, refreshTokenMode: 'online', useRefreshTokens: true, useDpop: true });
276280
```
277281

278282
> [!NOTE]
279-
> 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.
280284
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:
282286

283287
```js
284288
import { InvalidConfigurationError } from '@auth0/auth0-spa-js';
@@ -287,7 +291,8 @@ The SDK enforces the DPoP requirement at two layers:
287291
const auth0 = await createAuth0Client({
288292
domain: '<AUTH0_DOMAIN>',
289293
clientId: '<AUTH0_CLIENT_ID>',
290-
onlineAccess: true // missing useDpop: true
294+
refreshTokenMode: 'online',
295+
useRefreshTokens: true // missing useDpop: true
291296
});
292297
} catch (e) {
293298
if (e instanceof InvalidConfigurationError) {
@@ -315,7 +320,8 @@ Online access is compatible with [MRRT](#using-multi-resource-refresh-tokens): a
315320
const auth0 = await createAuth0Client({
316321
domain: '<AUTH0_DOMAIN>',
317322
clientId: '<AUTH0_CLIENT_ID>',
318-
onlineAccess: true,
323+
useRefreshTokens: true,
324+
refreshTokenMode: 'online',
319325
useDpop: true,
320326
useMrrt: true,
321327
authorizationParams: {

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,22 @@ window.addEventListener('load', async () => {
116116

117117
### Online Access
118118

119-
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.
120120

121121
```js
122122
const auth0 = await createAuth0Client({
123123
domain: '<AUTH0_DOMAIN>',
124124
clientId: '<AUTH0_CLIENT_ID>',
125-
onlineAccess: true,
125+
useRefreshTokens: true,
126+
refreshTokenMode: 'online',
126127
useDpop: true,
127128
authorizationParams: {
128129
redirect_uri: '<MY_CALLBACK_URL>'
129130
}
130131
});
131132
```
132133

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

135136
### More Examples
136137

0 commit comments

Comments
 (0)