@auth0/auth0-spa-js 2.19.0 → 2.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/auth0-spa-js.development.js +38 -24
  2. package/dist/auth0-spa-js.development.js.map +1 -1
  3. package/dist/auth0-spa-js.production.esm.js +1 -1
  4. package/dist/auth0-spa-js.production.esm.js.map +1 -1
  5. package/dist/auth0-spa-js.production.js +1 -1
  6. package/dist/auth0-spa-js.production.js.map +1 -1
  7. package/dist/lib/auth0-spa-js.cjs.js +38 -24
  8. package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
  9. package/dist/typings/Auth0Client.d.ts +476 -476
  10. package/dist/typings/Auth0Client.utils.d.ts +90 -90
  11. package/dist/typings/MyAccountApiClient.d.ts +92 -92
  12. package/dist/typings/TokenExchange.d.ts +77 -77
  13. package/dist/typings/api.d.ts +33 -33
  14. package/dist/typings/cache/cache-localstorage.d.ts +7 -7
  15. package/dist/typings/cache/cache-manager.d.ts +69 -69
  16. package/dist/typings/cache/cache-memory.d.ts +4 -4
  17. package/dist/typings/cache/index.d.ts +4 -4
  18. package/dist/typings/cache/key-manifest.d.ts +12 -12
  19. package/dist/typings/cache/shared.d.ts +68 -68
  20. package/dist/typings/constants.d.ts +58 -58
  21. package/dist/typings/dpop/dpop.d.ts +17 -17
  22. package/dist/typings/dpop/storage.d.ts +27 -27
  23. package/dist/typings/dpop/utils.d.ts +15 -15
  24. package/dist/typings/errors.d.ts +96 -96
  25. package/dist/typings/fetcher.d.ts +54 -54
  26. package/dist/typings/global.d.ts +826 -826
  27. package/dist/typings/http.d.ts +11 -11
  28. package/dist/typings/index.d.ts +24 -24
  29. package/dist/typings/jwt.d.ts +21 -21
  30. package/dist/typings/lock.d.ts +32 -32
  31. package/dist/typings/mfa/MfaApiClient.d.ts +225 -225
  32. package/dist/typings/mfa/MfaContextManager.d.ts +79 -79
  33. package/dist/typings/mfa/constants.d.ts +23 -23
  34. package/dist/typings/mfa/errors.d.ts +117 -117
  35. package/dist/typings/mfa/index.d.ts +4 -4
  36. package/dist/typings/mfa/types.d.ts +181 -181
  37. package/dist/typings/mfa/utils.d.ts +23 -23
  38. package/dist/typings/promise-utils.d.ts +2 -2
  39. package/dist/typings/scope.d.ts +35 -35
  40. package/dist/typings/storage.d.ts +26 -26
  41. package/dist/typings/transaction-manager.d.ts +33 -33
  42. package/dist/typings/utils.d.ts +36 -36
  43. package/dist/typings/version.d.ts +2 -2
  44. package/dist/typings/worker/token.worker.d.ts +1 -1
  45. package/dist/typings/worker/worker.types.d.ts +27 -27
  46. package/dist/typings/worker/worker.utils.d.ts +13 -13
  47. package/package.json +1 -1
  48. package/src/api.ts +15 -11
  49. package/src/cache/cache-manager.ts +28 -9
  50. package/src/version.ts +1 -1
