@auth0/auth0-spa-js 2.17.1 → 2.18.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.
- package/README.md +1 -1
- package/dist/auth0-spa-js.development.js +430 -314
- package/dist/auth0-spa-js.development.js.map +1 -1
- package/dist/auth0-spa-js.production.esm.js +1 -1
- package/dist/auth0-spa-js.production.esm.js.map +1 -1
- package/dist/auth0-spa-js.production.js +1 -1
- package/dist/auth0-spa-js.production.js.map +1 -1
- package/dist/auth0-spa-js.worker.development.js +71 -21
- package/dist/auth0-spa-js.worker.development.js.map +1 -1
- package/dist/auth0-spa-js.worker.production.js +1 -1
- package/dist/auth0-spa-js.worker.production.js.map +1 -1
- package/dist/lib/auth0-spa-js.cjs.js +453 -334
- package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
- package/package.json +4 -3
- package/src/Auth0Client.ts +67 -9
- package/src/global.ts +44 -0
- package/src/index.ts +6 -3
- package/src/utils.ts +11 -5
- package/src/version.ts +1 -1
- package/dist/typings/Auth0Client.d.ts +0 -415
- package/dist/typings/Auth0Client.utils.d.ts +0 -90
- package/dist/typings/MyAccountApiClient.d.ts +0 -92
- package/dist/typings/TokenExchange.d.ts +0 -77
- package/dist/typings/api.d.ts +0 -2
- package/dist/typings/cache/cache-localstorage.d.ts +0 -7
- package/dist/typings/cache/cache-manager.d.ts +0 -56
- package/dist/typings/cache/cache-memory.d.ts +0 -4
- package/dist/typings/cache/index.d.ts +0 -4
- package/dist/typings/cache/key-manifest.d.ts +0 -12
- package/dist/typings/cache/shared.d.ts +0 -68
- package/dist/typings/constants.d.ts +0 -58
- package/dist/typings/dpop/dpop.d.ts +0 -17
- package/dist/typings/dpop/storage.d.ts +0 -27
- package/dist/typings/dpop/utils.d.ts +0 -15
- package/dist/typings/errors.d.ts +0 -96
- package/dist/typings/fetcher.d.ts +0 -54
- package/dist/typings/global.d.ts +0 -777
- package/dist/typings/http.d.ts +0 -5
- package/dist/typings/index.d.ts +0 -23
- package/dist/typings/jwt.d.ts +0 -21
- package/dist/typings/lock.d.ts +0 -32
- package/dist/typings/mfa/MfaApiClient.d.ts +0 -225
- package/dist/typings/mfa/MfaContextManager.d.ts +0 -79
- package/dist/typings/mfa/constants.d.ts +0 -23
- package/dist/typings/mfa/errors.d.ts +0 -117
- package/dist/typings/mfa/index.d.ts +0 -4
- package/dist/typings/mfa/types.d.ts +0 -181
- package/dist/typings/mfa/utils.d.ts +0 -23
- package/dist/typings/promise-utils.d.ts +0 -2
- package/dist/typings/scope.d.ts +0 -35
- package/dist/typings/storage.d.ts +0 -26
- package/dist/typings/transaction-manager.d.ts +0 -33
- package/dist/typings/utils.d.ts +0 -36
- package/dist/typings/version.d.ts +0 -2
- package/dist/typings/worker/token.worker.d.ts +0 -1
- package/dist/typings/worker/worker.types.d.ts +0 -15
- package/dist/typings/worker/worker.utils.d.ts +0 -7
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@auth0/auth0-spa-js",
|
|
4
4
|
"description": "Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.18.1",
|
|
7
7
|
"main": "dist/lib/auth0-spa-js.cjs.js",
|
|
8
8
|
"types": "dist/typings/index.d.ts",
|
|
9
9
|
"module": "dist/auth0-spa-js.production.esm.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@auth0/auth0-auth-js": "1.
|
|
26
|
+
"@auth0/auth0-auth-js": "1.6.0",
|
|
27
27
|
"browser-tabs-lock": "1.3.0",
|
|
28
28
|
"dpop": "2.1.1",
|
|
29
29
|
"es-cookie": "1.3.2"
|
|
@@ -54,9 +54,10 @@
|
|
|
54
54
|
"publish:cdn": "ccu --trace"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@auth0/component-cdn-uploader": "^
|
|
57
|
+
"@auth0/component-cdn-uploader": "^3.0.0",
|
|
58
58
|
"@babel/core": "^7.28.5",
|
|
59
59
|
"@babel/preset-env": "^7.28.5",
|
|
60
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
60
61
|
"@rollup/plugin-babel": "^6.1.0",
|
|
61
62
|
"@rollup/plugin-commonjs": "^21.1.0",
|
|
62
63
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
package/src/Auth0Client.ts
CHANGED
|
@@ -378,6 +378,57 @@ export class Auth0Client {
|
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
+
/**
|
|
382
|
+
* Extracts the session transfer token from the current URL query parameters
|
|
383
|
+
* for Native to Web SSO flows.
|
|
384
|
+
*
|
|
385
|
+
* @param paramName The query parameter name to extract from the URL
|
|
386
|
+
* @returns The session transfer token if present, undefined otherwise
|
|
387
|
+
*/
|
|
388
|
+
private _extractSessionTransferToken(paramName: string): string | undefined {
|
|
389
|
+
const params = new URLSearchParams(window.location.search);
|
|
390
|
+
return params.get(paramName) || undefined;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Clears the session transfer token from the current URL using the History API.
|
|
395
|
+
* This prevents the token from being re-sent on subsequent authentication requests,
|
|
396
|
+
* which is important since session transfer tokens are typically single-use.
|
|
397
|
+
*
|
|
398
|
+
* @param paramName The query parameter name to remove from the URL
|
|
399
|
+
*/
|
|
400
|
+
private _clearSessionTransferTokenFromUrl(paramName: string): void {
|
|
401
|
+
try {
|
|
402
|
+
const url = new URL(window.location.href);
|
|
403
|
+
if (url.searchParams.has(paramName)) {
|
|
404
|
+
url.searchParams.delete(paramName);
|
|
405
|
+
window.history.replaceState({}, '', url.toString());
|
|
406
|
+
}
|
|
407
|
+
} catch {
|
|
408
|
+
// Silently fail if URL manipulation isn't possible
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Applies the session transfer token from the URL to the authorization parameters
|
|
414
|
+
* if configured and not already provided.
|
|
415
|
+
*
|
|
416
|
+
* @param authorizationParams The authorization parameters to enhance
|
|
417
|
+
* @returns The authorization parameters with session_transfer_token added if applicable
|
|
418
|
+
*/
|
|
419
|
+
private _applySessionTransferToken(
|
|
420
|
+
authorizationParams: AuthorizationParams
|
|
421
|
+
): AuthorizationParams {
|
|
422
|
+
const paramName = this.options.sessionTransferTokenQueryParamName;
|
|
423
|
+
if (!paramName || authorizationParams.session_transfer_token) {
|
|
424
|
+
return authorizationParams;
|
|
425
|
+
}
|
|
426
|
+
const token = this._extractSessionTransferToken(paramName);
|
|
427
|
+
if (!token) return authorizationParams;
|
|
428
|
+
this._clearSessionTransferTokenFromUrl(paramName);
|
|
429
|
+
return { ...authorizationParams, session_transfer_token: token };
|
|
430
|
+
}
|
|
431
|
+
|
|
381
432
|
private async _prepareAuthorizeUrl(
|
|
382
433
|
authorizationParams: AuthorizationParams,
|
|
383
434
|
authorizeOptions?: Partial<AuthorizeOptions>,
|
|
@@ -463,21 +514,26 @@ export class Auth0Client {
|
|
|
463
514
|
}
|
|
464
515
|
}
|
|
465
516
|
|
|
517
|
+
const authorizationParams = this._applySessionTransferToken(options.authorizationParams || {});
|
|
518
|
+
|
|
466
519
|
const params = await this._prepareAuthorizeUrl(
|
|
467
|
-
|
|
520
|
+
authorizationParams,
|
|
468
521
|
{ response_mode: 'web_message' },
|
|
469
522
|
window.location.origin
|
|
470
523
|
);
|
|
471
524
|
|
|
472
525
|
config.popup.location.href = params.url;
|
|
473
526
|
|
|
474
|
-
const codeResult = await runPopup(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
527
|
+
const codeResult = await runPopup(
|
|
528
|
+
{
|
|
529
|
+
...config,
|
|
530
|
+
timeoutInSeconds:
|
|
531
|
+
config.timeoutInSeconds ||
|
|
532
|
+
this.options.authorizeTimeoutInSeconds ||
|
|
533
|
+
DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS
|
|
534
|
+
},
|
|
535
|
+
new URL(params.url).origin
|
|
536
|
+
);
|
|
481
537
|
|
|
482
538
|
if (params.state !== codeResult.state) {
|
|
483
539
|
throw new GenericError('state_mismatch', 'Invalid state');
|
|
@@ -553,8 +609,10 @@ export class Auth0Client {
|
|
|
553
609
|
urlOptions.authorizationParams?.organization ||
|
|
554
610
|
this.options.authorizationParams.organization;
|
|
555
611
|
|
|
612
|
+
const authorizationParams = this._applySessionTransferToken(urlOptions.authorizationParams || {});
|
|
613
|
+
|
|
556
614
|
const { url, ...transaction } = await this._prepareAuthorizeUrl(
|
|
557
|
-
|
|
615
|
+
authorizationParams
|
|
558
616
|
);
|
|
559
617
|
|
|
560
618
|
this.transactionManager.create<LoginTransaction>({
|
package/src/global.ts
CHANGED
|
@@ -113,6 +113,15 @@ export interface AuthorizationParams {
|
|
|
113
113
|
*/
|
|
114
114
|
redirect_uri?: string;
|
|
115
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Session transfer token from a native application for Native to Web SSO.
|
|
118
|
+
* When `sessionTransferTokenQueryParamName` is set, this is automatically
|
|
119
|
+
* extracted from the specified URL query parameter if present.
|
|
120
|
+
*
|
|
121
|
+
* @see https://auth0.com/docs/authenticate/single-sign-on/native-to-web
|
|
122
|
+
*/
|
|
123
|
+
session_transfer_token?: string;
|
|
124
|
+
|
|
116
125
|
/**
|
|
117
126
|
* If you need to send custom parameters to the Authorization Server,
|
|
118
127
|
* make sure to use the original parameter name.
|
|
@@ -324,6 +333,41 @@ export interface Auth0ClientOptions {
|
|
|
324
333
|
* defined by Auth0 or custom parameters that you define.
|
|
325
334
|
*/
|
|
326
335
|
authorizationParams?: ClientAuthorizationParams;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Query parameter name to extract the session transfer token from for Native to Web SSO.
|
|
339
|
+
*
|
|
340
|
+
* When set, the SDK automatically extracts the token from the specified URL query
|
|
341
|
+
* parameter and includes it as `session_transfer_token` in authorization requests.
|
|
342
|
+
* This enables seamless single sign-on when users transition from a native mobile
|
|
343
|
+
* application to a web application.
|
|
344
|
+
*
|
|
345
|
+
* After extraction, the token is automatically removed from the URL using
|
|
346
|
+
* `window.history.replaceState()` to prevent accidental reuse on subsequent
|
|
347
|
+
* authentication requests.
|
|
348
|
+
*
|
|
349
|
+
* **Default:** `undefined` (feature disabled)
|
|
350
|
+
*
|
|
351
|
+
* **Common values:**
|
|
352
|
+
* - `'session_transfer_token'` - Standard parameter name
|
|
353
|
+
* - `'stt'` - Shortened version
|
|
354
|
+
* - Custom parameter name of your choice
|
|
355
|
+
*
|
|
356
|
+
* Set to `undefined` to disable automatic extraction if you prefer to handle
|
|
357
|
+
* session transfer tokens manually.
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* ```js
|
|
361
|
+
* const auth0 = await createAuth0Client({
|
|
362
|
+
* domain: '<AUTH0_DOMAIN>',
|
|
363
|
+
* clientId: '<AUTH0_CLIENT_ID>',
|
|
364
|
+
* sessionTransferTokenQueryParamName: 'session_transfer_token'
|
|
365
|
+
* });
|
|
366
|
+
* ```
|
|
367
|
+
*
|
|
368
|
+
* @see https://auth0.com/docs/authenticate/single-sign-on/native-to-web
|
|
369
|
+
*/
|
|
370
|
+
sessionTransferTokenQueryParamName?: string;
|
|
327
371
|
}
|
|
328
372
|
|
|
329
373
|
/**
|
package/src/index.ts
CHANGED
|
@@ -58,16 +58,19 @@ export type {
|
|
|
58
58
|
} from './mfa';
|
|
59
59
|
|
|
60
60
|
export {
|
|
61
|
-
ICache,
|
|
62
61
|
LocalStorageCache,
|
|
63
62
|
InMemoryCache,
|
|
63
|
+
CacheKey
|
|
64
|
+
} from './cache';
|
|
65
|
+
|
|
66
|
+
export type {
|
|
67
|
+
ICache,
|
|
64
68
|
Cacheable,
|
|
65
69
|
DecodedToken,
|
|
66
70
|
CacheEntry,
|
|
67
71
|
WrappedCacheEntry,
|
|
68
72
|
KeyManifestEntry,
|
|
69
73
|
MaybePromise,
|
|
70
|
-
CacheKey,
|
|
71
74
|
CacheKeyData
|
|
72
75
|
} from './cache';
|
|
73
76
|
|
|
@@ -79,4 +82,4 @@ export type {
|
|
|
79
82
|
|
|
80
83
|
export { MyAccountApiError } from './MyAccountApiClient';
|
|
81
84
|
|
|
82
|
-
export { CustomTokenExchangeOptions } from './TokenExchange';
|
|
85
|
+
export type { CustomTokenExchangeOptions } from './TokenExchange';
|
package/src/utils.ts
CHANGED
|
@@ -97,7 +97,7 @@ export const openPopup = (url: string) => {
|
|
|
97
97
|
);
|
|
98
98
|
};
|
|
99
99
|
|
|
100
|
-
export const runPopup = (config: PopupConfigOptions) => {
|
|
100
|
+
export const runPopup = (config: PopupConfigOptions, eventOrigin: string) => {
|
|
101
101
|
return new Promise<AuthenticationResult>((resolve, reject) => {
|
|
102
102
|
let popupEventListener: (e: MessageEvent) => void;
|
|
103
103
|
|
|
@@ -118,6 +118,7 @@ export const runPopup = (config: PopupConfigOptions) => {
|
|
|
118
118
|
}, (config.timeoutInSeconds || DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS) * 1000);
|
|
119
119
|
|
|
120
120
|
popupEventListener = function (e: MessageEvent) {
|
|
121
|
+
if (e.origin !== eventOrigin) return;
|
|
121
122
|
if (!e.data || e.data.type !== 'authorization_response') {
|
|
122
123
|
return;
|
|
123
124
|
}
|
|
@@ -149,11 +150,16 @@ export const getCrypto = () => {
|
|
|
149
150
|
export const createRandomString = () => {
|
|
150
151
|
const charset =
|
|
151
152
|
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.';
|
|
153
|
+
const validMax = 256 - (256 % charset.length);
|
|
152
154
|
let random = '';
|
|
153
|
-
|
|
154
|
-
getCrypto().getRandomValues(new Uint8Array(43))
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
while (random.length < 43) {
|
|
156
|
+
const bytes = getCrypto().getRandomValues(new Uint8Array(43 - random.length));
|
|
157
|
+
for (const byte of bytes) {
|
|
158
|
+
if (random.length < 43 && byte < validMax) {
|
|
159
|
+
random += charset[byte % charset.length];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
157
163
|
return random;
|
|
158
164
|
};
|
|
159
165
|
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '2.
|
|
1
|
+
export default '2.18.1';
|
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import { Auth0ClientOptions, RedirectLoginOptions, PopupLoginOptions, PopupConfigOptions, RedirectLoginResult, GetTokenSilentlyOptions, GetTokenWithPopupOptions, LogoutOptions, User, IdToken, GetTokenSilentlyVerboseResponse, TokenEndpointResponse, ConnectAccountRedirectResult, RedirectConnectAccountOptions, ClientConfiguration } 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
|
-
private _prepareAuthorizeUrl;
|
|
62
|
-
/**
|
|
63
|
-
* ```js
|
|
64
|
-
* try {
|
|
65
|
-
* await auth0.loginWithPopup(options);
|
|
66
|
-
* } catch(e) {
|
|
67
|
-
* if (e instanceof PopupCancelledError) {
|
|
68
|
-
* // Popup was closed before login completed
|
|
69
|
-
* }
|
|
70
|
-
* }
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* Opens a popup with the `/authorize` URL using the parameters
|
|
74
|
-
* provided as arguments. Random and secure `state` and `nonce`
|
|
75
|
-
* parameters will be auto-generated. If the response is successful,
|
|
76
|
-
* results will be valid according to their expiration times.
|
|
77
|
-
*
|
|
78
|
-
* IMPORTANT: This method has to be called from an event handler
|
|
79
|
-
* that was started by the user like a button click, for example,
|
|
80
|
-
* otherwise the popup will be blocked in most browsers.
|
|
81
|
-
*
|
|
82
|
-
* @param options
|
|
83
|
-
* @param config
|
|
84
|
-
*/
|
|
85
|
-
loginWithPopup(options?: PopupLoginOptions, config?: PopupConfigOptions): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
* ```js
|
|
88
|
-
* const user = await auth0.getUser();
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
|
-
* Returns the user information if available (decoded
|
|
92
|
-
* from the `id_token`).
|
|
93
|
-
*
|
|
94
|
-
* @typeparam TUser The type to return, has to extend {@link User}.
|
|
95
|
-
*/
|
|
96
|
-
getUser<TUser extends User>(): Promise<TUser | undefined>;
|
|
97
|
-
/**
|
|
98
|
-
* ```js
|
|
99
|
-
* const claims = await auth0.getIdTokenClaims();
|
|
100
|
-
* ```
|
|
101
|
-
*
|
|
102
|
-
* Returns all claims from the id_token if available.
|
|
103
|
-
*/
|
|
104
|
-
getIdTokenClaims(): Promise<IdToken | undefined>;
|
|
105
|
-
/**
|
|
106
|
-
* ```js
|
|
107
|
-
* await auth0.loginWithRedirect(options);
|
|
108
|
-
* ```
|
|
109
|
-
*
|
|
110
|
-
* Performs a redirect to `/authorize` using the parameters
|
|
111
|
-
* provided as arguments. Random and secure `state` and `nonce`
|
|
112
|
-
* parameters will be auto-generated.
|
|
113
|
-
*
|
|
114
|
-
* @param options
|
|
115
|
-
*/
|
|
116
|
-
loginWithRedirect<TAppState = any>(options?: RedirectLoginOptions<TAppState>): Promise<void>;
|
|
117
|
-
/**
|
|
118
|
-
* After the browser redirects back to the callback page,
|
|
119
|
-
* call `handleRedirectCallback` to handle success and error
|
|
120
|
-
* responses from Auth0. If the response is successful, results
|
|
121
|
-
* will be valid according to their expiration times.
|
|
122
|
-
*/
|
|
123
|
-
handleRedirectCallback<TAppState = any>(url?: string): Promise<RedirectLoginResult<TAppState> | ConnectAccountRedirectResult<TAppState>>;
|
|
124
|
-
/**
|
|
125
|
-
* Handles the redirect callback from the login flow.
|
|
126
|
-
*
|
|
127
|
-
* @template AppState - The application state persisted from the /authorize redirect.
|
|
128
|
-
* @param {string} authenticationResult - The parsed authentication result from the URL.
|
|
129
|
-
* @param {string} transaction - The login transaction.
|
|
130
|
-
*
|
|
131
|
-
* @returns {RedirectLoginResult} Resolves with the persisted app state.
|
|
132
|
-
* @throws {GenericError | Error} If the transaction is missing, invalid, or the code exchange fails.
|
|
133
|
-
*/
|
|
134
|
-
private _handleLoginRedirectCallback;
|
|
135
|
-
/**
|
|
136
|
-
* Handles the redirect callback from the connect account flow.
|
|
137
|
-
* This works the same as the redirect from the login flow expect it verifies the `connect_code`
|
|
138
|
-
* with the My Account API rather than the `code` with the Authorization Server.
|
|
139
|
-
*
|
|
140
|
-
* @template AppState - The application state persisted from the connect redirect.
|
|
141
|
-
* @param {string} connectResult - The parsed connect accounts result from the URL.
|
|
142
|
-
* @param {string} transaction - The login transaction.
|
|
143
|
-
* @returns {Promise<ConnectAccountRedirectResult>} The result of the My Account API, including any persisted app state.
|
|
144
|
-
* @throws {GenericError | MyAccountApiError} If the transaction is missing, invalid, or an error is returned from the My Account API.
|
|
145
|
-
*/
|
|
146
|
-
private _handleConnectAccountRedirectCallback;
|
|
147
|
-
/**
|
|
148
|
-
* ```js
|
|
149
|
-
* await auth0.checkSession();
|
|
150
|
-
* ```
|
|
151
|
-
*
|
|
152
|
-
* Check if the user is logged in using `getTokenSilently`. The difference
|
|
153
|
-
* with `getTokenSilently` is that this doesn't return a token, but it will
|
|
154
|
-
* pre-fill the token cache.
|
|
155
|
-
*
|
|
156
|
-
* This method also heeds the `auth0.{clientId}.is.authenticated` cookie, as an optimization
|
|
157
|
-
* to prevent calling Auth0 unnecessarily. If the cookie is not present because
|
|
158
|
-
* there was no previous login (or it has expired) then tokens will not be refreshed.
|
|
159
|
-
*
|
|
160
|
-
* It should be used for silently logging in the user when you instantiate the
|
|
161
|
-
* `Auth0Client` constructor. You should not need this if you are using the
|
|
162
|
-
* `createAuth0Client` factory.
|
|
163
|
-
*
|
|
164
|
-
* **Note:** the cookie **may not** be present if running an app using a private tab, as some
|
|
165
|
-
* browsers clear JS cookie data and local storage when the tab or page is closed, or on page reload. This effectively
|
|
166
|
-
* means that `checkSession` could silently return without authenticating the user on page refresh when
|
|
167
|
-
* using a private tab, despite having previously logged in. As a workaround, use `getTokenSilently` instead
|
|
168
|
-
* and handle the possible `login_required` error [as shown in the readme](https://github.com/auth0/auth0-spa-js#creating-the-client).
|
|
169
|
-
*
|
|
170
|
-
* @param options
|
|
171
|
-
*/
|
|
172
|
-
checkSession(options?: GetTokenSilentlyOptions): Promise<void>;
|
|
173
|
-
/**
|
|
174
|
-
* Fetches a new access token and returns the response from the /oauth/token endpoint, omitting the refresh token.
|
|
175
|
-
*
|
|
176
|
-
* @param options
|
|
177
|
-
*/
|
|
178
|
-
getTokenSilently(options: GetTokenSilentlyOptions & {
|
|
179
|
-
detailedResponse: true;
|
|
180
|
-
}): Promise<GetTokenSilentlyVerboseResponse>;
|
|
181
|
-
/**
|
|
182
|
-
* Fetches a new access token and returns it.
|
|
183
|
-
*
|
|
184
|
-
* @param options
|
|
185
|
-
*/
|
|
186
|
-
getTokenSilently(options?: GetTokenSilentlyOptions): Promise<string>;
|
|
187
|
-
private _getTokenSilently;
|
|
188
|
-
/**
|
|
189
|
-
* Checks if an error should be handled by the interactive error handler.
|
|
190
|
-
* Matches:
|
|
191
|
-
* - MfaRequiredError (refresh token path, error='mfa_required')
|
|
192
|
-
* - GenericError from iframe path (error='login_required',
|
|
193
|
-
* error_description='Multifactor authentication required')
|
|
194
|
-
* Extensible for future interactive error types.
|
|
195
|
-
*/
|
|
196
|
-
private _isInteractiveError;
|
|
197
|
-
/**
|
|
198
|
-
* Checks if a login_required error from the iframe flow is actually
|
|
199
|
-
* an MFA step-up requirement. The /authorize endpoint returns
|
|
200
|
-
* error='login_required' with error_description='Multifactor authentication required'
|
|
201
|
-
* when MFA is needed but prompt=none prevents interaction.
|
|
202
|
-
*/
|
|
203
|
-
private _isIframeMfaError;
|
|
204
|
-
/**
|
|
205
|
-
* Handles MFA errors by opening a popup to complete authentication,
|
|
206
|
-
* then reads the resulting token from cache.
|
|
207
|
-
*/
|
|
208
|
-
private _handleInteractiveErrorWithPopup;
|
|
209
|
-
/**
|
|
210
|
-
* ```js
|
|
211
|
-
* const token = await auth0.getTokenWithPopup(options);
|
|
212
|
-
* ```
|
|
213
|
-
* Opens a popup with the `/authorize` URL using the parameters
|
|
214
|
-
* provided as arguments. Random and secure `state` and `nonce`
|
|
215
|
-
* parameters will be auto-generated. If the response is successful,
|
|
216
|
-
* results will be valid according to their expiration times.
|
|
217
|
-
*
|
|
218
|
-
* @param options
|
|
219
|
-
* @param config
|
|
220
|
-
*/
|
|
221
|
-
getTokenWithPopup(options?: GetTokenWithPopupOptions, config?: PopupConfigOptions): Promise<string | undefined>;
|
|
222
|
-
/**
|
|
223
|
-
* ```js
|
|
224
|
-
* const isAuthenticated = await auth0.isAuthenticated();
|
|
225
|
-
* ```
|
|
226
|
-
*
|
|
227
|
-
* Returns `true` if there's valid information stored,
|
|
228
|
-
* otherwise returns `false`.
|
|
229
|
-
*
|
|
230
|
-
*/
|
|
231
|
-
isAuthenticated(): Promise<boolean>;
|
|
232
|
-
/**
|
|
233
|
-
* ```js
|
|
234
|
-
* await auth0.buildLogoutUrl(options);
|
|
235
|
-
* ```
|
|
236
|
-
*
|
|
237
|
-
* Builds a URL to the logout endpoint using the parameters provided as arguments.
|
|
238
|
-
* @param options
|
|
239
|
-
*/
|
|
240
|
-
private _buildLogoutUrl;
|
|
241
|
-
/**
|
|
242
|
-
* ```js
|
|
243
|
-
* await auth0.logout(options);
|
|
244
|
-
* ```
|
|
245
|
-
*
|
|
246
|
-
* Clears the application session and performs a redirect to `/v2/logout`, using
|
|
247
|
-
* the parameters provided as arguments, to clear the Auth0 session.
|
|
248
|
-
*
|
|
249
|
-
* If the `federated` option is specified it also clears the Identity Provider session.
|
|
250
|
-
* [Read more about how Logout works at Auth0](https://auth0.com/docs/logout).
|
|
251
|
-
*
|
|
252
|
-
* @param options
|
|
253
|
-
*/
|
|
254
|
-
logout(options?: LogoutOptions): Promise<void>;
|
|
255
|
-
private _getTokenFromIFrame;
|
|
256
|
-
private _getTokenUsingRefreshToken;
|
|
257
|
-
private _saveEntryInCache;
|
|
258
|
-
private _getIdTokenFromCache;
|
|
259
|
-
private _getEntryFromCache;
|
|
260
|
-
private _requestToken;
|
|
261
|
-
/**
|
|
262
|
-
* ```js
|
|
263
|
-
* await auth0.loginWithCustomTokenExchange(options);
|
|
264
|
-
* ```
|
|
265
|
-
*
|
|
266
|
-
* Exchanges an external subject token for Auth0 tokens and logs the user in.
|
|
267
|
-
* This method implements the Custom Token Exchange grant as specified in RFC 8693.
|
|
268
|
-
*
|
|
269
|
-
* The exchanged tokens are automatically cached, establishing an authenticated session.
|
|
270
|
-
* After calling this method, you can use `getUser()`, `getIdTokenClaims()`, and
|
|
271
|
-
* `getTokenSilently()` to access the user's information and tokens.
|
|
272
|
-
*
|
|
273
|
-
* @param {CustomTokenExchangeOptions} options - The options required to perform the token exchange.
|
|
274
|
-
*
|
|
275
|
-
* @returns {Promise<TokenEndpointResponse>} A promise that resolves to the token endpoint response,
|
|
276
|
-
* which contains the issued Auth0 tokens (access_token, id_token, etc.).
|
|
277
|
-
*
|
|
278
|
-
* The request includes the following parameters:
|
|
279
|
-
* - `grant_type`: "urn:ietf:params:oauth:grant-type:token-exchange"
|
|
280
|
-
* - `subject_token`: The external token to exchange
|
|
281
|
-
* - `subject_token_type`: The type identifier of the external token
|
|
282
|
-
* - `scope`: Merged scopes from the request and SDK defaults
|
|
283
|
-
* - `audience`: Target audience (defaults to SDK configuration)
|
|
284
|
-
* - `organization`: Optional organization ID/name for org-scoped authentication
|
|
285
|
-
*
|
|
286
|
-
* **Example Usage:**
|
|
287
|
-
*
|
|
288
|
-
* ```js
|
|
289
|
-
* const options = {
|
|
290
|
-
* subject_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...',
|
|
291
|
-
* subject_token_type: 'urn:acme:legacy-system-token',
|
|
292
|
-
* scope: 'openid profile email',
|
|
293
|
-
* audience: 'https://api.example.com',
|
|
294
|
-
* organization: 'org_12345'
|
|
295
|
-
* };
|
|
296
|
-
*
|
|
297
|
-
* try {
|
|
298
|
-
* const tokenResponse = await auth0.loginWithCustomTokenExchange(options);
|
|
299
|
-
* console.log('Access token:', tokenResponse.access_token);
|
|
300
|
-
*
|
|
301
|
-
* // User is now logged in - access user info
|
|
302
|
-
* const user = await auth0.getUser();
|
|
303
|
-
* console.log('Logged in user:', user);
|
|
304
|
-
* } catch (error) {
|
|
305
|
-
* console.error('Token exchange failed:', error);
|
|
306
|
-
* }
|
|
307
|
-
* ```
|
|
308
|
-
*/
|
|
309
|
-
loginWithCustomTokenExchange(options: CustomTokenExchangeOptions): Promise<TokenEndpointResponse>;
|
|
310
|
-
/**
|
|
311
|
-
* @deprecated Use `loginWithCustomTokenExchange()` instead. This method will be removed in the next major version.
|
|
312
|
-
*
|
|
313
|
-
* Exchanges an external subject token for Auth0 tokens.
|
|
314
|
-
*
|
|
315
|
-
* @param {CustomTokenExchangeOptions} options - The options required to perform the token exchange.
|
|
316
|
-
* @returns {Promise<TokenEndpointResponse>} A promise that resolves to the token endpoint response.
|
|
317
|
-
*
|
|
318
|
-
* **Example:**
|
|
319
|
-
* ```js
|
|
320
|
-
* // Instead of:
|
|
321
|
-
* const tokens = await auth0.exchangeToken(options);
|
|
322
|
-
*
|
|
323
|
-
* // Use:
|
|
324
|
-
* const tokens = await auth0.loginWithCustomTokenExchange(options);
|
|
325
|
-
* ```
|
|
326
|
-
*/
|
|
327
|
-
exchangeToken(options: CustomTokenExchangeOptions): Promise<TokenEndpointResponse>;
|
|
328
|
-
protected _assertDpop(dpop: Dpop | undefined): asserts dpop is Dpop;
|
|
329
|
-
/**
|
|
330
|
-
* Returns the current DPoP nonce used for making requests to Auth0.
|
|
331
|
-
*
|
|
332
|
-
* It can return `undefined` because when starting fresh it will not
|
|
333
|
-
* be populated until after the first response from the server.
|
|
334
|
-
*
|
|
335
|
-
* It requires enabling the {@link Auth0ClientOptions.useDpop} option.
|
|
336
|
-
*
|
|
337
|
-
* @param nonce The nonce value.
|
|
338
|
-
* @param id The identifier of a nonce: if absent, it will get the nonce
|
|
339
|
-
* used for requests to Auth0. Otherwise, it will be used to
|
|
340
|
-
* select a specific non-Auth0 nonce.
|
|
341
|
-
*/
|
|
342
|
-
getDpopNonce(id?: string): Promise<string | undefined>;
|
|
343
|
-
/**
|
|
344
|
-
* Sets the current DPoP nonce used for making requests to Auth0.
|
|
345
|
-
*
|
|
346
|
-
* It requires enabling the {@link Auth0ClientOptions.useDpop} option.
|
|
347
|
-
*
|
|
348
|
-
* @param nonce The nonce value.
|
|
349
|
-
* @param id The identifier of a nonce: if absent, it will set the nonce
|
|
350
|
-
* used for requests to Auth0. Otherwise, it will be used to
|
|
351
|
-
* select a specific non-Auth0 nonce.
|
|
352
|
-
*/
|
|
353
|
-
setDpopNonce(nonce: string, id?: string): Promise<void>;
|
|
354
|
-
/**
|
|
355
|
-
* Returns a string to be used to demonstrate possession of the private
|
|
356
|
-
* key used to cryptographically bind access tokens with DPoP.
|
|
357
|
-
*
|
|
358
|
-
* It requires enabling the {@link Auth0ClientOptions.useDpop} option.
|
|
359
|
-
*/
|
|
360
|
-
generateDpopProof(params: {
|
|
361
|
-
url: string;
|
|
362
|
-
method: string;
|
|
363
|
-
nonce?: string;
|
|
364
|
-
accessToken: string;
|
|
365
|
-
}): Promise<string>;
|
|
366
|
-
/**
|
|
367
|
-
* Returns a new `Fetcher` class that will contain a `fetchWithAuth()` method.
|
|
368
|
-
* This is a drop-in replacement for the Fetch API's `fetch()` method, but will
|
|
369
|
-
* handle certain authentication logic for you, like building the proper auth
|
|
370
|
-
* headers or managing DPoP nonces and retries automatically.
|
|
371
|
-
*
|
|
372
|
-
* Check the `EXAMPLES.md` file for a deeper look into this method.
|
|
373
|
-
*/
|
|
374
|
-
createFetcher<TOutput extends CustomFetchMinimalOutput = Response>(config?: FetcherConfig<TOutput>): Fetcher<TOutput>;
|
|
375
|
-
/**
|
|
376
|
-
* Initiates a redirect to connect the user's account with a specified connection.
|
|
377
|
-
* This method generates PKCE parameters, creates a transaction, and redirects to the /connect endpoint.
|
|
378
|
-
*
|
|
379
|
-
* You must enable `Offline Access` from the Connection Permissions settings to be able to use the connection with Connected Accounts.
|
|
380
|
-
*
|
|
381
|
-
* @template TAppState - The application state to persist through the transaction.
|
|
382
|
-
* @param {RedirectConnectAccountOptions<TAppState>} options - Options for the connect account redirect flow.
|
|
383
|
-
* @param {string} options.connection - The name of the connection to link (e.g. 'google-oauth2').
|
|
384
|
-
* @param {string[]} [options.scopes] - Array of scopes to request from the Identity Provider during the connect account flow.
|
|
385
|
-
* @param {AuthorizationParams} [options.authorization_params] - Additional authorization parameters for the request to the upstream IdP.
|
|
386
|
-
* @param {string} [options.redirectUri] - The URI to redirect back to after connecting the account.
|
|
387
|
-
* @param {TAppState} [options.appState] - Application state to persist through the transaction.
|
|
388
|
-
* @param {(url: string) => Promise<void>} [options.openUrl] - Custom function to open the URL.
|
|
389
|
-
*
|
|
390
|
-
* @returns {Promise<void>} Resolves when the redirect is initiated.
|
|
391
|
-
* @throws {MyAccountApiError} If the connect request to the My Account API fails.
|
|
392
|
-
*/
|
|
393
|
-
connectAccountWithRedirect<TAppState = any>(options: RedirectConnectAccountOptions<TAppState>): Promise<void>;
|
|
394
|
-
/**
|
|
395
|
-
* @internal
|
|
396
|
-
* Internal method used by MfaApiClient to exchange MFA tokens for access tokens.
|
|
397
|
-
* This method should not be called directly by applications.
|
|
398
|
-
*/
|
|
399
|
-
_requestTokenForMfa(options: {
|
|
400
|
-
grant_type: string;
|
|
401
|
-
mfaToken: string;
|
|
402
|
-
scope?: string;
|
|
403
|
-
audience?: string;
|
|
404
|
-
otp?: string;
|
|
405
|
-
binding_code?: string;
|
|
406
|
-
oob_code?: string;
|
|
407
|
-
recovery_code?: string;
|
|
408
|
-
}, additionalParameters?: RequestTokenAdditionalParameters): Promise<TokenEndpointResponse>;
|
|
409
|
-
}
|
|
410
|
-
interface RequestTokenAdditionalParameters {
|
|
411
|
-
nonceIn?: string;
|
|
412
|
-
organization?: string;
|
|
413
|
-
scopesToRequest?: string;
|
|
414
|
-
}
|
|
415
|
-
export {};
|