@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.
Files changed (42) hide show
  1. package/README.md +4 -2
  2. package/dist/auth0-spa-js.development.js +6040 -920
  3. package/dist/auth0-spa-js.development.js.map +1 -1
  4. package/dist/auth0-spa-js.production.esm.js +1 -1
  5. package/dist/auth0-spa-js.production.esm.js.map +1 -1
  6. package/dist/auth0-spa-js.production.js +1 -1
  7. package/dist/auth0-spa-js.production.js.map +1 -1
  8. package/dist/auth0-spa-js.worker.development.js +13 -8
  9. package/dist/auth0-spa-js.worker.development.js.map +1 -1
  10. package/dist/auth0-spa-js.worker.production.js +1 -1
  11. package/dist/auth0-spa-js.worker.production.js.map +1 -1
  12. package/dist/lib/auth0-spa-js.cjs.js +6450 -913
  13. package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
  14. package/dist/typings/Auth0Client.d.ts +51 -1
  15. package/dist/typings/errors.d.ts +15 -1
  16. package/dist/typings/global.d.ts +17 -2
  17. package/dist/typings/index.d.ts +3 -0
  18. package/dist/typings/mfa/MfaApiClient.d.ts +225 -0
  19. package/dist/typings/mfa/MfaContextManager.d.ts +79 -0
  20. package/dist/typings/mfa/constants.d.ts +23 -0
  21. package/dist/typings/mfa/errors.d.ts +117 -0
  22. package/dist/typings/mfa/index.d.ts +4 -0
  23. package/dist/typings/mfa/types.d.ts +181 -0
  24. package/dist/typings/mfa/utils.d.ts +23 -0
  25. package/dist/typings/utils.d.ts +2 -1
  26. package/dist/typings/version.d.ts +1 -1
  27. package/package.json +8 -4
  28. package/src/Auth0Client.ts +88 -5
  29. package/src/dpop/utils.ts +4 -1
  30. package/src/errors.ts +12 -1
  31. package/src/global.ts +41 -1
  32. package/src/http.ts +1 -1
  33. package/src/index.ts +22 -0
  34. package/src/mfa/MfaApiClient.ts +425 -0
  35. package/src/mfa/MfaContextManager.ts +128 -0
  36. package/src/mfa/constants.ts +48 -0
  37. package/src/mfa/errors.ts +154 -0
  38. package/src/mfa/index.ts +24 -0
  39. package/src/mfa/types.ts +209 -0
  40. package/src/mfa/utils.ts +41 -0
  41. package/src/utils.ts +7 -1
  42. package/src/version.ts +1 -1
