@auth0/auth0-spa-js 2.19.0 → 2.19.2
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/dist/auth0-spa-js.development.js +47 -26
- 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 +7 -0
- 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 +47 -26
- package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
- package/dist/typings/Auth0Client.d.ts +476 -476
- package/dist/typings/Auth0Client.utils.d.ts +90 -90
- package/dist/typings/MyAccountApiClient.d.ts +92 -92
- package/dist/typings/TokenExchange.d.ts +77 -77
- package/dist/typings/api.d.ts +33 -33
- package/dist/typings/cache/cache-localstorage.d.ts +7 -7
- package/dist/typings/cache/cache-manager.d.ts +69 -69
- package/dist/typings/cache/cache-memory.d.ts +4 -4
- package/dist/typings/cache/index.d.ts +4 -4
- package/dist/typings/cache/key-manifest.d.ts +12 -12
- package/dist/typings/cache/shared.d.ts +68 -68
- package/dist/typings/constants.d.ts +58 -58
- package/dist/typings/dpop/dpop.d.ts +17 -17
- package/dist/typings/dpop/storage.d.ts +27 -27
- package/dist/typings/dpop/utils.d.ts +15 -15
- package/dist/typings/errors.d.ts +96 -96
- package/dist/typings/fetcher.d.ts +54 -54
- package/dist/typings/global.d.ts +826 -826
- package/dist/typings/http.d.ts +11 -11
- package/dist/typings/index.d.ts +24 -24
- package/dist/typings/jwt.d.ts +21 -21
- package/dist/typings/lock.d.ts +32 -32
- package/dist/typings/mfa/MfaApiClient.d.ts +225 -225
- package/dist/typings/mfa/MfaContextManager.d.ts +79 -79
- package/dist/typings/mfa/constants.d.ts +23 -23
- package/dist/typings/mfa/errors.d.ts +117 -117
- package/dist/typings/mfa/index.d.ts +4 -4
- package/dist/typings/mfa/types.d.ts +181 -181
- package/dist/typings/mfa/utils.d.ts +23 -23
- package/dist/typings/promise-utils.d.ts +2 -2
- package/dist/typings/scope.d.ts +35 -35
- package/dist/typings/storage.d.ts +26 -26
- package/dist/typings/transaction-manager.d.ts +33 -33
- package/dist/typings/utils.d.ts +36 -36
- package/dist/typings/version.d.ts +2 -2
- package/dist/typings/worker/token.worker.d.ts +1 -1
- package/dist/typings/worker/worker.types.d.ts +30 -27
- package/dist/typings/worker/worker.utils.d.ts +13 -13
- package/package.json +1 -1
- package/src/Auth0Client.ts +10 -0
- package/src/api.ts +15 -11
- package/src/cache/cache-manager.ts +28 -9
- package/src/version.ts +1 -1
- package/src/worker/token.worker.ts +6 -0
- package/src/worker/worker.types.ts +6 -1
- package/src/worker/worker.utils.ts +5 -1
package/dist/typings/http.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { FetchOptions } from './global';
|
|
2
|
-
import { Dpop } from './dpop/dpop';
|
|
3
|
-
export declare const createAbortController: () => AbortController;
|
|
4
|
-
/**
|
|
5
|
-
* Wraps a single `fetch` call with an AbortController-based timeout and
|
|
6
|
-
* returns the raw `Response`. Shared by the JSON token path and the revoke
|
|
7
|
-
* path to avoid duplicating abort/timeout orchestration.
|
|
8
|
-
*/
|
|
9
|
-
export declare const fetchWithTimeout: (fetchUrl: string, fetchOptions: FetchOptions, timeout: number) => Promise<Response>;
|
|
10
|
-
export declare const switchFetch: (fetchUrl: string, audience: string, scope: string, fetchOptions: FetchOptions, worker?: Worker, useFormData?: boolean, timeout?: number, useMrrt?: boolean) => Promise<any>;
|
|
11
|
-
export declare function getJSON<T>(url: string, timeout: number | undefined, audience: string, scope: string, options: FetchOptions, worker?: Worker, useFormData?: boolean, useMrrt?: boolean, dpop?: Pick<Dpop, 'generateProof' | 'getNonce' | 'setNonce'>, isDpopRetry?: boolean): Promise<T>;
|
|
1
|
+
import { FetchOptions } from './global';
|
|
2
|
+
import { Dpop } from './dpop/dpop';
|
|
3
|
+
export declare const createAbortController: () => AbortController;
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a single `fetch` call with an AbortController-based timeout and
|
|
6
|
+
* returns the raw `Response`. Shared by the JSON token path and the revoke
|
|
7
|
+
* path to avoid duplicating abort/timeout orchestration.
|
|
8
|
+
*/
|
|
9
|
+
export declare const fetchWithTimeout: (fetchUrl: string, fetchOptions: FetchOptions, timeout: number) => Promise<Response>;
|
|
10
|
+
export declare const switchFetch: (fetchUrl: string, audience: string, scope: string, fetchOptions: FetchOptions, worker?: Worker, useFormData?: boolean, timeout?: number, useMrrt?: boolean) => Promise<any>;
|
|
11
|
+
export declare function getJSON<T>(url: string, timeout: number | undefined, audience: string, scope: string, options: FetchOptions, worker?: Worker, useFormData?: boolean, useMrrt?: boolean, dpop?: Pick<Dpop, 'generateProof' | 'getNonce' | 'setNonce'>, isDpopRetry?: boolean): Promise<T>;
|
package/dist/typings/index.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Auth0Client } from './Auth0Client';
|
|
2
|
-
import { Auth0ClientOptions } from './global';
|
|
3
|
-
import './global';
|
|
4
|
-
export * from './global';
|
|
5
|
-
/**
|
|
6
|
-
* Asynchronously creates the Auth0Client instance and calls `checkSession`.
|
|
7
|
-
*
|
|
8
|
-
* **Note:** There are caveats to using this in a private browser tab, which may not silently authenticate
|
|
9
|
-
* a user on page refresh. Please see [the checkSession docs](https://auth0.github.io/auth0-spa-js/classes/Auth0Client.html#checksession) for more info.
|
|
10
|
-
*
|
|
11
|
-
* @param options The client options
|
|
12
|
-
* @returns An instance of Auth0Client
|
|
13
|
-
*/
|
|
14
|
-
export declare function createAuth0Client(options: Auth0ClientOptions): Promise<Auth0Client>;
|
|
15
|
-
export { Auth0Client };
|
|
16
|
-
export { ConnectError, GenericError, AuthenticationError, TimeoutError, PopupTimeoutError, PopupCancelledError, PopupOpenError, MfaRequiredError, MissingRefreshTokenError, UseDpopNonceError } from './errors';
|
|
17
|
-
export { MfaError, MfaListAuthenticatorsError, MfaEnrollmentError, MfaChallengeError, MfaVerifyError, MfaEnrollmentFactorsError } from './mfa/errors';
|
|
18
|
-
export { MfaApiClient } from './mfa';
|
|
19
|
-
export type { MfaFactorType, EnrollParams, EnrollOtpParams, EnrollSmsParams, EnrollVoiceParams, EnrollEmailParams, EnrollPushParams, VerifyParams } from './mfa';
|
|
20
|
-
export { LocalStorageCache, InMemoryCache, CacheKey } from './cache';
|
|
21
|
-
export type { ICache, Cacheable, DecodedToken, CacheEntry, WrappedCacheEntry, KeyManifestEntry, MaybePromise, CacheKeyData } from './cache';
|
|
22
|
-
export type { FetcherConfig, Fetcher, CustomFetchMinimalOutput } from './fetcher';
|
|
23
|
-
export { MyAccountApiError } from './MyAccountApiClient';
|
|
24
|
-
export type { CustomTokenExchangeOptions } from './TokenExchange';
|
|
1
|
+
import { Auth0Client } from './Auth0Client';
|
|
2
|
+
import { Auth0ClientOptions } from './global';
|
|
3
|
+
import './global';
|
|
4
|
+
export * from './global';
|
|
5
|
+
/**
|
|
6
|
+
* Asynchronously creates the Auth0Client instance and calls `checkSession`.
|
|
7
|
+
*
|
|
8
|
+
* **Note:** There are caveats to using this in a private browser tab, which may not silently authenticate
|
|
9
|
+
* a user on page refresh. Please see [the checkSession docs](https://auth0.github.io/auth0-spa-js/classes/Auth0Client.html#checksession) for more info.
|
|
10
|
+
*
|
|
11
|
+
* @param options The client options
|
|
12
|
+
* @returns An instance of Auth0Client
|
|
13
|
+
*/
|
|
14
|
+
export declare function createAuth0Client(options: Auth0ClientOptions): Promise<Auth0Client>;
|
|
15
|
+
export { Auth0Client };
|
|
16
|
+
export { ConnectError, GenericError, AuthenticationError, TimeoutError, PopupTimeoutError, PopupCancelledError, PopupOpenError, MfaRequiredError, MissingRefreshTokenError, UseDpopNonceError } from './errors';
|
|
17
|
+
export { MfaError, MfaListAuthenticatorsError, MfaEnrollmentError, MfaChallengeError, MfaVerifyError, MfaEnrollmentFactorsError } from './mfa/errors';
|
|
18
|
+
export { MfaApiClient } from './mfa';
|
|
19
|
+
export type { MfaFactorType, EnrollParams, EnrollOtpParams, EnrollSmsParams, EnrollVoiceParams, EnrollEmailParams, EnrollPushParams, VerifyParams } from './mfa';
|
|
20
|
+
export { LocalStorageCache, InMemoryCache, CacheKey } from './cache';
|
|
21
|
+
export type { ICache, Cacheable, DecodedToken, CacheEntry, WrappedCacheEntry, KeyManifestEntry, MaybePromise, CacheKeyData } from './cache';
|
|
22
|
+
export type { FetcherConfig, Fetcher, CustomFetchMinimalOutput } from './fetcher';
|
|
23
|
+
export { MyAccountApiError } from './MyAccountApiClient';
|
|
24
|
+
export type { CustomTokenExchangeOptions } from './TokenExchange';
|
package/dist/typings/jwt.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { IdToken, JWTVerifyOptions } from './global';
|
|
2
|
-
export declare const decode: (token: string) => {
|
|
3
|
-
encoded: {
|
|
4
|
-
header: string;
|
|
5
|
-
payload: string;
|
|
6
|
-
signature: string;
|
|
7
|
-
};
|
|
8
|
-
header: any;
|
|
9
|
-
claims: IdToken;
|
|
10
|
-
user: any;
|
|
11
|
-
};
|
|
12
|
-
export declare const verify: (options: JWTVerifyOptions) => {
|
|
13
|
-
encoded: {
|
|
14
|
-
header: string;
|
|
15
|
-
payload: string;
|
|
16
|
-
signature: string;
|
|
17
|
-
};
|
|
18
|
-
header: any;
|
|
19
|
-
claims: IdToken;
|
|
20
|
-
user: any;
|
|
21
|
-
};
|
|
1
|
+
import { IdToken, JWTVerifyOptions } from './global';
|
|
2
|
+
export declare const decode: (token: string) => {
|
|
3
|
+
encoded: {
|
|
4
|
+
header: string;
|
|
5
|
+
payload: string;
|
|
6
|
+
signature: string;
|
|
7
|
+
};
|
|
8
|
+
header: any;
|
|
9
|
+
claims: IdToken;
|
|
10
|
+
user: any;
|
|
11
|
+
};
|
|
12
|
+
export declare const verify: (options: JWTVerifyOptions) => {
|
|
13
|
+
encoded: {
|
|
14
|
+
header: string;
|
|
15
|
+
payload: string;
|
|
16
|
+
signature: string;
|
|
17
|
+
};
|
|
18
|
+
header: any;
|
|
19
|
+
claims: IdToken;
|
|
20
|
+
user: any;
|
|
21
|
+
};
|
package/dist/typings/lock.d.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lock manager abstraction for cross-tab synchronization.
|
|
3
|
-
* Supports both modern Web Locks API and legacy localStorage-based locking.
|
|
4
|
-
*/
|
|
5
|
-
/** Lock manager interface - callback pattern ensures automatic lock release */
|
|
6
|
-
export interface ILockManager {
|
|
7
|
-
/**
|
|
8
|
-
* Run callback while holding a lock.
|
|
9
|
-
* Lock is automatically released when callback completes or throws.
|
|
10
|
-
*
|
|
11
|
-
* @param key - Lock identifier
|
|
12
|
-
* @param timeout - Maximum time to wait for lock acquisition (ms)
|
|
13
|
-
* @param callback - Function to execute while holding the lock
|
|
14
|
-
* @returns Promise resolving to callback's return value
|
|
15
|
-
* @throws Error if lock cannot be acquired within timeout
|
|
16
|
-
*/
|
|
17
|
-
runWithLock<T>(key: string, timeout: number, callback: () => Promise<T>): Promise<T>;
|
|
18
|
-
}
|
|
19
|
-
/** Web Locks API implementation - true mutex with OS-level queuing */
|
|
20
|
-
export declare class WebLocksApiManager implements ILockManager {
|
|
21
|
-
runWithLock<T>(key: string, timeout: number, callback: () => Promise<T>): Promise<T>;
|
|
22
|
-
}
|
|
23
|
-
/** Legacy localStorage-based locking with retry logic for older browsers */
|
|
24
|
-
export declare class LegacyLockManager implements ILockManager {
|
|
25
|
-
private lock;
|
|
26
|
-
private activeLocks;
|
|
27
|
-
private pagehideHandler;
|
|
28
|
-
constructor();
|
|
29
|
-
runWithLock<T>(key: string, timeout: number, callback: () => Promise<T>): Promise<T>;
|
|
30
|
-
}
|
|
31
|
-
export declare function getLockManager(): ILockManager;
|
|
32
|
-
export declare function resetLockManager(): void;
|
|
1
|
+
/**
|
|
2
|
+
* Lock manager abstraction for cross-tab synchronization.
|
|
3
|
+
* Supports both modern Web Locks API and legacy localStorage-based locking.
|
|
4
|
+
*/
|
|
5
|
+
/** Lock manager interface - callback pattern ensures automatic lock release */
|
|
6
|
+
export interface ILockManager {
|
|
7
|
+
/**
|
|
8
|
+
* Run callback while holding a lock.
|
|
9
|
+
* Lock is automatically released when callback completes or throws.
|
|
10
|
+
*
|
|
11
|
+
* @param key - Lock identifier
|
|
12
|
+
* @param timeout - Maximum time to wait for lock acquisition (ms)
|
|
13
|
+
* @param callback - Function to execute while holding the lock
|
|
14
|
+
* @returns Promise resolving to callback's return value
|
|
15
|
+
* @throws Error if lock cannot be acquired within timeout
|
|
16
|
+
*/
|
|
17
|
+
runWithLock<T>(key: string, timeout: number, callback: () => Promise<T>): Promise<T>;
|
|
18
|
+
}
|
|
19
|
+
/** Web Locks API implementation - true mutex with OS-level queuing */
|
|
20
|
+
export declare class WebLocksApiManager implements ILockManager {
|
|
21
|
+
runWithLock<T>(key: string, timeout: number, callback: () => Promise<T>): Promise<T>;
|
|
22
|
+
}
|
|
23
|
+
/** Legacy localStorage-based locking with retry logic for older browsers */
|
|
24
|
+
export declare class LegacyLockManager implements ILockManager {
|
|
25
|
+
private lock;
|
|
26
|
+
private activeLocks;
|
|
27
|
+
private pagehideHandler;
|
|
28
|
+
constructor();
|
|
29
|
+
runWithLock<T>(key: string, timeout: number, callback: () => Promise<T>): Promise<T>;
|
|
30
|
+
}
|
|
31
|
+
export declare function getLockManager(): ILockManager;
|
|
32
|
+
export declare function resetLockManager(): void;
|
|
@@ -1,225 +1,225 @@
|
|
|
1
|
-
import { Auth0Client } from '../Auth0Client';
|
|
2
|
-
import type { TokenEndpointResponse } from '../global';
|
|
3
|
-
import type { Authenticator, EnrollParams, EnrollmentResponse, ChallengeAuthenticatorParams, ChallengeResponse, VerifyParams, EnrollmentFactor } from './types';
|
|
4
|
-
import { MfaClient as Auth0AuthJsMfaClient } from '@auth0/auth0-auth-js';
|
|
5
|
-
import { MfaRequirements } from '../errors';
|
|
6
|
-
/**
|
|
7
|
-
* Client for Auth0 MFA API operations
|
|
8
|
-
*
|
|
9
|
-
* Manages multi-factor authentication including:
|
|
10
|
-
* - Listing enrolled authenticators
|
|
11
|
-
* - Enrolling new authenticators (OTP, SMS, Voice, Push, Email)
|
|
12
|
-
* - Initiating MFA challenges
|
|
13
|
-
* - Verifying MFA challenges
|
|
14
|
-
*
|
|
15
|
-
* This is a wrapper around auth0-auth-js MfaClient that maintains
|
|
16
|
-
* backward compatibility with the existing spa-js API.
|
|
17
|
-
*
|
|
18
|
-
* MFA context (scope, audience) is stored internally keyed by mfaToken,
|
|
19
|
-
* enabling concurrent MFA flows without state conflicts.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* try {
|
|
24
|
-
* await auth0.getTokenSilently({ authorizationParams: { audience: 'https://api.example.com' } });
|
|
25
|
-
* } catch (e) {
|
|
26
|
-
* if (e instanceof MfaRequiredError) {
|
|
27
|
-
* // SDK automatically stores context for this mfaToken
|
|
28
|
-
* const authenticators = await auth0.mfa.getAuthenticators({ mfaToken: e.mfa_token });
|
|
29
|
-
* // ... complete MFA flow
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export declare class MfaApiClient {
|
|
35
|
-
private authJsMfaClient;
|
|
36
|
-
private auth0Client;
|
|
37
|
-
private contextManager;
|
|
38
|
-
/**
|
|
39
|
-
* @internal
|
|
40
|
-
* Do not instantiate directly. Use Auth0Client.mfa instead.
|
|
41
|
-
*/
|
|
42
|
-
constructor(authJsMfaClient: Auth0AuthJsMfaClient, auth0Client: Auth0Client);
|
|
43
|
-
/**
|
|
44
|
-
* @internal
|
|
45
|
-
* Stores authentication details (scope, audience, and MFA requirements) for MFA token verification.
|
|
46
|
-
* This is automatically called by Auth0Client when an mfa_required error occurs.
|
|
47
|
-
*
|
|
48
|
-
* The context is stored keyed by the MFA token, enabling concurrent MFA flows.
|
|
49
|
-
*
|
|
50
|
-
* @param mfaToken - The MFA token from the mfa_required error response
|
|
51
|
-
* @param scope - The OAuth scope from the original request (optional)
|
|
52
|
-
* @param audience - The API audience from the original request (optional)
|
|
53
|
-
* @param mfaRequirements - The MFA requirements from the mfa_required error (optional)
|
|
54
|
-
*/
|
|
55
|
-
setMFAAuthDetails(mfaToken: string, scope?: string, audience?: string, mfaRequirements?: MfaRequirements): void;
|
|
56
|
-
/**
|
|
57
|
-
* Gets enrolled MFA authenticators filtered by challenge types from context.
|
|
58
|
-
*
|
|
59
|
-
* Challenge types are automatically resolved from the stored MFA context
|
|
60
|
-
* (set when mfa_required error occurred).
|
|
61
|
-
*
|
|
62
|
-
* @param mfaToken - MFA token from mfa_required error
|
|
63
|
-
* @returns Array of enrolled authenticators matching the challenge types
|
|
64
|
-
* @throws {MfaListAuthenticatorsError} If the request fails or context not found
|
|
65
|
-
*
|
|
66
|
-
* @example Basic usage
|
|
67
|
-
* ```typescript
|
|
68
|
-
* try {
|
|
69
|
-
* await auth0.getTokenSilently();
|
|
70
|
-
* } catch (e) {
|
|
71
|
-
* if (e instanceof MfaRequiredError) {
|
|
72
|
-
* // SDK automatically uses challenge types from error context
|
|
73
|
-
* const authenticators = await auth0.mfa.getAuthenticators(e.mfa_token);
|
|
74
|
-
* }
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
getAuthenticators(mfaToken: string): Promise<Authenticator[]>;
|
|
79
|
-
/**
|
|
80
|
-
* Enrolls a new MFA authenticator
|
|
81
|
-
*
|
|
82
|
-
* Requires MFA access token with 'enroll' scope
|
|
83
|
-
*
|
|
84
|
-
* @param params - Enrollment parameters including mfaToken and factorType
|
|
85
|
-
* @returns Enrollment response with authenticator details
|
|
86
|
-
* @throws {MfaEnrollmentError} If enrollment fails
|
|
87
|
-
*
|
|
88
|
-
* @example OTP enrollment
|
|
89
|
-
* ```typescript
|
|
90
|
-
* const enrollment = await mfa.enroll({
|
|
91
|
-
* mfaToken: mfaToken,
|
|
92
|
-
* factorType: 'otp'
|
|
93
|
-
* });
|
|
94
|
-
* console.log(enrollment.secret); // Base32 secret
|
|
95
|
-
* console.log(enrollment.barcodeUri); // QR code URI
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* @example SMS enrollment
|
|
99
|
-
* ```typescript
|
|
100
|
-
* const enrollment = await mfa.enroll({
|
|
101
|
-
* mfaToken: mfaToken,
|
|
102
|
-
* factorType: 'sms',
|
|
103
|
-
* phoneNumber: '+12025551234'
|
|
104
|
-
* });
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
enroll(params: EnrollParams): Promise<EnrollmentResponse>;
|
|
108
|
-
/**
|
|
109
|
-
* Initiates an MFA challenge
|
|
110
|
-
*
|
|
111
|
-
* Sends OTP via SMS, initiates push notification, or prepares for OTP entry
|
|
112
|
-
*
|
|
113
|
-
* @param params - Challenge parameters including mfaToken
|
|
114
|
-
* @returns Challenge response with oobCode if applicable
|
|
115
|
-
* @throws {MfaChallengeError} If challenge initiation fails
|
|
116
|
-
*
|
|
117
|
-
* @example OTP challenge
|
|
118
|
-
* ```typescript
|
|
119
|
-
* const challenge = await mfa.challenge({
|
|
120
|
-
* mfaToken: mfaTokenFromLogin,
|
|
121
|
-
* challengeType: 'otp',
|
|
122
|
-
* authenticatorId: 'otp|dev_xxx'
|
|
123
|
-
* });
|
|
124
|
-
* // User enters OTP from their authenticator app
|
|
125
|
-
* ```
|
|
126
|
-
*
|
|
127
|
-
* @example SMS challenge
|
|
128
|
-
* ```typescript
|
|
129
|
-
* const challenge = await mfa.challenge({
|
|
130
|
-
* mfaToken: mfaTokenFromLogin,
|
|
131
|
-
* challengeType: 'oob',
|
|
132
|
-
* authenticatorId: 'sms|dev_xxx'
|
|
133
|
-
* });
|
|
134
|
-
* console.log(challenge.oobCode); // Use for verification
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
challenge(params: ChallengeAuthenticatorParams): Promise<ChallengeResponse>;
|
|
138
|
-
/**
|
|
139
|
-
* Gets available MFA enrollment factors from the stored context.
|
|
140
|
-
*
|
|
141
|
-
* This method exposes the enrollment options from the mfa_required error's
|
|
142
|
-
* mfaRequirements.enroll array, eliminating the need for manual parsing.
|
|
143
|
-
*
|
|
144
|
-
* @param mfaToken - MFA token from mfa_required error
|
|
145
|
-
* @returns Array of enrollment factors available for the user (empty array if no enrollment required)
|
|
146
|
-
* @throws {MfaEnrollmentFactorsError} If MFA context not found
|
|
147
|
-
*
|
|
148
|
-
* @example Basic usage
|
|
149
|
-
* ```typescript
|
|
150
|
-
* try {
|
|
151
|
-
* await auth0.getTokenSilently();
|
|
152
|
-
* } catch (error) {
|
|
153
|
-
* if (error.error === 'mfa_required') {
|
|
154
|
-
* // Get enrollment options from SDK
|
|
155
|
-
* const enrollOptions = await auth0.mfa.getEnrollmentFactors(error.mfa_token);
|
|
156
|
-
* // [{ type: 'otp' }, { type: 'phone' }, { type: 'push-notification' }]
|
|
157
|
-
*
|
|
158
|
-
* showEnrollmentOptions(enrollOptions);
|
|
159
|
-
* }
|
|
160
|
-
* }
|
|
161
|
-
* ```
|
|
162
|
-
*
|
|
163
|
-
* @example Check if enrollment is required
|
|
164
|
-
* ```typescript
|
|
165
|
-
* try {
|
|
166
|
-
* const factors = await auth0.mfa.getEnrollmentFactors(mfaToken);
|
|
167
|
-
* if (factors.length > 0) {
|
|
168
|
-
* // User needs to enroll in MFA
|
|
169
|
-
* renderEnrollmentUI(factors);
|
|
170
|
-
* } else {
|
|
171
|
-
* // No enrollment required, proceed with challenge
|
|
172
|
-
* }
|
|
173
|
-
* } catch (error) {
|
|
174
|
-
* if (error instanceof MfaEnrollmentFactorsError) {
|
|
175
|
-
* console.error('Context not found:', error.error_description);
|
|
176
|
-
* }
|
|
177
|
-
* }
|
|
178
|
-
* ```
|
|
179
|
-
*/
|
|
180
|
-
getEnrollmentFactors(mfaToken: string): Promise<EnrollmentFactor[]>;
|
|
181
|
-
/**
|
|
182
|
-
* Verifies an MFA challenge and completes authentication
|
|
183
|
-
*
|
|
184
|
-
* The scope and audience are retrieved from the stored context (set when the
|
|
185
|
-
* mfa_required error occurred). The grant_type is automatically inferred from
|
|
186
|
-
* which verification field is provided (otp, oobCode, or recoveryCode).
|
|
187
|
-
*
|
|
188
|
-
* @param params - Verification parameters with OTP, OOB code, or recovery code
|
|
189
|
-
* @returns Token response with access_token, id_token, refresh_token
|
|
190
|
-
* @throws {MfaVerifyError} If verification fails (invalid code, expired, rate limited)
|
|
191
|
-
* @throws {MfaVerifyError} If MFA context not found
|
|
192
|
-
* @throws {MfaVerifyError} If grant_type cannot be inferred
|
|
193
|
-
*
|
|
194
|
-
* Rate limits:
|
|
195
|
-
* - 10 verification attempts allowed
|
|
196
|
-
* - Refreshes at 1 attempt per 6 minutes
|
|
197
|
-
*
|
|
198
|
-
* @example OTP verification (grant_type inferred from otp field)
|
|
199
|
-
* ```typescript
|
|
200
|
-
* const tokens = await mfa.verify({
|
|
201
|
-
* mfaToken: mfaTokenFromLogin,
|
|
202
|
-
* otp: '123456'
|
|
203
|
-
* });
|
|
204
|
-
* console.log(tokens.access_token);
|
|
205
|
-
* ```
|
|
206
|
-
*
|
|
207
|
-
* @example OOB verification (grant_type inferred from oobCode field)
|
|
208
|
-
* ```typescript
|
|
209
|
-
* const tokens = await mfa.verify({
|
|
210
|
-
* mfaToken: mfaTokenFromLogin,
|
|
211
|
-
* oobCode: challenge.oobCode,
|
|
212
|
-
* bindingCode: '123456' // Code user received via SMS
|
|
213
|
-
* });
|
|
214
|
-
* ```
|
|
215
|
-
*
|
|
216
|
-
* @example Recovery code verification (grant_type inferred from recoveryCode field)
|
|
217
|
-
* ```typescript
|
|
218
|
-
* const tokens = await mfa.verify({
|
|
219
|
-
* mfaToken: mfaTokenFromLogin,
|
|
220
|
-
* recoveryCode: 'XXXX-XXXX-XXXX'
|
|
221
|
-
* });
|
|
222
|
-
* ```
|
|
223
|
-
*/
|
|
224
|
-
verify(params: VerifyParams): Promise<TokenEndpointResponse>;
|
|
225
|
-
}
|
|
1
|
+
import { Auth0Client } from '../Auth0Client';
|
|
2
|
+
import type { TokenEndpointResponse } from '../global';
|
|
3
|
+
import type { Authenticator, EnrollParams, EnrollmentResponse, ChallengeAuthenticatorParams, ChallengeResponse, VerifyParams, EnrollmentFactor } from './types';
|
|
4
|
+
import { MfaClient as Auth0AuthJsMfaClient } from '@auth0/auth0-auth-js';
|
|
5
|
+
import { MfaRequirements } from '../errors';
|
|
6
|
+
/**
|
|
7
|
+
* Client for Auth0 MFA API operations
|
|
8
|
+
*
|
|
9
|
+
* Manages multi-factor authentication including:
|
|
10
|
+
* - Listing enrolled authenticators
|
|
11
|
+
* - Enrolling new authenticators (OTP, SMS, Voice, Push, Email)
|
|
12
|
+
* - Initiating MFA challenges
|
|
13
|
+
* - Verifying MFA challenges
|
|
14
|
+
*
|
|
15
|
+
* This is a wrapper around auth0-auth-js MfaClient that maintains
|
|
16
|
+
* backward compatibility with the existing spa-js API.
|
|
17
|
+
*
|
|
18
|
+
* MFA context (scope, audience) is stored internally keyed by mfaToken,
|
|
19
|
+
* enabling concurrent MFA flows without state conflicts.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* try {
|
|
24
|
+
* await auth0.getTokenSilently({ authorizationParams: { audience: 'https://api.example.com' } });
|
|
25
|
+
* } catch (e) {
|
|
26
|
+
* if (e instanceof MfaRequiredError) {
|
|
27
|
+
* // SDK automatically stores context for this mfaToken
|
|
28
|
+
* const authenticators = await auth0.mfa.getAuthenticators({ mfaToken: e.mfa_token });
|
|
29
|
+
* // ... complete MFA flow
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class MfaApiClient {
|
|
35
|
+
private authJsMfaClient;
|
|
36
|
+
private auth0Client;
|
|
37
|
+
private contextManager;
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
* Do not instantiate directly. Use Auth0Client.mfa instead.
|
|
41
|
+
*/
|
|
42
|
+
constructor(authJsMfaClient: Auth0AuthJsMfaClient, auth0Client: Auth0Client);
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
* Stores authentication details (scope, audience, and MFA requirements) for MFA token verification.
|
|
46
|
+
* This is automatically called by Auth0Client when an mfa_required error occurs.
|
|
47
|
+
*
|
|
48
|
+
* The context is stored keyed by the MFA token, enabling concurrent MFA flows.
|
|
49
|
+
*
|
|
50
|
+
* @param mfaToken - The MFA token from the mfa_required error response
|
|
51
|
+
* @param scope - The OAuth scope from the original request (optional)
|
|
52
|
+
* @param audience - The API audience from the original request (optional)
|
|
53
|
+
* @param mfaRequirements - The MFA requirements from the mfa_required error (optional)
|
|
54
|
+
*/
|
|
55
|
+
setMFAAuthDetails(mfaToken: string, scope?: string, audience?: string, mfaRequirements?: MfaRequirements): void;
|
|
56
|
+
/**
|
|
57
|
+
* Gets enrolled MFA authenticators filtered by challenge types from context.
|
|
58
|
+
*
|
|
59
|
+
* Challenge types are automatically resolved from the stored MFA context
|
|
60
|
+
* (set when mfa_required error occurred).
|
|
61
|
+
*
|
|
62
|
+
* @param mfaToken - MFA token from mfa_required error
|
|
63
|
+
* @returns Array of enrolled authenticators matching the challenge types
|
|
64
|
+
* @throws {MfaListAuthenticatorsError} If the request fails or context not found
|
|
65
|
+
*
|
|
66
|
+
* @example Basic usage
|
|
67
|
+
* ```typescript
|
|
68
|
+
* try {
|
|
69
|
+
* await auth0.getTokenSilently();
|
|
70
|
+
* } catch (e) {
|
|
71
|
+
* if (e instanceof MfaRequiredError) {
|
|
72
|
+
* // SDK automatically uses challenge types from error context
|
|
73
|
+
* const authenticators = await auth0.mfa.getAuthenticators(e.mfa_token);
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
getAuthenticators(mfaToken: string): Promise<Authenticator[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Enrolls a new MFA authenticator
|
|
81
|
+
*
|
|
82
|
+
* Requires MFA access token with 'enroll' scope
|
|
83
|
+
*
|
|
84
|
+
* @param params - Enrollment parameters including mfaToken and factorType
|
|
85
|
+
* @returns Enrollment response with authenticator details
|
|
86
|
+
* @throws {MfaEnrollmentError} If enrollment fails
|
|
87
|
+
*
|
|
88
|
+
* @example OTP enrollment
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const enrollment = await mfa.enroll({
|
|
91
|
+
* mfaToken: mfaToken,
|
|
92
|
+
* factorType: 'otp'
|
|
93
|
+
* });
|
|
94
|
+
* console.log(enrollment.secret); // Base32 secret
|
|
95
|
+
* console.log(enrollment.barcodeUri); // QR code URI
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example SMS enrollment
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const enrollment = await mfa.enroll({
|
|
101
|
+
* mfaToken: mfaToken,
|
|
102
|
+
* factorType: 'sms',
|
|
103
|
+
* phoneNumber: '+12025551234'
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
enroll(params: EnrollParams): Promise<EnrollmentResponse>;
|
|
108
|
+
/**
|
|
109
|
+
* Initiates an MFA challenge
|
|
110
|
+
*
|
|
111
|
+
* Sends OTP via SMS, initiates push notification, or prepares for OTP entry
|
|
112
|
+
*
|
|
113
|
+
* @param params - Challenge parameters including mfaToken
|
|
114
|
+
* @returns Challenge response with oobCode if applicable
|
|
115
|
+
* @throws {MfaChallengeError} If challenge initiation fails
|
|
116
|
+
*
|
|
117
|
+
* @example OTP challenge
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const challenge = await mfa.challenge({
|
|
120
|
+
* mfaToken: mfaTokenFromLogin,
|
|
121
|
+
* challengeType: 'otp',
|
|
122
|
+
* authenticatorId: 'otp|dev_xxx'
|
|
123
|
+
* });
|
|
124
|
+
* // User enters OTP from their authenticator app
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @example SMS challenge
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const challenge = await mfa.challenge({
|
|
130
|
+
* mfaToken: mfaTokenFromLogin,
|
|
131
|
+
* challengeType: 'oob',
|
|
132
|
+
* authenticatorId: 'sms|dev_xxx'
|
|
133
|
+
* });
|
|
134
|
+
* console.log(challenge.oobCode); // Use for verification
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
challenge(params: ChallengeAuthenticatorParams): Promise<ChallengeResponse>;
|
|
138
|
+
/**
|
|
139
|
+
* Gets available MFA enrollment factors from the stored context.
|
|
140
|
+
*
|
|
141
|
+
* This method exposes the enrollment options from the mfa_required error's
|
|
142
|
+
* mfaRequirements.enroll array, eliminating the need for manual parsing.
|
|
143
|
+
*
|
|
144
|
+
* @param mfaToken - MFA token from mfa_required error
|
|
145
|
+
* @returns Array of enrollment factors available for the user (empty array if no enrollment required)
|
|
146
|
+
* @throws {MfaEnrollmentFactorsError} If MFA context not found
|
|
147
|
+
*
|
|
148
|
+
* @example Basic usage
|
|
149
|
+
* ```typescript
|
|
150
|
+
* try {
|
|
151
|
+
* await auth0.getTokenSilently();
|
|
152
|
+
* } catch (error) {
|
|
153
|
+
* if (error.error === 'mfa_required') {
|
|
154
|
+
* // Get enrollment options from SDK
|
|
155
|
+
* const enrollOptions = await auth0.mfa.getEnrollmentFactors(error.mfa_token);
|
|
156
|
+
* // [{ type: 'otp' }, { type: 'phone' }, { type: 'push-notification' }]
|
|
157
|
+
*
|
|
158
|
+
* showEnrollmentOptions(enrollOptions);
|
|
159
|
+
* }
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @example Check if enrollment is required
|
|
164
|
+
* ```typescript
|
|
165
|
+
* try {
|
|
166
|
+
* const factors = await auth0.mfa.getEnrollmentFactors(mfaToken);
|
|
167
|
+
* if (factors.length > 0) {
|
|
168
|
+
* // User needs to enroll in MFA
|
|
169
|
+
* renderEnrollmentUI(factors);
|
|
170
|
+
* } else {
|
|
171
|
+
* // No enrollment required, proceed with challenge
|
|
172
|
+
* }
|
|
173
|
+
* } catch (error) {
|
|
174
|
+
* if (error instanceof MfaEnrollmentFactorsError) {
|
|
175
|
+
* console.error('Context not found:', error.error_description);
|
|
176
|
+
* }
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
getEnrollmentFactors(mfaToken: string): Promise<EnrollmentFactor[]>;
|
|
181
|
+
/**
|
|
182
|
+
* Verifies an MFA challenge and completes authentication
|
|
183
|
+
*
|
|
184
|
+
* The scope and audience are retrieved from the stored context (set when the
|
|
185
|
+
* mfa_required error occurred). The grant_type is automatically inferred from
|
|
186
|
+
* which verification field is provided (otp, oobCode, or recoveryCode).
|
|
187
|
+
*
|
|
188
|
+
* @param params - Verification parameters with OTP, OOB code, or recovery code
|
|
189
|
+
* @returns Token response with access_token, id_token, refresh_token
|
|
190
|
+
* @throws {MfaVerifyError} If verification fails (invalid code, expired, rate limited)
|
|
191
|
+
* @throws {MfaVerifyError} If MFA context not found
|
|
192
|
+
* @throws {MfaVerifyError} If grant_type cannot be inferred
|
|
193
|
+
*
|
|
194
|
+
* Rate limits:
|
|
195
|
+
* - 10 verification attempts allowed
|
|
196
|
+
* - Refreshes at 1 attempt per 6 minutes
|
|
197
|
+
*
|
|
198
|
+
* @example OTP verification (grant_type inferred from otp field)
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const tokens = await mfa.verify({
|
|
201
|
+
* mfaToken: mfaTokenFromLogin,
|
|
202
|
+
* otp: '123456'
|
|
203
|
+
* });
|
|
204
|
+
* console.log(tokens.access_token);
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @example OOB verification (grant_type inferred from oobCode field)
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const tokens = await mfa.verify({
|
|
210
|
+
* mfaToken: mfaTokenFromLogin,
|
|
211
|
+
* oobCode: challenge.oobCode,
|
|
212
|
+
* bindingCode: '123456' // Code user received via SMS
|
|
213
|
+
* });
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @example Recovery code verification (grant_type inferred from recoveryCode field)
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const tokens = await mfa.verify({
|
|
219
|
+
* mfaToken: mfaTokenFromLogin,
|
|
220
|
+
* recoveryCode: 'XXXX-XXXX-XXXX'
|
|
221
|
+
* });
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
verify(params: VerifyParams): Promise<TokenEndpointResponse>;
|
|
225
|
+
}
|