@auth0/auth0-spa-js 2.11.3 → 2.13.0
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 +4 -2
- package/dist/auth0-spa-js.development.js +6040 -920
- 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 +13 -8
- 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 +6450 -913
- package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
- package/dist/typings/Auth0Client.d.ts +51 -1
- package/dist/typings/errors.d.ts +15 -1
- package/dist/typings/global.d.ts +17 -2
- package/dist/typings/index.d.ts +3 -0
- package/dist/typings/mfa/MfaApiClient.d.ts +225 -0
- package/dist/typings/mfa/MfaContextManager.d.ts +79 -0
- package/dist/typings/mfa/constants.d.ts +23 -0
- package/dist/typings/mfa/errors.d.ts +117 -0
- package/dist/typings/mfa/index.d.ts +4 -0
- package/dist/typings/mfa/types.d.ts +181 -0
- package/dist/typings/mfa/utils.d.ts +23 -0
- package/dist/typings/utils.d.ts +2 -1
- package/dist/typings/version.d.ts +1 -1
- package/package.json +8 -4
- package/src/Auth0Client.ts +88 -5
- package/src/dpop/utils.ts +4 -1
- package/src/errors.ts +12 -1
- package/src/global.ts +41 -1
- package/src/http.ts +1 -1
- package/src/index.ts +22 -0
- package/src/mfa/MfaApiClient.ts +425 -0
- package/src/mfa/MfaContextManager.ts +128 -0
- package/src/mfa/constants.ts +48 -0
- package/src/mfa/errors.ts +154 -0
- package/src/mfa/index.ts +24 -0
- package/src/mfa/types.ts +209 -0
- package/src/mfa/utils.ts +41 -0
- package/src/utils.ts +7 -1
- package/src/version.ts +1 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { MfaGrantTypes } from './constants';
|
|
2
|
+
/**
|
|
3
|
+
* Represents an MFA authenticator enrolled by a user
|
|
4
|
+
*/
|
|
5
|
+
export interface Authenticator {
|
|
6
|
+
/** Unique identifier for the authenticator */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Type of authenticator */
|
|
9
|
+
authenticatorType: AuthenticatorType;
|
|
10
|
+
/** Whether the authenticator is active */
|
|
11
|
+
active: boolean;
|
|
12
|
+
/** Optional friendly name */
|
|
13
|
+
name?: string;
|
|
14
|
+
/** ISO 8601 timestamp when created */
|
|
15
|
+
createdAt?: string;
|
|
16
|
+
/** ISO 8601 timestamp of last authentication */
|
|
17
|
+
lastAuth?: string;
|
|
18
|
+
/** Types of MFA challenges*/
|
|
19
|
+
type?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Supported authenticator types.
|
|
23
|
+
* Note: Email authenticators use 'oob' type with oobChannel: 'email'
|
|
24
|
+
*/
|
|
25
|
+
export type AuthenticatorType = 'otp' | 'oob' | 'recovery-code';
|
|
26
|
+
/**
|
|
27
|
+
* Types of MFA challenges
|
|
28
|
+
*/
|
|
29
|
+
export type ChallengeType = 'otp' | 'phone' | 'recovery-code' | 'email' | 'push-notification' | 'totp';
|
|
30
|
+
/**
|
|
31
|
+
* Out-of-band delivery channels.
|
|
32
|
+
* Includes 'email' which is also delivered out-of-band.
|
|
33
|
+
*/
|
|
34
|
+
export type OobChannel = 'sms' | 'voice' | 'auth0' | 'email';
|
|
35
|
+
/**
|
|
36
|
+
* Supported MFA factors for enrollment
|
|
37
|
+
*/
|
|
38
|
+
export type MfaFactorType = 'otp' | 'sms' | 'email' | 'push' | 'voice';
|
|
39
|
+
/**
|
|
40
|
+
* Base parameters for all enrollment types
|
|
41
|
+
*/
|
|
42
|
+
export interface EnrollBaseParams {
|
|
43
|
+
/** MFA token from mfa_required error */
|
|
44
|
+
mfaToken: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* OTP (Time-based One-Time Password) enrollment parameters
|
|
48
|
+
*/
|
|
49
|
+
export interface EnrollOtpParams extends EnrollBaseParams {
|
|
50
|
+
/** The factor type for enrollment */
|
|
51
|
+
factorType: 'otp';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* SMS enrollment parameters
|
|
55
|
+
*/
|
|
56
|
+
export interface EnrollSmsParams extends EnrollBaseParams {
|
|
57
|
+
/** The factor type for enrollment */
|
|
58
|
+
factorType: 'sms';
|
|
59
|
+
/** Phone number in E.164 format (required for SMS) */
|
|
60
|
+
phoneNumber: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Voice enrollment parameters
|
|
64
|
+
*/
|
|
65
|
+
export interface EnrollVoiceParams extends EnrollBaseParams {
|
|
66
|
+
/** The factor type for enrollment */
|
|
67
|
+
factorType: 'voice';
|
|
68
|
+
/** Phone number in E.164 format (required for voice) */
|
|
69
|
+
phoneNumber: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Email enrollment parameters
|
|
73
|
+
*/
|
|
74
|
+
export interface EnrollEmailParams extends EnrollBaseParams {
|
|
75
|
+
/** The factor type for enrollment */
|
|
76
|
+
factorType: 'email';
|
|
77
|
+
/** Email address (optional, uses user's email if not provided) */
|
|
78
|
+
email?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Push notification enrollment parameters
|
|
82
|
+
*/
|
|
83
|
+
export interface EnrollPushParams extends EnrollBaseParams {
|
|
84
|
+
/** The factor type for enrollment */
|
|
85
|
+
factorType: 'push';
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Union type for all enrollment parameter types
|
|
89
|
+
*/
|
|
90
|
+
export type EnrollParams = EnrollOtpParams | EnrollSmsParams | EnrollVoiceParams | EnrollEmailParams | EnrollPushParams;
|
|
91
|
+
/**
|
|
92
|
+
* Response when enrolling an OTP authenticator
|
|
93
|
+
*/
|
|
94
|
+
export interface OtpEnrollmentResponse {
|
|
95
|
+
/** Authenticator type */
|
|
96
|
+
authenticatorType: 'otp';
|
|
97
|
+
/** Base32-encoded secret for TOTP generation */
|
|
98
|
+
secret: string;
|
|
99
|
+
/** URI for generating QR code (otpauth://...) */
|
|
100
|
+
barcodeUri: string;
|
|
101
|
+
/** Recovery codes for account recovery */
|
|
102
|
+
recoveryCodes?: string[];
|
|
103
|
+
/** Authenticator ID */
|
|
104
|
+
id?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Response when enrolling an OOB authenticator
|
|
108
|
+
*/
|
|
109
|
+
export interface OobEnrollmentResponse {
|
|
110
|
+
/** Authenticator type */
|
|
111
|
+
authenticatorType: 'oob';
|
|
112
|
+
/** Delivery channel used */
|
|
113
|
+
oobChannel: OobChannel;
|
|
114
|
+
/** Out-of-band code for verification */
|
|
115
|
+
oobCode?: string;
|
|
116
|
+
/** Binding method (e.g., 'prompt' for user code entry) */
|
|
117
|
+
bindingMethod?: string;
|
|
118
|
+
/** Recovery codes (generated when enrolling first MFA factor) */
|
|
119
|
+
recoveryCodes?: string[];
|
|
120
|
+
/** Authenticator ID */
|
|
121
|
+
id?: string;
|
|
122
|
+
/** URI for QR code (for Push/Guardian enrollment) */
|
|
123
|
+
barcodeUri?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Union type for all enrollment response types
|
|
127
|
+
*/
|
|
128
|
+
export type EnrollmentResponse = OtpEnrollmentResponse | OobEnrollmentResponse;
|
|
129
|
+
/**
|
|
130
|
+
* Parameters for initiating an MFA challenge
|
|
131
|
+
*/
|
|
132
|
+
export interface ChallengeAuthenticatorParams {
|
|
133
|
+
/** MFA token from mfa_required error or MFA-scoped access token */
|
|
134
|
+
mfaToken: string;
|
|
135
|
+
/** Type of challenge to initiate */
|
|
136
|
+
challengeType: 'otp' | 'oob';
|
|
137
|
+
/** Specific authenticator to challenge (optional) */
|
|
138
|
+
authenticatorId?: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Response from initiating an MFA challenge
|
|
142
|
+
*/
|
|
143
|
+
export interface ChallengeResponse {
|
|
144
|
+
/** Type of challenge created */
|
|
145
|
+
challengeType: 'otp' | 'oob';
|
|
146
|
+
/** Out-of-band code (for OOB challenges) */
|
|
147
|
+
oobCode?: string;
|
|
148
|
+
/** Binding method for OOB (e.g., 'prompt') */
|
|
149
|
+
bindingMethod?: string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Grant types for MFA verification (derived from MfaGrantTypes constants)
|
|
153
|
+
*/
|
|
154
|
+
export type MfaGrantType = (typeof MfaGrantTypes)[keyof typeof MfaGrantTypes];
|
|
155
|
+
/**
|
|
156
|
+
* Parameters for verifying an MFA challenge.
|
|
157
|
+
*
|
|
158
|
+
* The grant_type is automatically inferred from which verification field is provided:
|
|
159
|
+
* - `otp` field → MFA-OTP grant type
|
|
160
|
+
* - `oobCode` field → MFA-OOB grant type
|
|
161
|
+
* - `recoveryCode` field → MFA-RECOVERY-CODE grant type
|
|
162
|
+
*/
|
|
163
|
+
export interface VerifyParams {
|
|
164
|
+
/** MFA token from challenge flow */
|
|
165
|
+
mfaToken: string;
|
|
166
|
+
/** One-time password (for OTP challenges) */
|
|
167
|
+
otp?: string;
|
|
168
|
+
/** Out-of-band code (for OOB challenges) */
|
|
169
|
+
oobCode?: string;
|
|
170
|
+
/** Binding code (for OOB challenges with binding) */
|
|
171
|
+
bindingCode?: string;
|
|
172
|
+
/** Recovery code (for recovery code verification) */
|
|
173
|
+
recoveryCode?: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Enrollment factor returned by getEnrollmentFactors
|
|
177
|
+
*/
|
|
178
|
+
export interface EnrollmentFactor {
|
|
179
|
+
/** Type of enrollment factor available */
|
|
180
|
+
type: string;
|
|
181
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { EnrollParams, VerifyParams, MfaGrantType } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Converts factor-based enrollment params to auth-js format
|
|
4
|
+
*
|
|
5
|
+
* @param params - The enrollment parameters with factorType
|
|
6
|
+
* @returns Parameters in auth-js format with authenticatorTypes/oobChannels
|
|
7
|
+
*/
|
|
8
|
+
export declare function getAuthJsEnrollParams(params: EnrollParams): {
|
|
9
|
+
email?: string | undefined;
|
|
10
|
+
phoneNumber?: string | undefined;
|
|
11
|
+
oobChannels?: import("./types").OobChannel[] | undefined;
|
|
12
|
+
mfaToken: string;
|
|
13
|
+
authenticatorTypes: ["otp"] | ["oob"];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Gets the grant type from verification parameters based on which field is provided.
|
|
17
|
+
*
|
|
18
|
+
* Priority order: otp > oobCode > recoveryCode
|
|
19
|
+
*
|
|
20
|
+
* @param params - The verification parameters
|
|
21
|
+
* @returns The grant type or undefined if no verification field is present
|
|
22
|
+
*/
|
|
23
|
+
export declare function getGrantType(params: VerifyParams): MfaGrantType | undefined;
|
package/dist/typings/utils.d.ts
CHANGED
|
@@ -10,9 +10,10 @@ export declare const decode: (value: string) => string;
|
|
|
10
10
|
/**
|
|
11
11
|
* Strips any property that is not present in ALLOWED_AUTH0CLIENT_PROPERTIES
|
|
12
12
|
* @param auth0Client - The full auth0Client object
|
|
13
|
+
* @param excludeEnv - If true, excludes the 'env' property from the result
|
|
13
14
|
* @returns The stripped auth0Client object
|
|
14
15
|
*/
|
|
15
|
-
export declare const stripAuth0Client: (auth0Client: any) => any;
|
|
16
|
+
export declare const stripAuth0Client: (auth0Client: any, excludeEnv?: boolean) => any;
|
|
16
17
|
export declare const createQueryParams: ({ clientId: client_id, ...params }: any) => string;
|
|
17
18
|
export declare const sha256: (s: string) => Promise<any>;
|
|
18
19
|
export declare const urlDecodeB64: (input: string) => string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "2.
|
|
1
|
+
declare const _default: "2.13.0";
|
|
2
2
|
export default _default;
|
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.13.0",
|
|
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,6 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@auth0/auth0-auth-js": "^1.4.0",
|
|
26
27
|
"browser-tabs-lock": "^1.2.15",
|
|
27
28
|
"dpop": "^2.1.1",
|
|
28
29
|
"es-cookie": "~1.3.2"
|
|
@@ -54,12 +55,17 @@
|
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
57
|
"@auth0/component-cdn-uploader": "^2.4.2",
|
|
58
|
+
"@babel/core": "^7.28.5",
|
|
59
|
+
"@babel/preset-env": "^7.28.5",
|
|
60
|
+
"@rollup/plugin-babel": "^6.1.0",
|
|
61
|
+
"@rollup/plugin-commonjs": "^21.1.0",
|
|
62
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
57
63
|
"@rollup/plugin-replace": "^4.0.0",
|
|
58
64
|
"@types/cypress": "^1.1.3",
|
|
59
65
|
"@types/jest": "^28.1.7",
|
|
60
66
|
"@typescript-eslint/eslint-plugin-tslint": "^5.33.1",
|
|
61
67
|
"@typescript-eslint/parser": "^5.33.1",
|
|
62
|
-
"browserstack-cypress-cli": "1.36.
|
|
68
|
+
"browserstack-cypress-cli": "1.36.2",
|
|
63
69
|
"cli-table": "^0.3.6",
|
|
64
70
|
"concurrently": "^7.3.0",
|
|
65
71
|
"cypress": "13.17.0",
|
|
@@ -82,10 +88,8 @@
|
|
|
82
88
|
"rimraf": "^3.0.2",
|
|
83
89
|
"rollup": "^2.78.0",
|
|
84
90
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
85
|
-
"rollup-plugin-commonjs": "^10.1.0",
|
|
86
91
|
"rollup-plugin-dev": "^1.1.3",
|
|
87
92
|
"rollup-plugin-livereload": "^2.0.5",
|
|
88
|
-
"rollup-plugin-node-resolve": "^5.2.0",
|
|
89
93
|
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
90
94
|
"rollup-plugin-terser": "^7.0.2",
|
|
91
95
|
"rollup-plugin-typescript2": "^0.36.0",
|
package/src/Auth0Client.ts
CHANGED
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
openPopup,
|
|
14
14
|
getDomain,
|
|
15
15
|
getTokenIssuer,
|
|
16
|
-
parseNumber
|
|
16
|
+
parseNumber,
|
|
17
|
+
stripAuth0Client
|
|
17
18
|
} from './utils';
|
|
18
19
|
|
|
19
20
|
import { oauthToken } from './api';
|
|
@@ -37,6 +38,7 @@ import {
|
|
|
37
38
|
AuthenticationError,
|
|
38
39
|
ConnectError,
|
|
39
40
|
GenericError,
|
|
41
|
+
MfaRequiredError,
|
|
40
42
|
MissingRefreshTokenError,
|
|
41
43
|
MissingScopesError,
|
|
42
44
|
PopupOpenError,
|
|
@@ -86,6 +88,7 @@ import {
|
|
|
86
88
|
RedirectConnectAccountOptions,
|
|
87
89
|
ResponseType,
|
|
88
90
|
ClientAuthorizationParams,
|
|
91
|
+
ClientConfiguration
|
|
89
92
|
} from './global';
|
|
90
93
|
|
|
91
94
|
// @ts-ignore
|
|
@@ -114,6 +117,8 @@ import {
|
|
|
114
117
|
type CustomFetchMinimalOutput
|
|
115
118
|
} from './fetcher';
|
|
116
119
|
import { MyAccountApiClient } from './MyAccountApiClient';
|
|
120
|
+
import { MfaApiClient } from './mfa';
|
|
121
|
+
import { AuthClient as Auth0AuthJsClient } from '@auth0/auth0-auth-js';
|
|
117
122
|
|
|
118
123
|
/**
|
|
119
124
|
* @ignore
|
|
@@ -152,8 +157,20 @@ export class Auth0Client {
|
|
|
152
157
|
private readonly userCache: ICache = new InMemoryCache().enclosedCache;
|
|
153
158
|
private readonly myAccountApi: MyAccountApiClient;
|
|
154
159
|
|
|
160
|
+
/**
|
|
161
|
+
* MFA API client for multi-factor authentication operations.
|
|
162
|
+
*
|
|
163
|
+
* Provides methods for:
|
|
164
|
+
* - Listing enrolled authenticators
|
|
165
|
+
* - Enrolling new authenticators (OTP, SMS, Voice, Push, Email)
|
|
166
|
+
* - Initiating MFA challenges
|
|
167
|
+
* - Verifying MFA challenges
|
|
168
|
+
*/
|
|
169
|
+
public readonly mfa: MfaApiClient;
|
|
170
|
+
|
|
155
171
|
private worker?: Worker;
|
|
156
172
|
private readonly activeLockKeys: Set<string> = new Set();
|
|
173
|
+
private readonly authJsClient: Auth0AuthJsClient;
|
|
157
174
|
|
|
158
175
|
private readonly defaultOptions: Partial<Auth0ClientOptions> = {
|
|
159
176
|
authorizationParams: {
|
|
@@ -270,6 +287,14 @@ export class Auth0Client {
|
|
|
270
287
|
myAccountApiIdentifier
|
|
271
288
|
);
|
|
272
289
|
|
|
290
|
+
// Initialize auth-js client foundational Oauth feature support
|
|
291
|
+
this.authJsClient = new Auth0AuthJsClient({
|
|
292
|
+
domain: this.options.domain,
|
|
293
|
+
clientId: this.options.clientId,
|
|
294
|
+
});
|
|
295
|
+
this.mfa = new MfaApiClient(this.authJsClient.mfa, this);
|
|
296
|
+
|
|
297
|
+
|
|
273
298
|
// Don't use web workers unless using refresh tokens in memory
|
|
274
299
|
if (
|
|
275
300
|
typeof window !== 'undefined' &&
|
|
@@ -285,9 +310,35 @@ export class Auth0Client {
|
|
|
285
310
|
}
|
|
286
311
|
}
|
|
287
312
|
|
|
313
|
+
/**
|
|
314
|
+
* Returns a readonly copy of the initialization configuration.
|
|
315
|
+
*
|
|
316
|
+
* @returns An object containing domain and clientId
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* const auth0 = new Auth0Client({
|
|
321
|
+
* domain: 'tenant.auth0.com',
|
|
322
|
+
* clientId: 'abc123'
|
|
323
|
+
* });
|
|
324
|
+
*
|
|
325
|
+
* const config = auth0.getConfiguration();
|
|
326
|
+
* // { domain: 'tenant.auth0.com', clientId: 'abc123' }
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
public getConfiguration(): Readonly<ClientConfiguration> {
|
|
330
|
+
return Object.freeze({
|
|
331
|
+
domain: this.options.domain,
|
|
332
|
+
clientId: this.options.clientId
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
288
336
|
private _url(path: string) {
|
|
337
|
+
const auth0ClientObj = this.options.auth0Client || DEFAULT_AUTH0_CLIENT;
|
|
338
|
+
// Strip env from auth0Client for /authorize to prevent query param truncation
|
|
339
|
+
const strippedAuth0Client = stripAuth0Client(auth0ClientObj, true);
|
|
289
340
|
const auth0Client = encodeURIComponent(
|
|
290
|
-
btoa(JSON.stringify(
|
|
341
|
+
btoa(JSON.stringify(strippedAuth0Client))
|
|
291
342
|
);
|
|
292
343
|
return `${this.domainUrl}${path}&auth0Client=${auth0Client}`;
|
|
293
344
|
}
|
|
@@ -1258,6 +1309,14 @@ export class Auth0Client {
|
|
|
1258
1309
|
) {
|
|
1259
1310
|
return await this._getTokenFromIFrame(options);
|
|
1260
1311
|
}
|
|
1312
|
+
if (e instanceof MfaRequiredError) {
|
|
1313
|
+
this.mfa.setMFAAuthDetails(
|
|
1314
|
+
e.mfa_token,
|
|
1315
|
+
options.authorizationParams?.scope,
|
|
1316
|
+
options.authorizationParams?.audience,
|
|
1317
|
+
e.mfa_requirements
|
|
1318
|
+
);
|
|
1319
|
+
}
|
|
1261
1320
|
|
|
1262
1321
|
throw e;
|
|
1263
1322
|
}
|
|
@@ -1396,9 +1455,9 @@ export class Auth0Client {
|
|
|
1396
1455
|
// If so, clear the cache to prevent tokens from multiple users coexisting
|
|
1397
1456
|
if (options.grant_type === 'authorization_code') {
|
|
1398
1457
|
const existingIdToken = await this._getIdTokenFromCache();
|
|
1399
|
-
|
|
1400
|
-
if (existingIdToken?.decodedToken?.claims?.sub &&
|
|
1401
|
-
|
|
1458
|
+
|
|
1459
|
+
if (existingIdToken?.decodedToken?.claims?.sub &&
|
|
1460
|
+
existingIdToken.decodedToken.claims.sub !== decodedToken.claims.sub) {
|
|
1402
1461
|
// Different user detected - clear cached tokens
|
|
1403
1462
|
await this.cacheManager.clear(this.options.clientId);
|
|
1404
1463
|
this.userCache.remove(CACHE_KEY_ID_TOKEN_SUFFIX);
|
|
@@ -1580,6 +1639,7 @@ export class Auth0Client {
|
|
|
1580
1639
|
});
|
|
1581
1640
|
}
|
|
1582
1641
|
|
|
1642
|
+
|
|
1583
1643
|
/**
|
|
1584
1644
|
* Initiates a redirect to connect the user's account with a specified connection.
|
|
1585
1645
|
* This method generates PKCE parameters, creates a transaction, and redirects to the /connect endpoint.
|
|
@@ -1649,6 +1709,29 @@ export class Auth0Client {
|
|
|
1649
1709
|
window.location.assign(url);
|
|
1650
1710
|
}
|
|
1651
1711
|
}
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* @internal
|
|
1715
|
+
* Internal method used by MfaApiClient to exchange MFA tokens for access tokens.
|
|
1716
|
+
* This method should not be called directly by applications.
|
|
1717
|
+
*/
|
|
1718
|
+
async _requestTokenForMfa(
|
|
1719
|
+
options: {
|
|
1720
|
+
grant_type: string;
|
|
1721
|
+
mfaToken: string;
|
|
1722
|
+
scope?: string;
|
|
1723
|
+
audience?: string;
|
|
1724
|
+
otp?: string;
|
|
1725
|
+
binding_code?: string;
|
|
1726
|
+
oob_code?: string;
|
|
1727
|
+
recovery_code?: string;
|
|
1728
|
+
},
|
|
1729
|
+
additionalParameters?: RequestTokenAdditionalParameters
|
|
1730
|
+
): Promise<TokenEndpointResponse> {
|
|
1731
|
+
// Need to add better typing here
|
|
1732
|
+
const { mfaToken, ...restOptions } = options;
|
|
1733
|
+
return this._requestToken({ ...restOptions, mfa_token: mfaToken } as any, additionalParameters);
|
|
1734
|
+
}
|
|
1652
1735
|
}
|
|
1653
1736
|
|
|
1654
1737
|
interface BaseRequestTokenOptions {
|
package/src/dpop/utils.ts
CHANGED
|
@@ -7,7 +7,10 @@ const KEY_PAIR_ALGORITHM: dpopLib.JWSAlgorithm = 'ES256';
|
|
|
7
7
|
const SUPPORTED_GRANT_TYPES = [
|
|
8
8
|
'authorization_code',
|
|
9
9
|
'refresh_token',
|
|
10
|
-
'urn:ietf:params:oauth:grant-type:token-exchange'
|
|
10
|
+
'urn:ietf:params:oauth:grant-type:token-exchange',
|
|
11
|
+
'http://auth0.com/oauth/grant-type/mfa-oob',
|
|
12
|
+
'http://auth0.com/oauth/grant-type/mfa-otp',
|
|
13
|
+
'http://auth0.com/oauth/grant-type/mfa-recovery-code'
|
|
11
14
|
];
|
|
12
15
|
|
|
13
16
|
export type KeyPair = Readonly<dpopLib.KeyPair>;
|
package/src/errors.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MFA requirements from an mfa_required error response
|
|
3
|
+
*/
|
|
4
|
+
export interface MfaRequirements {
|
|
5
|
+
/** Required enrollment types */
|
|
6
|
+
enroll?: Array<{ type: string }>;
|
|
7
|
+
/** Required challenge types */
|
|
8
|
+
challenge?: Array<{ type: string }>;
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* Thrown when network requests to the Auth server fail.
|
|
3
13
|
*/
|
|
@@ -99,7 +109,8 @@ export class MfaRequiredError extends GenericError {
|
|
|
99
109
|
constructor(
|
|
100
110
|
error: string,
|
|
101
111
|
error_description: string,
|
|
102
|
-
public mfa_token: string
|
|
112
|
+
public mfa_token: string,
|
|
113
|
+
public mfa_requirements: MfaRequirements
|
|
103
114
|
) {
|
|
104
115
|
super(error, error_description);
|
|
105
116
|
//https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
package/src/global.ts
CHANGED
|
@@ -296,13 +296,31 @@ export interface Auth0ClientOptions {
|
|
|
296
296
|
*/
|
|
297
297
|
useDpop?: boolean;
|
|
298
298
|
|
|
299
|
+
|
|
299
300
|
/**
|
|
300
301
|
* URL parameters that will be sent back to the Authorization Server. This can be known parameters
|
|
301
302
|
* defined by Auth0 or custom parameters that you define.
|
|
302
|
-
|
|
303
|
+
*/
|
|
303
304
|
authorizationParams?: ClientAuthorizationParams;
|
|
304
305
|
}
|
|
305
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Configuration details exposed by the Auth0Client after initialization.
|
|
309
|
+
*
|
|
310
|
+
* @category Main
|
|
311
|
+
*/
|
|
312
|
+
export interface ClientConfiguration {
|
|
313
|
+
/**
|
|
314
|
+
* The Auth0 domain that was configured
|
|
315
|
+
*/
|
|
316
|
+
domain: string;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* The Auth0 client ID that was configured
|
|
320
|
+
*/
|
|
321
|
+
clientId: string;
|
|
322
|
+
}
|
|
323
|
+
|
|
306
324
|
/**
|
|
307
325
|
* The possible locations where tokens can be stored
|
|
308
326
|
*/
|
|
@@ -818,3 +836,25 @@ export type GetTokenSilentlyVerboseResponse = Omit<
|
|
|
818
836
|
TokenEndpointResponse,
|
|
819
837
|
'refresh_token'
|
|
820
838
|
>;
|
|
839
|
+
|
|
840
|
+
// MFA API types
|
|
841
|
+
export type {
|
|
842
|
+
Authenticator,
|
|
843
|
+
AuthenticatorType,
|
|
844
|
+
OobChannel,
|
|
845
|
+
MfaFactorType,
|
|
846
|
+
EnrollParams,
|
|
847
|
+
EnrollOtpParams,
|
|
848
|
+
EnrollSmsParams,
|
|
849
|
+
EnrollVoiceParams,
|
|
850
|
+
EnrollEmailParams,
|
|
851
|
+
EnrollPushParams,
|
|
852
|
+
EnrollmentResponse,
|
|
853
|
+
OtpEnrollmentResponse,
|
|
854
|
+
OobEnrollmentResponse,
|
|
855
|
+
ChallengeAuthenticatorParams,
|
|
856
|
+
ChallengeResponse,
|
|
857
|
+
VerifyParams,
|
|
858
|
+
MfaGrantType,
|
|
859
|
+
EnrollmentFactor
|
|
860
|
+
} from './mfa/types';
|
package/src/http.ts
CHANGED
|
@@ -188,7 +188,7 @@ export async function getJSON<T>(
|
|
|
188
188
|
error_description || `HTTP error. Unable to fetch ${url}`;
|
|
189
189
|
|
|
190
190
|
if (error === 'mfa_required') {
|
|
191
|
-
throw new MfaRequiredError(error, errorMessage, data.mfa_token);
|
|
191
|
+
throw new MfaRequiredError(error, errorMessage, data.mfa_token, data.mfa_requirements);
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
if (error === 'missing_refresh_token') {
|
package/src/index.ts
CHANGED
|
@@ -35,6 +35,28 @@ export {
|
|
|
35
35
|
UseDpopNonceError
|
|
36
36
|
} from './errors';
|
|
37
37
|
|
|
38
|
+
export {
|
|
39
|
+
MfaError,
|
|
40
|
+
MfaListAuthenticatorsError,
|
|
41
|
+
MfaEnrollmentError,
|
|
42
|
+
MfaChallengeError,
|
|
43
|
+
MfaVerifyError,
|
|
44
|
+
MfaEnrollmentFactorsError
|
|
45
|
+
} from './mfa/errors';
|
|
46
|
+
|
|
47
|
+
export { MfaApiClient } from './mfa';
|
|
48
|
+
|
|
49
|
+
export type {
|
|
50
|
+
MfaFactorType,
|
|
51
|
+
EnrollParams,
|
|
52
|
+
EnrollOtpParams,
|
|
53
|
+
EnrollSmsParams,
|
|
54
|
+
EnrollVoiceParams,
|
|
55
|
+
EnrollEmailParams,
|
|
56
|
+
EnrollPushParams,
|
|
57
|
+
VerifyParams
|
|
58
|
+
} from './mfa';
|
|
59
|
+
|
|
38
60
|
export {
|
|
39
61
|
ICache,
|
|
40
62
|
LocalStorageCache,
|