@@ -0,0 +1,154 @@
1
+ import { MfaApiErrorResponse } from '@auth0/auth0-auth-js';
2
+ import { GenericError } from '../errors';
3
+
4
+ /**
5
+ * Base class for MFA-related errors in auth0-spa-js.
6
+ * Extends GenericError for unified error hierarchy across the SDK.
7
+ */
8
+ export class MfaError extends GenericError {
9
+ constructor(error: string, error_description: string) {
10
+ super(error, error_description);
11
+ //https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
12
+ Object.setPrototypeOf(this, MfaError.prototype);
13
+ }
14
+
15
+ static fromPayload({
16
+ error,
17
+ error_description
18
+ }: {
19
+ error: string;
20
+ error_description: string;
21
+ }) {
22
+ return new MfaError(error, error_description);
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Error thrown when listing MFA authenticators fails.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * try {
32
+ * const authenticators = await mfa.getAuthenticators();
33
+ * } catch (error) {
34
+ * if (error instanceof MfaListAuthenticatorsError) {
35
+ * console.log(error.error); // 'access_denied'
36
+ * console.log(error.error_description); // 'Unauthorized'
37
+ * }
38
+ * }
39
+ * ```
40
+ */
41
+ export class MfaListAuthenticatorsError extends MfaError {
42
+ constructor(error: string, error_description: string) {
43
+ super(error, error_description);
44
+ //https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
45
+ Object.setPrototypeOf(this, MfaListAuthenticatorsError.prototype);
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Error thrown when enrolling an MFA authenticator fails.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * try {
55
+ * const enrollment = await mfa.enroll({
56
+ * authenticator_types: ['otp']
57
+ * });
58
+ * } catch (error) {
59
+ * if (error instanceof MfaEnrollmentError) {
60
+ * console.log(error.error); // 'invalid_phone_number'
61
+ * console.log(error.error_description); // 'Invalid phone number format'
62
+ * }
63
+ * }
64
+ * ```
65
+ */
66
+ export class MfaEnrollmentError extends MfaError {
67
+ constructor(error: string, error_description: string) {
68
+ super(error, error_description);
69
+ //https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
70
+ Object.setPrototypeOf(this, MfaEnrollmentError.prototype);
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Error thrown when initiating an MFA challenge fails.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * try {
80
+ * const challenge = await mfa.challenge({
81
+ * mfaToken: mfaToken,
82
+ * challengeType: 'otp',
83
+ * authenticatorId: 'otp|dev_123'
84
+ * });
85
+ * } catch (error) {
86
+ * if (error instanceof MfaChallengeError) {
87
+ * console.log(error.error); // 'too_many_attempts'
88
+ * console.log(error.error_description); // 'Rate limit exceeded'
89
+ * }
90
+ * }
91
+ * ```
92
+ */
93
+ export class MfaChallengeError extends MfaError {
94
+ constructor(error: string, error_description: string) {
95
+ super(error, error_description);
96
+ //https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
97
+ Object.setPrototypeOf(this, MfaChallengeError.prototype);
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Error thrown when verifying an MFA challenge fails.
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * try {
107
+ * const tokens = await mfa.verify({
108
+ * mfaToken: mfaToken,
109
+ * grant_type: 'http://auth0.com/oauth/grant-type/mfa-otp',
110
+ * otp: '123456'
111
+ * });
112
+ * } catch (error) {
113
+ * if (error instanceof MfaVerifyError) {
114
+ * console.log(error.error); // 'invalid_otp' or 'context_not_found'
115
+ * console.log(error.error_description); // Error details
116
+ * }
117
+ * }
118
+ * ```
119
+ */
120
+ export class MfaVerifyError extends MfaError {
121
+ constructor(error: string, error_description: string) {
122
+ super(error, error_description);
123
+ //https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
124
+ Object.setPrototypeOf(this, MfaVerifyError.prototype);
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Error thrown when getting enrollment factors fails.
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * try {
134
+ * const factors = await mfa.getEnrollmentFactors(mfaToken);
135
+ * } catch (error) {
136
+ * if (error instanceof MfaEnrollmentFactorsError) {
137
+ * console.log(error.error); // 'mfa_context_not_found'
138
+ * console.log(error.error_description); // 'MFA context not found...'
139
+ * }
140
+ * }
141
+ * ```
142
+ */
143
+ export class MfaEnrollmentFactorsError extends MfaError {
144
+ constructor(error: string, error_description: string) {
145
+ super(error, error_description);
146
+ //https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
147
+ Object.setPrototypeOf(this, MfaEnrollmentFactorsError.prototype);
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Re-export MfaApiErrorResponse type for convenience
153
+ */
154
+ export type { MfaApiErrorResponse };
@@ -0,0 +1,24 @@
1
+ export { MfaApiClient } from './MfaApiClient';
2
+ export { MfaContextManager } from './MfaContextManager';
3
+ export type { MfaContext } from './MfaContextManager';
4
+ export type {
5
+ Authenticator,
6
+ AuthenticatorType,
7
+ OobChannel,
8
+ MfaFactorType,
9
+ EnrollBaseParams,
10
+ EnrollParams,
11
+ EnrollOtpParams,
12
+ EnrollSmsParams,
13
+ EnrollVoiceParams,
14
+ EnrollEmailParams,
15
+ EnrollPushParams,
16
+ EnrollmentResponse,
17
+ OtpEnrollmentResponse,
18
+ OobEnrollmentResponse,
19
+ ChallengeAuthenticatorParams,
20
+ ChallengeResponse,
21
+ VerifyParams,
22
+ MfaGrantType,
23
+ EnrollmentFactor
24
+ } from './types';
@@ -0,0 +1,209 @@
1
+ import { MfaGrantTypes } from './constants';
2
+
3
+ /**
4
+ * Represents an MFA authenticator enrolled by a user
5
+ */
6
+ export interface Authenticator {
7
+ /** Unique identifier for the authenticator */
8
+ id: string;
9
+ /** Type of authenticator */
10
+ authenticatorType: AuthenticatorType;
11
+ /** Whether the authenticator is active */
12
+ active: boolean;
13
+ /** Optional friendly name */
14
+ name?: string;
15
+ /** ISO 8601 timestamp when created */
16
+ createdAt?: string;
17
+ /** ISO 8601 timestamp of last authentication */
18
+ lastAuth?: string;
19
+ /** Types of MFA challenges*/
20
+ type?: string;
21
+ }
22
+
23
+ /**
24
+ * Supported authenticator types.
25
+ * Note: Email authenticators use 'oob' type with oobChannel: 'email'
26
+ */
27
+ export type AuthenticatorType = 'otp' | 'oob' | 'recovery-code';
28
+
29
+ /**
30
+ * Types of MFA challenges
31
+ */
32
+ export type ChallengeType = 'otp' | 'phone' | 'recovery-code' | 'email' | 'push-notification' | 'totp';
33
+
34
+ /**
35
+ * Out-of-band delivery channels.
36
+ * Includes 'email' which is also delivered out-of-band.
37
+ */
38
+ export type OobChannel = 'sms' | 'voice' | 'auth0' | 'email';
39
+
40
+ /**
41
+ * Supported MFA factors for enrollment
42
+ */
43
+ export type MfaFactorType = 'otp' | 'sms' | 'email' | 'push' | 'voice';
44
+
45
+ /**
46
+ * Base parameters for all enrollment types
47
+ */
48
+ export interface EnrollBaseParams {
49
+ /** MFA token from mfa_required error */
50
+ mfaToken: string;
51
+ }
52
+
53
+ /**
54
+ * OTP (Time-based One-Time Password) enrollment parameters
55
+ */
56
+ export interface EnrollOtpParams extends EnrollBaseParams {
57
+ /** The factor type for enrollment */
58
+ factorType: 'otp';
59
+ }
60
+
61
+ /**
62
+ * SMS enrollment parameters
63
+ */
64
+ export interface EnrollSmsParams extends EnrollBaseParams {
65
+ /** The factor type for enrollment */
66
+ factorType: 'sms';
67
+ /** Phone number in E.164 format (required for SMS) */
68
+ phoneNumber: string;
69
+ }
70
+
71
+ /**
72
+ * Voice enrollment parameters
73
+ */
74
+ export interface EnrollVoiceParams extends EnrollBaseParams {
75
+ /** The factor type for enrollment */
76
+ factorType: 'voice';
77
+ /** Phone number in E.164 format (required for voice) */
78
+ phoneNumber: string;
79
+ }
80
+
81
+ /**
82
+ * Email enrollment parameters
83
+ */
84
+ export interface EnrollEmailParams extends EnrollBaseParams {
85
+ /** The factor type for enrollment */
86
+ factorType: 'email';
87
+ /** Email address (optional, uses user's email if not provided) */
88
+ email?: string;
89
+ }
90
+
91
+ /**
92
+ * Push notification enrollment parameters
93
+ */
94
+ export interface EnrollPushParams extends EnrollBaseParams {
95
+ /** The factor type for enrollment */
96
+ factorType: 'push';
97
+ }
98
+
99
+ /**
100
+ * Union type for all enrollment parameter types
101
+ */
102
+ export type EnrollParams =
103
+ | EnrollOtpParams
104
+ | EnrollSmsParams
105
+ | EnrollVoiceParams
106
+ | EnrollEmailParams
107
+ | EnrollPushParams;
108
+
109
+ /**
110
+ * Response when enrolling an OTP authenticator
111
+ */
112
+ export interface OtpEnrollmentResponse {
113
+ /** Authenticator type */
114
+ authenticatorType: 'otp';
115
+ /** Base32-encoded secret for TOTP generation */
116
+ secret: string;
117
+ /** URI for generating QR code (otpauth://...) */
118
+ barcodeUri: string;
119
+ /** Recovery codes for account recovery */
120
+ recoveryCodes?: string[];
121
+ /** Authenticator ID */
122
+ id?: string;
123
+ }
124
+
125
+ /**
126
+ * Response when enrolling an OOB authenticator
127
+ */
128
+ export interface OobEnrollmentResponse {
129
+ /** Authenticator type */
130
+ authenticatorType: 'oob';
131
+ /** Delivery channel used */
132
+ oobChannel: OobChannel;
133
+ /** Out-of-band code for verification */
134
+ oobCode?: string;
135
+ /** Binding method (e.g., 'prompt' for user code entry) */
136
+ bindingMethod?: string;
137
+ /** Recovery codes (generated when enrolling first MFA factor) */
138
+ recoveryCodes?: string[];
139
+ /** Authenticator ID */
140
+ id?: string;
141
+ /** URI for QR code (for Push/Guardian enrollment) */
142
+ barcodeUri?: string;
143
+ }
144
+
145
+
146
+ /**
147
+ * Union type for all enrollment response types
148
+ */
149
+ export type EnrollmentResponse =
150
+ | OtpEnrollmentResponse
151
+ | OobEnrollmentResponse
152
+
153
+ /**
154
+ * Parameters for initiating an MFA challenge
155
+ */
156
+ export interface ChallengeAuthenticatorParams {
157
+ /** MFA token from mfa_required error or MFA-scoped access token */
158
+ mfaToken: string;
159
+ /** Type of challenge to initiate */
160
+ challengeType: 'otp' | 'oob';
161
+ /** Specific authenticator to challenge (optional) */
162
+ authenticatorId?: string;
163
+ }
164
+
165
+ /**
166
+ * Response from initiating an MFA challenge
167
+ */
168
+ export interface ChallengeResponse {
169
+ /** Type of challenge created */
170
+ challengeType: 'otp' | 'oob';
171
+ /** Out-of-band code (for OOB challenges) */
172
+ oobCode?: string;
173
+ /** Binding method for OOB (e.g., 'prompt') */
174
+ bindingMethod?: string;
175
+ }
176
+
177
+ /**
178
+ * Grant types for MFA verification (derived from MfaGrantTypes constants)
179
+ */
180
+ export type MfaGrantType = (typeof MfaGrantTypes)[keyof typeof MfaGrantTypes];
181
+
182
+ /**
183
+ * Parameters for verifying an MFA challenge.
184
+ *
185
+ * The grant_type is automatically inferred from which verification field is provided:
186
+ * - `otp` field → MFA-OTP grant type
187
+ * - `oobCode` field → MFA-OOB grant type
188
+ * - `recoveryCode` field → MFA-RECOVERY-CODE grant type
189
+ */
190
+ export interface VerifyParams {
191
+ /** MFA token from challenge flow */
192
+ mfaToken: string;
193
+ /** One-time password (for OTP challenges) */
194
+ otp?: string;
195
+ /** Out-of-band code (for OOB challenges) */
196
+ oobCode?: string;
197
+ /** Binding code (for OOB challenges with binding) */
198
+ bindingCode?: string;
199
+ /** Recovery code (for recovery code verification) */
200
+ recoveryCode?: string;
201
+ }
202
+
203
+ /**
204
+ * Enrollment factor returned by getEnrollmentFactors
205
+ */
206
+ export interface EnrollmentFactor {
207
+ /** Type of enrollment factor available */
208
+ type: string;
209
+ }
@@ -0,0 +1,41 @@
1
+ import { FACTOR_MAPPING, MfaGrantTypes } from './constants';
2
+ import type { EnrollParams, VerifyParams, MfaGrantType } from './types';
3
+
4
+ /**
5
+ * Converts factor-based enrollment params to auth-js format
6
+ *
7
+ * @param params - The enrollment parameters with factorType
8
+ * @returns Parameters in auth-js format with authenticatorTypes/oobChannels
9
+ */
10
+ export function getAuthJsEnrollParams(params: EnrollParams) {
11
+ const mapping = FACTOR_MAPPING[params.factorType];
12
+
13
+ return {
14
+ mfaToken: params.mfaToken,
15
+ authenticatorTypes: mapping.authenticatorTypes,
16
+ ...(mapping.oobChannels && { oobChannels: mapping.oobChannels }),
17
+ ...('phoneNumber' in params && { phoneNumber: params.phoneNumber }),
18
+ ...('email' in params && { email: params.email })
19
+ };
20
+ }
21
+
22
+ /**
23
+ * Gets the grant type from verification parameters based on which field is provided.
24
+ *
25
+ * Priority order: otp > oobCode > recoveryCode
26
+ *
27
+ * @param params - The verification parameters
28
+ * @returns The grant type or undefined if no verification field is present
29
+ */
30
+ export function getGrantType(params: VerifyParams): MfaGrantType | undefined {
31
+ if ('otp' in params && params.otp) {
32
+ return MfaGrantTypes.OTP;
33
+ }
34
+ if ('oobCode' in params && params.oobCode) {
35
+ return MfaGrantTypes.OOB;
36
+ }
37
+ if ('recoveryCode' in params && params.recoveryCode) {
38
+ return MfaGrantTypes.RECOVERY_CODE;
39
+ }
40
+ return undefined;
41
+ }
package/src/utils.ts CHANGED
@@ -184,10 +184,16 @@ const ALLOWED_AUTH0CLIENT_PROPERTIES = [
184
184
  /**
185
185
  * Strips any property that is not present in ALLOWED_AUTH0CLIENT_PROPERTIES
186
186
  * @param auth0Client - The full auth0Client object
187
+ * @param excludeEnv - If true, excludes the 'env' property from the result
187
188
  * @returns The stripped auth0Client object
188
189
  */
189
- export const stripAuth0Client = (auth0Client: any) => {
190
+ export const stripAuth0Client = (auth0Client: any, excludeEnv = false) => {
190
191
  return Object.keys(auth0Client).reduce((acc: any, key: string) => {
192
+ // Exclude 'env' if requested (for /authorize query params to prevent truncation)
193
+ if (excludeEnv && key === 'env') {
194
+ return acc;
195
+ }
196
+
191
197
  const allowedProperty = ALLOWED_AUTH0CLIENT_PROPERTIES.find(
192
198
  p => p.key === key
193
199
  );
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '2.11.3';
1
+ export default '2.13.0';