@@ -1,476 +1,476 @@
1
- import { Auth0ClientOptions, RedirectLoginOptions, PopupLoginOptions, PopupConfigOptions, RedirectLoginResult, GetTokenSilentlyOptions, GetTokenWithPopupOptions, LogoutOptions, User, IdToken, GetTokenSilentlyVerboseResponse, TokenEndpointResponse, ConnectAccountRedirectResult, RedirectConnectAccountOptions, ClientConfiguration, RevokeRefreshTokenOptions } from './global';
2
- import { CustomTokenExchangeOptions } from './TokenExchange';
3
- import { Dpop } from './dpop/dpop';
4
- import { Fetcher, type FetcherConfig, type CustomFetchMinimalOutput } from './fetcher';
5
- import { MfaApiClient } from './mfa';
6
- /**
7
- * Auth0 SDK for Single Page Applications using [Authorization Code Grant Flow with PKCE](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce).
8
- */
9
- export declare class Auth0Client {
10
- private readonly transactionManager;
11
- private readonly cacheManager;
12
- private readonly lockManager;
13
- private readonly domainUrl;
14
- private readonly tokenIssuer;
15
- private readonly scope;
16
- private readonly cookieStorage;
17
- private readonly dpop;
18
- private readonly sessionCheckExpiryDays;
19
- private readonly orgHintCookieName;
20
- private readonly isAuthenticatedCookieName;
21
- private readonly nowProvider;
22
- private readonly httpTimeoutMs;
23
- private readonly options;
24
- private readonly userCache;
25
- private readonly myAccountApi;
26
- /**
27
- * MFA API client for multi-factor authentication operations.
28
- *
29
- * Provides methods for:
30
- * - Listing enrolled authenticators
31
- * - Enrolling new authenticators (OTP, SMS, Voice, Push, Email)
32
- * - Initiating MFA challenges
33
- * - Verifying MFA challenges
34
- */
35
- readonly mfa: MfaApiClient;
36
- private worker?;
37
- private readonly authJsClient;
38
- private readonly defaultOptions;
39
- constructor(options: Auth0ClientOptions);
40
- /**
41
- * Returns a readonly copy of the initialization configuration.
42
- *
43
- * @returns An object containing domain and clientId
44
- *
45
- * @example
46
- * ```typescript
47
- * const auth0 = new Auth0Client({
48
- * domain: 'tenant.auth0.com',
49
- * clientId: 'abc123'
50
- * });
51
- *
52
- * const config = auth0.getConfiguration();
53
- * // { domain: 'tenant.auth0.com', clientId: 'abc123' }
54
- * ```
55
- */
56
- getConfiguration(): Readonly<ClientConfiguration>;
57
- private _url;
58
- private _authorizeUrl;
59
- private _verifyIdToken;
60
- private _processOrgHint;
61
- /**
62
- * Extracts the session transfer token from the current URL query parameters
63
- * for Native to Web SSO flows.
64
- *
65
- * @param paramName The query parameter name to extract from the URL
66
- * @returns The session transfer token if present, undefined otherwise
67
- */
68
- private _extractSessionTransferToken;
69
- /**
70
- * Clears the session transfer token from the current URL using the History API.
71
- * This prevents the token from being re-sent on subsequent authentication requests,
72
- * which is important since session transfer tokens are typically single-use.
73
- *
74
- * @param paramName The query parameter name to remove from the URL
75
- */
76
- private _clearSessionTransferTokenFromUrl;
77
- /**
78
- * Applies the session transfer token from the URL to the authorization parameters
79
- * if configured and not already provided.
80
- *
81
- * @param authorizationParams The authorization parameters to enhance
82
- * @returns The authorization parameters with session_transfer_token added if applicable
83
- */
84
- private _applySessionTransferToken;
85
- private _prepareAuthorizeUrl;
86
- /**
87
- * ```js
88
- * try {
89
- * await auth0.loginWithPopup(options);
90
- * } catch(e) {
91
- * if (e instanceof PopupCancelledError) {
92
- * // Popup was closed before login completed
93
- * }
94
- * }
95
- * ```
96
- *
97
- * Opens a popup with the `/authorize` URL using the parameters
98
- * provided as arguments. Random and secure `state` and `nonce`
99
- * parameters will be auto-generated. If the response is successful,
100
- * results will be valid according to their expiration times.
101
- *
102
- * IMPORTANT: This method has to be called from an event handler
103
- * that was started by the user like a button click, for example,
104
- * otherwise the popup will be blocked in most browsers.
105
- *
106
- * @param options
107
- * @param config
108
- */
109
- loginWithPopup(options?: PopupLoginOptions, config?: PopupConfigOptions): Promise<void>;
110
- /**
111
- * ```js
112
- * const user = await auth0.getUser();
113
- * ```
114
- *
115
- * Returns the user information if available (decoded
116
- * from the `id_token`).
117
- *
118
- * @typeparam TUser The type to return, has to extend {@link User}.
119
- */
120
- getUser<TUser extends User>(): Promise<TUser | undefined>;
121
- /**
122
- * ```js
123
- * const claims = await auth0.getIdTokenClaims();
124
- * ```
125
- *
126
- * Returns all claims from the id_token if available.
127
- */
128
- getIdTokenClaims(): Promise<IdToken | undefined>;
129
- /**
130
- * ```js
131
- * await auth0.loginWithRedirect(options);
132
- * ```
133
- *
134
- * Performs a redirect to `/authorize` using the parameters
135
- * provided as arguments. Random and secure `state` and `nonce`
136
- * parameters will be auto-generated.
137
- *
138
- * @param options
139
- */
140
- loginWithRedirect<TAppState = any>(options?: RedirectLoginOptions<TAppState>): Promise<void>;
141
- /**
142
- * After the browser redirects back to the callback page,
143
- * call `handleRedirectCallback` to handle success and error
144
- * responses from Auth0. If the response is successful, results
145
- * will be valid according to their expiration times.
146
- */
147
- handleRedirectCallback<TAppState = any>(url?: string): Promise<RedirectLoginResult<TAppState> | ConnectAccountRedirectResult<TAppState>>;
148
- /**
149
- * Handles the redirect callback from the login flow.
150
- *
151
- * @template AppState - The application state persisted from the /authorize redirect.
152
- * @param {string} authenticationResult - The parsed authentication result from the URL.
153
- * @param {string} transaction - The login transaction.
154
- *
155
- * @returns {RedirectLoginResult} Resolves with the persisted app state.
156
- * @throws {GenericError | Error} If the transaction is missing, invalid, or the code exchange fails.
157
- */
158
- private _handleLoginRedirectCallback;
159
- /**
160
- * Handles the redirect callback from the connect account flow.
161
- * This works the same as the redirect from the login flow expect it verifies the `connect_code`
162
- * with the My Account API rather than the `code` with the Authorization Server.
163
- *
164
- * @template AppState - The application state persisted from the connect redirect.
165
- * @param {string} connectResult - The parsed connect accounts result from the URL.
166
- * @param {string} transaction - The login transaction.
167
- * @returns {Promise<ConnectAccountRedirectResult>} The result of the My Account API, including any persisted app state.
168
- * @throws {GenericError | MyAccountApiError} If the transaction is missing, invalid, or an error is returned from the My Account API.
169
- */
170
- private _handleConnectAccountRedirectCallback;
171
- /**
172
- * ```js
173
- * await auth0.checkSession();
174
- * ```
175
- *
176
- * Check if the user is logged in using `getTokenSilently`. The difference
177
- * with `getTokenSilently` is that this doesn't return a token, but it will
178
- * pre-fill the token cache.
179
- *
180
- * This method also heeds the `auth0.{clientId}.is.authenticated` cookie, as an optimization
181
- * to prevent calling Auth0 unnecessarily. If the cookie is not present because
182
- * there was no previous login (or it has expired) then tokens will not be refreshed.
183
- *
184
- * It should be used for silently logging in the user when you instantiate the
185
- * `Auth0Client` constructor. You should not need this if you are using the
186
- * `createAuth0Client` factory.
187
- *
188
- * **Note:** the cookie **may not** be present if running an app using a private tab, as some
189
- * browsers clear JS cookie data and local storage when the tab or page is closed, or on page reload. This effectively
190
- * means that `checkSession` could silently return without authenticating the user on page refresh when
191
- * using a private tab, despite having previously logged in. As a workaround, use `getTokenSilently` instead
192
- * and handle the possible `login_required` error [as shown in the readme](https://github.com/auth0/auth0-spa-js#creating-the-client).
193
- *
194
- * @param options
195
- */
196
- checkSession(options?: GetTokenSilentlyOptions): Promise<void>;
197
- /**
198
- * Fetches a new access token and returns the response from the /oauth/token endpoint, omitting the refresh token.
199
- *
200
- * @param options
201
- */
202
- getTokenSilently(options: GetTokenSilentlyOptions & {
203
- detailedResponse: true;
204
- }): Promise<GetTokenSilentlyVerboseResponse>;
205
- /**
206
- * Fetches a new access token and returns it.
207
- *
208
- * @param options
209
- */
210
- getTokenSilently(options?: GetTokenSilentlyOptions): Promise<string>;
211
- private _getTokenSilently;
212
- /**
213
- * Checks if an error should be handled by the interactive error handler.
214
- * Matches:
215
- * - MfaRequiredError (refresh token path, error='mfa_required')
216
- * - GenericError from iframe path (error='login_required',
217
- * error_description='Multifactor authentication required')
218
- * Extensible for future interactive error types.
219
- */
220
- private _isInteractiveError;
221
- /**
222
- * Checks if a login_required error from the iframe flow is actually
223
- * an MFA step-up requirement. The /authorize endpoint returns
224
- * error='login_required' with error_description='Multifactor authentication required'
225
- * when MFA is needed but prompt=none prevents interaction.
226
- */
227
- private _isIframeMfaError;
228
- /**
229
- * Handles MFA errors by opening a popup to complete authentication,
230
- * then reads the resulting token from cache.
231
- */
232
- private _handleInteractiveErrorWithPopup;
233
- /**
234
- * ```js
235
- * const token = await auth0.getTokenWithPopup(options);
236
- * ```
237
- * Opens a popup with the `/authorize` URL using the parameters
238
- * provided as arguments. Random and secure `state` and `nonce`
239
- * parameters will be auto-generated. If the response is successful,
240
- * results will be valid according to their expiration times.
241
- *
242
- * @param options
243
- * @param config
244
- */
245
- getTokenWithPopup(options?: GetTokenWithPopupOptions, config?: PopupConfigOptions): Promise<string | undefined>;
246
- /**
247
- * ```js
248
- * const isAuthenticated = await auth0.isAuthenticated();
249
- * ```
250
- *
251
- * Returns `true` if there's valid information stored,
252
- * otherwise returns `false`.
253
- *
254
- */
255
- isAuthenticated(): Promise<boolean>;
256
- /**
257
- * ```js
258
- * await auth0.buildLogoutUrl(options);
259
- * ```
260
- *
261
- * Builds a URL to the logout endpoint using the parameters provided as arguments.
262
- * @param options
263
- */
264
- private _buildLogoutUrl;
265
- /**
266
- * ```js
267
- * await auth0.revokeRefreshToken();
268
- * ```
269
- *
270
- * Revokes the refresh token using the `/oauth/revoke` endpoint.
271
- * This invalidates the refresh token so it can no longer be used to obtain new access tokens.
272
- *
273
- * The method works with both memory and localStorage cache modes:
274
- * - For memory storage with worker: The refresh token never leaves the worker thread,
275
- * maintaining security isolation
276
- * - For localStorage: The token is retrieved from cache and revoked
277
- *
278
- * If `useRefreshTokens` is disabled, this method does nothing.
279
- *
280
- * **Important:** This method revokes the refresh token for a single audience. If your
281
- * application requests tokens for multiple audiences, each audience may have its own
282
- * refresh token. To fully revoke all refresh tokens, call this method once per audience.
283
- * If you want to terminate the user's session entirely, use `logout()` instead.
284
- *
285
- * When using Multi-Resource Refresh Tokens (MRRT), a single refresh token may cover
286
- * multiple audiences. In that case, revoking it will affect all cache entries that
287
- * share the same token.
288
- *
289
- * @param options - Optional parameters to identify which refresh token to revoke.
290
- * Defaults to the audience configured in `authorizationParams`.
291
- *
292
- * @example
293
- * // Revoke the default refresh token
294
- * await auth0.revokeRefreshToken();
295
- *
296
- * @example
297
- * // Revoke refresh tokens for each audience individually
298
- * await auth0.revokeRefreshToken({ audience: 'https://api.example.com' });
299
- * await auth0.revokeRefreshToken({ audience: 'https://api2.example.com' });
300
- */
301
- revokeRefreshToken(options?: RevokeRefreshTokenOptions): Promise<void>;
302
- /**
303
- * ```js
304
- * await auth0.logout(options);
305
- * ```
306
- *
307
- * Clears the application session and performs a redirect to `/v2/logout`, using
308
- * the parameters provided as arguments, to clear the Auth0 session.
309
- *
310
- * If the `federated` option is specified it also clears the Identity Provider session.
311
- * [Read more about how Logout works at Auth0](https://auth0.com/docs/logout).
312
- *
313
- * @param options
314
- */
315
- logout(options?: LogoutOptions): Promise<void>;
316
- private _getTokenFromIFrame;
317
- private _getTokenUsingRefreshToken;
318
- private _saveEntryInCache;
319
- private _getIdTokenFromCache;
320
- private _getEntryFromCache;
321
- private _requestToken;
322
- /**
323
- * ```js
324
- * await auth0.loginWithCustomTokenExchange(options);
325
- * ```
326
- *
327
- * Exchanges an external subject token for Auth0 tokens and logs the user in.
328
- * This method implements the Custom Token Exchange grant as specified in RFC 8693.
329
- *
330
- * The exchanged tokens are automatically cached, establishing an authenticated session.
331
- * After calling this method, you can use `getUser()`, `getIdTokenClaims()`, and
332
- * `getTokenSilently()` to access the user's information and tokens.
333
- *
334
- * @param {CustomTokenExchangeOptions} options - The options required to perform the token exchange.
335
- *
336
- * @returns {Promise<TokenEndpointResponse>} A promise that resolves to the token endpoint response,
337
- * which contains the issued Auth0 tokens (access_token, id_token, etc.).
338
- *
339
- * The request includes the following parameters:
340
- * - `grant_type`: "urn:ietf:params:oauth:grant-type:token-exchange"
341
- * - `subject_token`: The external token to exchange
342
- * - `subject_token_type`: The type identifier of the external token
343
- * - `scope`: Merged scopes from the request and SDK defaults
344
- * - `audience`: Target audience (defaults to SDK configuration)
345
- * - `organization`: Optional organization ID/name for org-scoped authentication
346
- *
347
- * **Example Usage:**
348
- *
349
- * ```js
350
- * const options = {
351
- * subject_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...',
352
- * subject_token_type: 'urn:acme:legacy-system-token',
353
- * scope: 'openid profile email',
354
- * audience: 'https://api.example.com',
355
- * organization: 'org_12345'
356
- * };
357
- *
358
- * try {
359
- * const tokenResponse = await auth0.loginWithCustomTokenExchange(options);
360
- * console.log('Access token:', tokenResponse.access_token);
361
- *
362
- * // User is now logged in - access user info
363
- * const user = await auth0.getUser();
364
- * console.log('Logged in user:', user);
365
- * } catch (error) {
366
- * console.error('Token exchange failed:', error);
367
- * }
368
- * ```
369
- */
370
- loginWithCustomTokenExchange(options: CustomTokenExchangeOptions): Promise<TokenEndpointResponse>;
371
- /**
372
- * @deprecated Use `loginWithCustomTokenExchange()` instead. This method will be removed in the next major version.
373
- *
374
- * Exchanges an external subject token for Auth0 tokens.
375
- *
376
- * @param {CustomTokenExchangeOptions} options - The options required to perform the token exchange.
377
- * @returns {Promise<TokenEndpointResponse>} A promise that resolves to the token endpoint response.
378
- *
379
- * **Example:**
380
- * ```js
381
- * // Instead of:
382
- * const tokens = await auth0.exchangeToken(options);
383
- *
384
- * // Use:
385
- * const tokens = await auth0.loginWithCustomTokenExchange(options);
386
- * ```
387
- */
388
- exchangeToken(options: CustomTokenExchangeOptions): Promise<TokenEndpointResponse>;
389
- protected _assertDpop(dpop: Dpop | undefined): asserts dpop is Dpop;
390
- /**
391
- * Returns the current DPoP nonce used for making requests to Auth0.
392
- *
393
- * It can return `undefined` because when starting fresh it will not
394
- * be populated until after the first response from the server.
395
- *
396
- * It requires enabling the {@link Auth0ClientOptions.useDpop} option.
397
- *
398
- * @param nonce The nonce value.
399
- * @param id The identifier of a nonce: if absent, it will get the nonce
400
- * used for requests to Auth0. Otherwise, it will be used to
401
- * select a specific non-Auth0 nonce.
402
- */
403
- getDpopNonce(id?: string): Promise<string | undefined>;
404
- /**
405
- * Sets the current DPoP nonce used for making requests to Auth0.
406
- *
407
- * It requires enabling the {@link Auth0ClientOptions.useDpop} option.
408
- *
409
- * @param nonce The nonce value.
410
- * @param id The identifier of a nonce: if absent, it will set the nonce
411
- * used for requests to Auth0. Otherwise, it will be used to
412
- * select a specific non-Auth0 nonce.
413
- */
414
- setDpopNonce(nonce: string, id?: string): Promise<void>;
415
- /**
416
- * Returns a string to be used to demonstrate possession of the private
417
- * key used to cryptographically bind access tokens with DPoP.
418
- *
419
- * It requires enabling the {@link Auth0ClientOptions.useDpop} option.
420
- */
421
- generateDpopProof(params: {
422
- url: string;
423
- method: string;
424
- nonce?: string;
425
- accessToken: string;
426
- }): Promise<string>;
427
- /**
428
- * Returns a new `Fetcher` class that will contain a `fetchWithAuth()` method.
429
- * This is a drop-in replacement for the Fetch API's `fetch()` method, but will
430
- * handle certain authentication logic for you, like building the proper auth
431
- * headers or managing DPoP nonces and retries automatically.
432
- *
433
- * Check the `EXAMPLES.md` file for a deeper look into this method.
434
- */
435
- createFetcher<TOutput extends CustomFetchMinimalOutput = Response>(config?: FetcherConfig<TOutput>): Fetcher<TOutput>;
436
- /**
437
- * Initiates a redirect to connect the user's account with a specified connection.
438
- * This method generates PKCE parameters, creates a transaction, and redirects to the /connect endpoint.
439
- *
440
- * You must enable `Offline Access` from the Connection Permissions settings to be able to use the connection with Connected Accounts.
441
- *
442
- * @template TAppState - The application state to persist through the transaction.
443
- * @param {RedirectConnectAccountOptions<TAppState>} options - Options for the connect account redirect flow.
444
- * @param {string} options.connection - The name of the connection to link (e.g. 'google-oauth2').
445
- * @param {string[]} [options.scopes] - Array of scopes to request from the Identity Provider during the connect account flow.
446
- * @param {AuthorizationParams} [options.authorization_params] - Additional authorization parameters for the request to the upstream IdP.
447
- * @param {string} [options.redirectUri] - The URI to redirect back to after connecting the account.
448
- * @param {TAppState} [options.appState] - Application state to persist through the transaction.
449
- * @param {(url: string) => Promise<void>} [options.openUrl] - Custom function to open the URL.
450
- *
451
- * @returns {Promise<void>} Resolves when the redirect is initiated.
452
- * @throws {MyAccountApiError} If the connect request to the My Account API fails.
453
- */
454
- connectAccountWithRedirect<TAppState = any>(options: RedirectConnectAccountOptions<TAppState>): Promise<void>;
455
- /**
456
- * @internal
457
- * Internal method used by MfaApiClient to exchange MFA tokens for access tokens.
458
- * This method should not be called directly by applications.
459
- */
460
- _requestTokenForMfa(options: {
461
- grant_type: string;
462
- mfaToken: string;
463
- scope?: string;
464
- audience?: string;
465
- otp?: string;
466
- binding_code?: string;
467
- oob_code?: string;
468
- recovery_code?: string;
469
- }, additionalParameters?: RequestTokenAdditionalParameters): Promise<TokenEndpointResponse>;
470
- }
471
- interface RequestTokenAdditionalParameters {
472
- nonceIn?: string;
473
- organization?: string;
474
- scopesToRequest?: string;
475
- }
476
- export {};
1
+ import { Auth0ClientOptions, RedirectLoginOptions, PopupLoginOptions, PopupConfigOptions, RedirectLoginResult, GetTokenSilentlyOptions, GetTokenWithPopupOptions, LogoutOptions, User, IdToken, GetTokenSilentlyVerboseResponse, TokenEndpointResponse, ConnectAccountRedirectResult, RedirectConnectAccountOptions, ClientConfiguration, RevokeRefreshTokenOptions } from './global';
2
+ import { CustomTokenExchangeOptions } from './TokenExchange';
3
+ import { Dpop } from './dpop/dpop';
4
+ import { Fetcher, type FetcherConfig, type CustomFetchMinimalOutput } from './fetcher';
5
+ import { MfaApiClient } from './mfa';
6
+ /**
7
+ * Auth0 SDK for Single Page Applications using [Authorization Code Grant Flow with PKCE](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce).
8
+ */
9
+ export declare class Auth0Client {
10
+ private readonly transactionManager;
11
+ private readonly cacheManager;
12
+ private readonly lockManager;
13
+ private readonly domainUrl;
14
+ private readonly tokenIssuer;
15
+ private readonly scope;
16
+ private readonly cookieStorage;
17
+ private readonly dpop;
18
+ private readonly sessionCheckExpiryDays;
19
+ private readonly orgHintCookieName;
20
+ private readonly isAuthenticatedCookieName;
21
+ private readonly nowProvider;
22
+ private readonly httpTimeoutMs;
23
+ private readonly options;
24
+ private readonly userCache;
25
+ private readonly myAccountApi;
26
+ /**
27
+ * MFA API client for multi-factor authentication operations.
28
+ *
29
+ * Provides methods for:
30
+ * - Listing enrolled authenticators
31
+ * - Enrolling new authenticators (OTP, SMS, Voice, Push, Email)
32
+ * - Initiating MFA challenges
33
+ * - Verifying MFA challenges
34
+ */
35
+ readonly mfa: MfaApiClient;
36
+ private worker?;
37
+ private readonly authJsClient;
38
+ private readonly defaultOptions;
39
+ constructor(options: Auth0ClientOptions);
40
+ /**
41
+ * Returns a readonly copy of the initialization configuration.
42
+ *
43
+ * @returns An object containing domain and clientId
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const auth0 = new Auth0Client({
48
+ * domain: 'tenant.auth0.com',
49
+ * clientId: 'abc123'
50
+ * });
51
+ *
52
+ * const config = auth0.getConfiguration();
53
+ * // { domain: 'tenant.auth0.com', clientId: 'abc123' }
54
+ * ```
55
+ */
56
+ getConfiguration(): Readonly<ClientConfiguration>;
57
+ private _url;
58
+ private _authorizeUrl;
59
+ private _verifyIdToken;
60
+ private _processOrgHint;
61
+ /**
62
+ * Extracts the session transfer token from the current URL query parameters
63
+ * for Native to Web SSO flows.
64
+ *
65
+ * @param paramName The query parameter name to extract from the URL
66
+ * @returns The session transfer token if present, undefined otherwise
67
+ */
68
+ private _extractSessionTransferToken;
69
+ /**
70
+ * Clears the session transfer token from the current URL using the History API.
71
+ * This prevents the token from being re-sent on subsequent authentication requests,
72
+ * which is important since session transfer tokens are typically single-use.
73
+ *
74
+ * @param paramName The query parameter name to remove from the URL
75
+ */
76
+ private _clearSessionTransferTokenFromUrl;
77
+ /**
78
+ * Applies the session transfer token from the URL to the authorization parameters
79
+ * if configured and not already provided.
80
+ *
81
+ * @param authorizationParams The authorization parameters to enhance
82
+ * @returns The authorization parameters with session_transfer_token added if applicable
83
+ */
84
+ private _applySessionTransferToken;
85
+ private _prepareAuthorizeUrl;
86
+ /**
87
+ * ```js
88
+ * try {
89
+ * await auth0.loginWithPopup(options);
90
+ * } catch(e) {
91
+ * if (e instanceof PopupCancelledError) {
92
+ * // Popup was closed before login completed
93
+ * }
94
+ * }
95
+ * ```
96
+ *
97
+ * Opens a popup with the `/authorize` URL using the parameters
98
+ * provided as arguments. Random and secure `state` and `nonce`
99
+ * parameters will be auto-generated. If the response is successful,
100
+ * results will be valid according to their expiration times.
101
+ *
102
+ * IMPORTANT: This method has to be called from an event handler
103
+ * that was started by the user like a button click, for example,
104
+ * otherwise the popup will be blocked in most browsers.
105
+ *
106
+ * @param options
107
+ * @param config
108
+ */
109
+ loginWithPopup(options?: PopupLoginOptions, config?: PopupConfigOptions): Promise<void>;
110
+ /**
111
+ * ```js
112
+ * const user = await auth0.getUser();
113
+ * ```
114
+ *
115
+ * Returns the user information if available (decoded
116
+ * from the `id_token`).
117
+ *
118
+ * @typeparam TUser The type to return, has to extend {@link User}.
119
+ */
120
+ getUser<TUser extends User>(): Promise<TUser | undefined>;
121
+ /**
122
+ * ```js
123
+ * const claims = await auth0.getIdTokenClaims();
124
+ * ```
125
+ *
126
+ * Returns all claims from the id_token if available.
127
+ */
128
+ getIdTokenClaims(): Promise<IdToken | undefined>;
129
+ /**
130
+ * ```js
131
+ * await auth0.loginWithRedirect(options);
132
+ * ```
133
+ *
134
+ * Performs a redirect to `/authorize` using the parameters
135
+ * provided as arguments. Random and secure `state` and `nonce`
136
+ * parameters will be auto-generated.
137
+ *
138
+ * @param options
139
+ */
140
+ loginWithRedirect<TAppState = any>(options?: RedirectLoginOptions<TAppState>): Promise<void>;
141
+ /**
142
+ * After the browser redirects back to the callback page,
143
+ * call `handleRedirectCallback` to handle success and error
144
+ * responses from Auth0. If the response is successful, results
145
+ * will be valid according to their expiration times.
146
+ */
147
+ handleRedirectCallback<TAppState = any>(url?: string): Promise<RedirectLoginResult<TAppState> | ConnectAccountRedirectResult<TAppState>>;
148
+ /**
149
+ * Handles the redirect callback from the login flow.
150
+ *
151
+ * @template AppState - The application state persisted from the /authorize redirect.
152
+ * @param {string} authenticationResult - The parsed authentication result from the URL.
153
+ * @param {string} transaction - The login transaction.
154
+ *
155
+ * @returns {RedirectLoginResult} Resolves with the persisted app state.
156
+ * @throws {GenericError | Error} If the transaction is missing, invalid, or the code exchange fails.
157
+ */
158
+ private _handleLoginRedirectCallback;
159
+ /**
160
+ * Handles the redirect callback from the connect account flow.
161
+ * This works the same as the redirect from the login flow expect it verifies the `connect_code`
162
+ * with the My Account API rather than the `code` with the Authorization Server.
163
+ *
164
+ * @template AppState - The application state persisted from the connect redirect.
165
+ * @param {string} connectResult - The parsed connect accounts result from the URL.
166
+ * @param {string} transaction - The login transaction.
167
+ * @returns {Promise<ConnectAccountRedirectResult>} The result of the My Account API, including any persisted app state.
168
+ * @throws {GenericError | MyAccountApiError} If the transaction is missing, invalid, or an error is returned from the My Account API.
169
+ */
170
+ private _handleConnectAccountRedirectCallback;
171
+ /**
172
+ * ```js
173
+ * await auth0.checkSession();
174
+ * ```
175
+ *
176
+ * Check if the user is logged in using `getTokenSilently`. The difference
177
+ * with `getTokenSilently` is that this doesn't return a token, but it will
178
+ * pre-fill the token cache.
179
+ *
180
+ * This method also heeds the `auth0.{clientId}.is.authenticated` cookie, as an optimization
181
+ * to prevent calling Auth0 unnecessarily. If the cookie is not present because
182
+ * there was no previous login (or it has expired) then tokens will not be refreshed.
183
+ *
184
+ * It should be used for silently logging in the user when you instantiate the
185
+ * `Auth0Client` constructor. You should not need this if you are using the
186
+ * `createAuth0Client` factory.
187
+ *
188
+ * **Note:** the cookie **may not** be present if running an app using a private tab, as some
189
+ * browsers clear JS cookie data and local storage when the tab or page is closed, or on page reload. This effectively
190
+ * means that `checkSession` could silently return without authenticating the user on page refresh when
191
+ * using a private tab, despite having previously logged in. As a workaround, use `getTokenSilently` instead
192
+ * and handle the possible `login_required` error [as shown in the readme](https://github.com/auth0/auth0-spa-js#creating-the-client).
193
+ *
194
+ * @param options
195
+ */
196
+ checkSession(options?: GetTokenSilentlyOptions): Promise<void>;
197
+ /**
198
+ * Fetches a new access token and returns the response from the /oauth/token endpoint, omitting the refresh token.
199
+ *
200
+ * @param options
201
+ */
202
+ getTokenSilently(options: GetTokenSilentlyOptions & {
203
+ detailedResponse: true;
204
+ }): Promise<GetTokenSilentlyVerboseResponse>;
205
+ /**
206
+ * Fetches a new access token and returns it.
207
+ *
208
+ * @param options
209
+ */
210
+ getTokenSilently(options?: GetTokenSilentlyOptions): Promise<string>;
211
+ private _getTokenSilently;
212
+ /**
213
+ * Checks if an error should be handled by the interactive error handler.
214
+ * Matches:
215
+ * - MfaRequiredError (refresh token path, error='mfa_required')
216
+ * - GenericError from iframe path (error='login_required',
217
+ * error_description='Multifactor authentication required')
218
+ * Extensible for future interactive error types.
219
+ */
220
+ private _isInteractiveError;
221
+ /**
222
+ * Checks if a login_required error from the iframe flow is actually
223
+ * an MFA step-up requirement. The /authorize endpoint returns
224
+ * error='login_required' with error_description='Multifactor authentication required'
225
+ * when MFA is needed but prompt=none prevents interaction.
226
+ */
227
+ private _isIframeMfaError;
228
+ /**
229
+ * Handles MFA errors by opening a popup to complete authentication,
230
+ * then reads the resulting token from cache.
231
+ */
232
+ private _handleInteractiveErrorWithPopup;
233
+ /**
234
+ * ```js
235
+ * const token = await auth0.getTokenWithPopup(options);
236
+ * ```
237
+ * Opens a popup with the `/authorize` URL using the parameters
238
+ * provided as arguments. Random and secure `state` and `nonce`
239
+ * parameters will be auto-generated. If the response is successful,
240
+ * results will be valid according to their expiration times.
241
+ *
242
+ * @param options
243
+ * @param config
244
+ */
245
+ getTokenWithPopup(options?: GetTokenWithPopupOptions, config?: PopupConfigOptions): Promise<string | undefined>;
246
+ /**
247
+ * ```js
248
+ * const isAuthenticated = await auth0.isAuthenticated();
249
+ * ```
250
+ *
251
+ * Returns `true` if there's valid information stored,
252
+ * otherwise returns `false`.
253
+ *
254
+ */
255
+ isAuthenticated(): Promise<boolean>;
256
+ /**
257
+ * ```js
258
+ * await auth0.buildLogoutUrl(options);
259
+ * ```
260
+ *
261
+ * Builds a URL to the logout endpoint using the parameters provided as arguments.
262
+ * @param options
263
+ */
264
+ private _buildLogoutUrl;
265
+ /**
266
+ * ```js
267
+ * await auth0.revokeRefreshToken();
268
+ * ```
269
+ *
270
+ * Revokes the refresh token using the `/oauth/revoke` endpoint.
271
+ * This invalidates the refresh token so it can no longer be used to obtain new access tokens.
272
+ *
273
+ * The method works with both memory and localStorage cache modes:
274
+ * - For memory storage with worker: The refresh token never leaves the worker thread,
275
+ * maintaining security isolation
276
+ * - For localStorage: The token is retrieved from cache and revoked
277
+ *
278
+ * If `useRefreshTokens` is disabled, this method does nothing.
279
+ *
280
+ * **Important:** This method revokes the refresh token for a single audience. If your
281
+ * application requests tokens for multiple audiences, each audience may have its own
282
+ * refresh token. To fully revoke all refresh tokens, call this method once per audience.
283
+ * If you want to terminate the user's session entirely, use `logout()` instead.
284
+ *
285
+ * When using Multi-Resource Refresh Tokens (MRRT), a single refresh token may cover
286
+ * multiple audiences. In that case, revoking it will affect all cache entries that
287
+ * share the same token.
288
+ *
289
+ * @param options - Optional parameters to identify which refresh token to revoke.
290
+ * Defaults to the audience configured in `authorizationParams`.
291
+ *
292
+ * @example
293
+ * // Revoke the default refresh token
294
+ * await auth0.revokeRefreshToken();
295
+ *
296
+ * @example
297
+ * // Revoke refresh tokens for each audience individually
298
+ * await auth0.revokeRefreshToken({ audience: 'https://api.example.com' });
299
+ * await auth0.revokeRefreshToken({ audience: 'https://api2.example.com' });
300
+ */
301
+ revokeRefreshToken(options?: RevokeRefreshTokenOptions): Promise<void>;
302
+ /**
303
+ * ```js
304
+ * await auth0.logout(options);
305
+ * ```
306
+ *
307
+ * Clears the application session and performs a redirect to `/v2/logout`, using
308
+ * the parameters provided as arguments, to clear the Auth0 session.
309
+ *
310
+ * If the `federated` option is specified it also clears the Identity Provider session.
311
+ * [Read more about how Logout works at Auth0](https://auth0.com/docs/logout).
312
+ *
313
+ * @param options
314
+ */
315
+ logout(options?: LogoutOptions): Promise<void>;
316
+ private _getTokenFromIFrame;
317
+ private _getTokenUsingRefreshToken;
318
+ private _saveEntryInCache;
319
+ private _getIdTokenFromCache;
320
+ private _getEntryFromCache;
321
+ private _requestToken;
322
+ /**
323
+ * ```js
324
+ * await auth0.loginWithCustomTokenExchange(options);
325
+ * ```
326
+ *
327
+ * Exchanges an external subject token for Auth0 tokens and logs the user in.
328
+ * This method implements the Custom Token Exchange grant as specified in RFC 8693.
329
+ *
330
+ * The exchanged tokens are automatically cached, establishing an authenticated session.
331
+ * After calling this method, you can use `getUser()`, `getIdTokenClaims()`, and
332
+ * `getTokenSilently()` to access the user's information and tokens.
333
+ *
334
+ * @param {CustomTokenExchangeOptions} options - The options required to perform the token exchange.
335
+ *
336
+ * @returns {Promise<TokenEndpointResponse>} A promise that resolves to the token endpoint response,
337
+ * which contains the issued Auth0 tokens (access_token, id_token, etc.).
338
+ *
339
+ * The request includes the following parameters:
340
+ * - `grant_type`: "urn:ietf:params:oauth:grant-type:token-exchange"
341
+ * - `subject_token`: The external token to exchange
342
+ * - `subject_token_type`: The type identifier of the external token
343
+ * - `scope`: Merged scopes from the request and SDK defaults
344
+ * - `audience`: Target audience (defaults to SDK configuration)
345
+ * - `organization`: Optional organization ID/name for org-scoped authentication
346
+ *
347
+ * **Example Usage:**
348
+ *
349
+ * ```js
350
+ * const options = {
351
+ * subject_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...',
352
+ * subject_token_type: 'urn:acme:legacy-system-token',
353
+ * scope: 'openid profile email',
354
+ * audience: 'https://api.example.com',
355
+ * organization: 'org_12345'
356
+ * };
357
+ *
358
+ * try {
359
+ * const tokenResponse = await auth0.loginWithCustomTokenExchange(options);
360
+ * console.log('Access token:', tokenResponse.access_token);
361
+ *
362
+ * // User is now logged in - access user info
363
+ * const user = await auth0.getUser();
364
+ * console.log('Logged in user:', user);
365
+ * } catch (error) {
366
+ * console.error('Token exchange failed:', error);
367
+ * }
368
+ * ```
369
+ */
370
+ loginWithCustomTokenExchange(options: CustomTokenExchangeOptions): Promise<TokenEndpointResponse>;
371
+ /**
372
+ * @deprecated Use `loginWithCustomTokenExchange()` instead. This method will be removed in the next major version.
373
+ *
374
+ * Exchanges an external subject token for Auth0 tokens.
375
+ *
376
+ * @param {CustomTokenExchangeOptions} options - The options required to perform the token exchange.
377
+ * @returns {Promise<TokenEndpointResponse>} A promise that resolves to the token endpoint response.
378
+ *
379
+ * **Example:**
380
+ * ```js
381
+ * // Instead of:
382
+ * const tokens = await auth0.exchangeToken(options);
383
+ *
384
+ * // Use:
385
+ * const tokens = await auth0.loginWithCustomTokenExchange(options);
386
+ * ```
387
+ */
388
+ exchangeToken(options: CustomTokenExchangeOptions): Promise<TokenEndpointResponse>;
389
+ protected _assertDpop(dpop: Dpop | undefined): asserts dpop is Dpop;
390
+ /**
391
+ * Returns the current DPoP nonce used for making requests to Auth0.
392
+ *
393
+ * It can return `undefined` because when starting fresh it will not
394
+ * be populated until after the first response from the server.
395
+ *
396
+ * It requires enabling the {@link Auth0ClientOptions.useDpop} option.
397
+ *
398
+ * @param nonce The nonce value.
399
+ * @param id The identifier of a nonce: if absent, it will get the nonce
400
+ * used for requests to Auth0. Otherwise, it will be used to
401
+ * select a specific non-Auth0 nonce.
402
+ */
403
+ getDpopNonce(id?: string): Promise<string | undefined>;
404
+ /**
405
+ * Sets the current DPoP nonce used for making requests to Auth0.
406
+ *
407
+ * It requires enabling the {@link Auth0ClientOptions.useDpop} option.
408
+ *
409
+ * @param nonce The nonce value.
410
+ * @param id The identifier of a nonce: if absent, it will set the nonce
411
+ * used for requests to Auth0. Otherwise, it will be used to
412
+ * select a specific non-Auth0 nonce.
413
+ */
414
+ setDpopNonce(nonce: string, id?: string): Promise<void>;
415
+ /**
416
+ * Returns a string to be used to demonstrate possession of the private
417
+ * key used to cryptographically bind access tokens with DPoP.
418
+ *
419
+ * It requires enabling the {@link Auth0ClientOptions.useDpop} option.
420
+ */
421
+ generateDpopProof(params: {
422
+ url: string;
423
+ method: string;
424
+ nonce?: string;
425
+ accessToken: string;
426
+ }): Promise<string>;
427
+ /**
428
+ * Returns a new `Fetcher` class that will contain a `fetchWithAuth()` method.
429
+ * This is a drop-in replacement for the Fetch API's `fetch()` method, but will
430
+ * handle certain authentication logic for you, like building the proper auth
431
+ * headers or managing DPoP nonces and retries automatically.
432
+ *
433
+ * Check the `EXAMPLES.md` file for a deeper look into this method.
434
+ */
435
+ createFetcher<TOutput extends CustomFetchMinimalOutput = Response>(config?: FetcherConfig<TOutput>): Fetcher<TOutput>;
436
+ /**
437
+ * Initiates a redirect to connect the user's account with a specified connection.
438
+ * This method generates PKCE parameters, creates a transaction, and redirects to the /connect endpoint.
439
+ *
440
+ * You must enable `Offline Access` from the Connection Permissions settings to be able to use the connection with Connected Accounts.
441
+ *
442
+ * @template TAppState - The application state to persist through the transaction.
443
+ * @param {RedirectConnectAccountOptions<TAppState>} options - Options for the connect account redirect flow.
444
+ * @param {string} options.connection - The name of the connection to link (e.g. 'google-oauth2').
445
+ * @param {string[]} [options.scopes] - Array of scopes to request from the Identity Provider during the connect account flow.
446
+ * @param {AuthorizationParams} [options.authorization_params] - Additional authorization parameters for the request to the upstream IdP.
447
+ * @param {string} [options.redirectUri] - The URI to redirect back to after connecting the account.
448
+ * @param {TAppState} [options.appState] - Application state to persist through the transaction.
449
+ * @param {(url: string) => Promise<void>} [options.openUrl] - Custom function to open the URL.
450
+ *
451
+ * @returns {Promise<void>} Resolves when the redirect is initiated.
452
+ * @throws {MyAccountApiError} If the connect request to the My Account API fails.
453
+ */
454
+ connectAccountWithRedirect<TAppState = any>(options: RedirectConnectAccountOptions<TAppState>): Promise<void>;
455
+ /**
456
+ * @internal
457
+ * Internal method used by MfaApiClient to exchange MFA tokens for access tokens.
458
+ * This method should not be called directly by applications.
459
+ */
460
+ _requestTokenForMfa(options: {
461
+ grant_type: string;
462
+ mfaToken: string;
463
+ scope?: string;
464
+ audience?: string;
465
+ otp?: string;
466
+ binding_code?: string;
467
+ oob_code?: string;
468
+ recovery_code?: string;
469
+ }, additionalParameters?: RequestTokenAdditionalParameters): Promise<TokenEndpointResponse>;
470
+ }
471
+ interface RequestTokenAdditionalParameters {
472
+ nonceIn?: string;
473
+ organization?: string;
474
+ scopesToRequest?: string;
475
+ }
476
+ export {};