@auth0/auth0-server-js 1.4.0 → 1.5.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/dist/index.cjs +136 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -4
- package/dist/index.d.ts +93 -4
- package/dist/index.js +135 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthorizationDetails, DiscoveryCacheOptions, TelemetryConfig, AuthClient } from '@auth0/auth0-auth-js';
|
|
2
|
-
export { DiscoveryCacheOptions, TelemetryConfig } from '@auth0/auth0-auth-js';
|
|
1
|
+
import { AuthorizationDetails, DiscoveryCacheOptions, TelemetryConfig, AuthClient, ListAuthenticatorsOptions, AuthenticatorResponse, EnrollAuthenticatorOptions, EnrollmentResponse, ChallengeOptions, ChallengeResponse, MfaVerifyOptions } from '@auth0/auth0-auth-js';
|
|
2
|
+
export { AuthenticatorResponse, AuthenticatorType, ChallengeOptions, ChallengeResponse, DiscoveryCacheOptions, EnrollAuthenticatorOptions, EnrollEmailOptions, EnrollOobOptions, EnrollOtpOptions, EnrollmentResponse, ListAuthenticatorsOptions, MfaChallengeError, MfaEnrollmentError, MfaFactorType, MfaListAuthenticatorsError, MfaRequirements, MfaVerifyError, MfaVerifyOobOptions, MfaVerifyOptions, MfaVerifyOtpOptions, MfaVerifyRecoveryCodeOptions, OobChannel, OobEnrollmentResponse, OtpEnrollmentResponse, TelemetryConfig, isMfaRequiredError } from '@auth0/auth0-auth-js';
|
|
3
3
|
import { JWTPayload } from 'jose';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -252,6 +252,82 @@ interface SessionCookieOptions {
|
|
|
252
252
|
path?: string;
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Response from a successful MFA verification.
|
|
257
|
+
*/
|
|
258
|
+
interface MfaVerifyResponse {
|
|
259
|
+
/** The access token */
|
|
260
|
+
accessToken: string;
|
|
261
|
+
/** The ID token (if openid scope was requested) */
|
|
262
|
+
idToken?: string;
|
|
263
|
+
/** The refresh token (if offline_access scope was requested) */
|
|
264
|
+
refreshToken?: string;
|
|
265
|
+
/** The token type (typically "bearer") */
|
|
266
|
+
tokenType: string;
|
|
267
|
+
/** Unix timestamp (seconds) at which the access token expires */
|
|
268
|
+
expiresAt: number;
|
|
269
|
+
/** The granted scopes */
|
|
270
|
+
scope?: string;
|
|
271
|
+
/** A new recovery code (only returned when verifying with a recovery code) */
|
|
272
|
+
recoveryCode?: string;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* @internal
|
|
276
|
+
* Options for constructing a ServerMfaClient.
|
|
277
|
+
*/
|
|
278
|
+
interface ServerMfaClientOptions<TStoreOptions = unknown> {
|
|
279
|
+
authClient: AuthClient;
|
|
280
|
+
domain: string;
|
|
281
|
+
stateStore: StateStore<TStoreOptions>;
|
|
282
|
+
stateStoreIdentifier: string;
|
|
283
|
+
defaultAudience: string;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
declare class ServerMfaClient<TStoreOptions = unknown> {
|
|
287
|
+
#private;
|
|
288
|
+
/**
|
|
289
|
+
* @internal
|
|
290
|
+
*/
|
|
291
|
+
constructor(options: ServerMfaClientOptions<TStoreOptions>);
|
|
292
|
+
/**
|
|
293
|
+
* Lists all MFA authenticators enrolled by the user.
|
|
294
|
+
*
|
|
295
|
+
* @param options - Options for listing authenticators
|
|
296
|
+
* @returns Promise resolving to an array of enrolled authenticators
|
|
297
|
+
* @throws {MfaListAuthenticatorsError} When the request fails
|
|
298
|
+
*/
|
|
299
|
+
listAuthenticators(options: ListAuthenticatorsOptions): Promise<AuthenticatorResponse[]>;
|
|
300
|
+
/**
|
|
301
|
+
* Enrolls a new MFA authenticator for the user.
|
|
302
|
+
*
|
|
303
|
+
* @param options - Enrollment options
|
|
304
|
+
* @returns Promise resolving to enrollment response with authenticator details
|
|
305
|
+
* @throws {MfaEnrollmentError} When enrollment fails
|
|
306
|
+
*/
|
|
307
|
+
enrollAuthenticator(options: EnrollAuthenticatorOptions): Promise<EnrollmentResponse>;
|
|
308
|
+
/**
|
|
309
|
+
* Initiates an MFA challenge for user verification.
|
|
310
|
+
*
|
|
311
|
+
* @param options - Challenge options
|
|
312
|
+
* @returns Promise resolving to challenge response with challenge details
|
|
313
|
+
* @throws {MfaChallengeError} When the challenge fails
|
|
314
|
+
*/
|
|
315
|
+
challengeAuthenticator(options: ChallengeOptions): Promise<ChallengeResponse>;
|
|
316
|
+
/**
|
|
317
|
+
* Verifies an MFA challenge and completes the authentication flow.
|
|
318
|
+
*
|
|
319
|
+
* Exchanges the MFA token and verification code for access, ID, and refresh tokens,
|
|
320
|
+
* then saves them into the user's session automatically.
|
|
321
|
+
*
|
|
322
|
+
* @param options - The MFA token, factor type (otp / oob / recovery-code), and the code to verify
|
|
323
|
+
* @param storeOptions - Optional options forwarded to the session store. Can be omitted when
|
|
324
|
+
* using the built-in stores; required if your custom store needs extra context (e.g. a request object).
|
|
325
|
+
* @returns The tokens returned by Auth0 after successful verification
|
|
326
|
+
* @throws {MfaVerifyError} When verification fails (e.g. invalid token, wrong code)
|
|
327
|
+
*/
|
|
328
|
+
verify(options: MfaVerifyOptions, storeOptions?: TStoreOptions): Promise<MfaVerifyResponse>;
|
|
329
|
+
}
|
|
330
|
+
|
|
255
331
|
declare class ServerClient<TStoreOptions = unknown> {
|
|
256
332
|
#private;
|
|
257
333
|
/**
|
|
@@ -265,6 +341,19 @@ declare class ServerClient<TStoreOptions = unknown> {
|
|
|
265
341
|
* Important: the methods exposed on the `authClient` instance do not handle any session or state management.
|
|
266
342
|
*/
|
|
267
343
|
get authClient(): AuthClient;
|
|
344
|
+
/**
|
|
345
|
+
* The MFA client for managing multi-factor authentication operations.
|
|
346
|
+
*
|
|
347
|
+
* Provides methods to list, enroll, and challenge MFA authenticators,
|
|
348
|
+
* as well as verify MFA challenges to complete authentication.
|
|
349
|
+
*
|
|
350
|
+
* The `verify` method integrates with the session state store, persisting tokens
|
|
351
|
+
* and user data after successful MFA verification.
|
|
352
|
+
*
|
|
353
|
+
* This property can only be used when `domain` is configured as a static string.
|
|
354
|
+
* In resolver mode (`domain` as a function), MFA is not supported.
|
|
355
|
+
*/
|
|
356
|
+
get mfa(): ServerMfaClient<TStoreOptions>;
|
|
268
357
|
constructor(options: ServerClientOptions<TStoreOptions>);
|
|
269
358
|
/**
|
|
270
359
|
* Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
|
|
@@ -371,7 +460,7 @@ declare class ServerClient<TStoreOptions = unknown> {
|
|
|
371
460
|
* Also updates the store when a new token was retrieved from Auth0.
|
|
372
461
|
* @param storeOptions Optional options used to pass to the Transaction and State Store.
|
|
373
462
|
*
|
|
374
|
-
* @throws {TokenByRefreshTokenError} If the refresh token was not found or there was an issue requesting the access token.
|
|
463
|
+
* @throws {TokenByRefreshTokenError} If the refresh token was not found or there was an issue requesting the access token. When the cause is `mfa_required`, use `isMfaRequiredError(error)` to narrow the error and read `cause.mfa_token`.
|
|
375
464
|
*
|
|
376
465
|
* @returns The Token Set, containing the access token, as well as additional information.
|
|
377
466
|
*/
|
|
@@ -585,4 +674,4 @@ declare class IssuerValidationError extends Error {
|
|
|
585
674
|
constructor(message: string);
|
|
586
675
|
}
|
|
587
676
|
|
|
588
|
-
export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type ConnectionTokenSet, type CookieHandler, type CookieSerializeOptions, CookieTransactionStore, type DomainResolver, type EncryptedStoreOptions, type GetAccessTokenOptions, type InternalStateData, InvalidConfigurationError, IssuerValidationError, type LoginBackchannelOptions, type LoginBackchannelResult, type LogoutOptions, type LogoutTokenClaims, MissingRequiredArgumentError, MissingSessionError, MissingTransactionError, ServerClient, type ServerClientOptions, type SessionConfiguration, type SessionCookieOptions, type SessionData, type SessionStore, type StartInteractiveLoginOptions, StartLinkUserError, type StartLinkUserOptions, type StartUnlinkUserOptions, type StateData, type StateStore, StatefulStateStore, type StatefulStateStoreOptions, StatelessStateStore, type TokenSet, type TransactionData, type TransactionStore, type UserClaims };
|
|
677
|
+
export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type ConnectionTokenSet, type CookieHandler, type CookieSerializeOptions, CookieTransactionStore, type DomainResolver, type EncryptedStoreOptions, type GetAccessTokenOptions, type InternalStateData, InvalidConfigurationError, IssuerValidationError, type LoginBackchannelOptions, type LoginBackchannelResult, type LogoutOptions, type LogoutTokenClaims, type MfaVerifyResponse, MissingRequiredArgumentError, MissingSessionError, MissingTransactionError, ServerClient, type ServerClientOptions, ServerMfaClient, type SessionConfiguration, type SessionCookieOptions, type SessionData, type SessionStore, type StartInteractiveLoginOptions, StartLinkUserError, type StartLinkUserOptions, type StartUnlinkUserOptions, type StateData, type StateStore, StatefulStateStore, type StatefulStateStoreOptions, StatelessStateStore, type TokenSet, type TransactionData, type TransactionStore, type UserClaims };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthorizationDetails, DiscoveryCacheOptions, TelemetryConfig, AuthClient } from '@auth0/auth0-auth-js';
|
|
2
|
-
export { DiscoveryCacheOptions, TelemetryConfig } from '@auth0/auth0-auth-js';
|
|
1
|
+
import { AuthorizationDetails, DiscoveryCacheOptions, TelemetryConfig, AuthClient, ListAuthenticatorsOptions, AuthenticatorResponse, EnrollAuthenticatorOptions, EnrollmentResponse, ChallengeOptions, ChallengeResponse, MfaVerifyOptions } from '@auth0/auth0-auth-js';
|
|
2
|
+
export { AuthenticatorResponse, AuthenticatorType, ChallengeOptions, ChallengeResponse, DiscoveryCacheOptions, EnrollAuthenticatorOptions, EnrollEmailOptions, EnrollOobOptions, EnrollOtpOptions, EnrollmentResponse, ListAuthenticatorsOptions, MfaChallengeError, MfaEnrollmentError, MfaFactorType, MfaListAuthenticatorsError, MfaRequirements, MfaVerifyError, MfaVerifyOobOptions, MfaVerifyOptions, MfaVerifyOtpOptions, MfaVerifyRecoveryCodeOptions, OobChannel, OobEnrollmentResponse, OtpEnrollmentResponse, TelemetryConfig, isMfaRequiredError } from '@auth0/auth0-auth-js';
|
|
3
3
|
import { JWTPayload } from 'jose';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -252,6 +252,82 @@ interface SessionCookieOptions {
|
|
|
252
252
|
path?: string;
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Response from a successful MFA verification.
|
|
257
|
+
*/
|
|
258
|
+
interface MfaVerifyResponse {
|
|
259
|
+
/** The access token */
|
|
260
|
+
accessToken: string;
|
|
261
|
+
/** The ID token (if openid scope was requested) */
|
|
262
|
+
idToken?: string;
|
|
263
|
+
/** The refresh token (if offline_access scope was requested) */
|
|
264
|
+
refreshToken?: string;
|
|
265
|
+
/** The token type (typically "bearer") */
|
|
266
|
+
tokenType: string;
|
|
267
|
+
/** Unix timestamp (seconds) at which the access token expires */
|
|
268
|
+
expiresAt: number;
|
|
269
|
+
/** The granted scopes */
|
|
270
|
+
scope?: string;
|
|
271
|
+
/** A new recovery code (only returned when verifying with a recovery code) */
|
|
272
|
+
recoveryCode?: string;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* @internal
|
|
276
|
+
* Options for constructing a ServerMfaClient.
|
|
277
|
+
*/
|
|
278
|
+
interface ServerMfaClientOptions<TStoreOptions = unknown> {
|
|
279
|
+
authClient: AuthClient;
|
|
280
|
+
domain: string;
|
|
281
|
+
stateStore: StateStore<TStoreOptions>;
|
|
282
|
+
stateStoreIdentifier: string;
|
|
283
|
+
defaultAudience: string;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
declare class ServerMfaClient<TStoreOptions = unknown> {
|
|
287
|
+
#private;
|
|
288
|
+
/**
|
|
289
|
+
* @internal
|
|
290
|
+
*/
|
|
291
|
+
constructor(options: ServerMfaClientOptions<TStoreOptions>);
|
|
292
|
+
/**
|
|
293
|
+
* Lists all MFA authenticators enrolled by the user.
|
|
294
|
+
*
|
|
295
|
+
* @param options - Options for listing authenticators
|
|
296
|
+
* @returns Promise resolving to an array of enrolled authenticators
|
|
297
|
+
* @throws {MfaListAuthenticatorsError} When the request fails
|
|
298
|
+
*/
|
|
299
|
+
listAuthenticators(options: ListAuthenticatorsOptions): Promise<AuthenticatorResponse[]>;
|
|
300
|
+
/**
|
|
301
|
+
* Enrolls a new MFA authenticator for the user.
|
|
302
|
+
*
|
|
303
|
+
* @param options - Enrollment options
|
|
304
|
+
* @returns Promise resolving to enrollment response with authenticator details
|
|
305
|
+
* @throws {MfaEnrollmentError} When enrollment fails
|
|
306
|
+
*/
|
|
307
|
+
enrollAuthenticator(options: EnrollAuthenticatorOptions): Promise<EnrollmentResponse>;
|
|
308
|
+
/**
|
|
309
|
+
* Initiates an MFA challenge for user verification.
|
|
310
|
+
*
|
|
311
|
+
* @param options - Challenge options
|
|
312
|
+
* @returns Promise resolving to challenge response with challenge details
|
|
313
|
+
* @throws {MfaChallengeError} When the challenge fails
|
|
314
|
+
*/
|
|
315
|
+
challengeAuthenticator(options: ChallengeOptions): Promise<ChallengeResponse>;
|
|
316
|
+
/**
|
|
317
|
+
* Verifies an MFA challenge and completes the authentication flow.
|
|
318
|
+
*
|
|
319
|
+
* Exchanges the MFA token and verification code for access, ID, and refresh tokens,
|
|
320
|
+
* then saves them into the user's session automatically.
|
|
321
|
+
*
|
|
322
|
+
* @param options - The MFA token, factor type (otp / oob / recovery-code), and the code to verify
|
|
323
|
+
* @param storeOptions - Optional options forwarded to the session store. Can be omitted when
|
|
324
|
+
* using the built-in stores; required if your custom store needs extra context (e.g. a request object).
|
|
325
|
+
* @returns The tokens returned by Auth0 after successful verification
|
|
326
|
+
* @throws {MfaVerifyError} When verification fails (e.g. invalid token, wrong code)
|
|
327
|
+
*/
|
|
328
|
+
verify(options: MfaVerifyOptions, storeOptions?: TStoreOptions): Promise<MfaVerifyResponse>;
|
|
329
|
+
}
|
|
330
|
+
|
|
255
331
|
declare class ServerClient<TStoreOptions = unknown> {
|
|
256
332
|
#private;
|
|
257
333
|
/**
|
|
@@ -265,6 +341,19 @@ declare class ServerClient<TStoreOptions = unknown> {
|
|
|
265
341
|
* Important: the methods exposed on the `authClient` instance do not handle any session or state management.
|
|
266
342
|
*/
|
|
267
343
|
get authClient(): AuthClient;
|
|
344
|
+
/**
|
|
345
|
+
* The MFA client for managing multi-factor authentication operations.
|
|
346
|
+
*
|
|
347
|
+
* Provides methods to list, enroll, and challenge MFA authenticators,
|
|
348
|
+
* as well as verify MFA challenges to complete authentication.
|
|
349
|
+
*
|
|
350
|
+
* The `verify` method integrates with the session state store, persisting tokens
|
|
351
|
+
* and user data after successful MFA verification.
|
|
352
|
+
*
|
|
353
|
+
* This property can only be used when `domain` is configured as a static string.
|
|
354
|
+
* In resolver mode (`domain` as a function), MFA is not supported.
|
|
355
|
+
*/
|
|
356
|
+
get mfa(): ServerMfaClient<TStoreOptions>;
|
|
268
357
|
constructor(options: ServerClientOptions<TStoreOptions>);
|
|
269
358
|
/**
|
|
270
359
|
* Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
|
|
@@ -371,7 +460,7 @@ declare class ServerClient<TStoreOptions = unknown> {
|
|
|
371
460
|
* Also updates the store when a new token was retrieved from Auth0.
|
|
372
461
|
* @param storeOptions Optional options used to pass to the Transaction and State Store.
|
|
373
462
|
*
|
|
374
|
-
* @throws {TokenByRefreshTokenError} If the refresh token was not found or there was an issue requesting the access token.
|
|
463
|
+
* @throws {TokenByRefreshTokenError} If the refresh token was not found or there was an issue requesting the access token. When the cause is `mfa_required`, use `isMfaRequiredError(error)` to narrow the error and read `cause.mfa_token`.
|
|
375
464
|
*
|
|
376
465
|
* @returns The Token Set, containing the access token, as well as additional information.
|
|
377
466
|
*/
|
|
@@ -585,4 +674,4 @@ declare class IssuerValidationError extends Error {
|
|
|
585
674
|
constructor(message: string);
|
|
586
675
|
}
|
|
587
676
|
|
|
588
|
-
export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type ConnectionTokenSet, type CookieHandler, type CookieSerializeOptions, CookieTransactionStore, type DomainResolver, type EncryptedStoreOptions, type GetAccessTokenOptions, type InternalStateData, InvalidConfigurationError, IssuerValidationError, type LoginBackchannelOptions, type LoginBackchannelResult, type LogoutOptions, type LogoutTokenClaims, MissingRequiredArgumentError, MissingSessionError, MissingTransactionError, ServerClient, type ServerClientOptions, type SessionConfiguration, type SessionCookieOptions, type SessionData, type SessionStore, type StartInteractiveLoginOptions, StartLinkUserError, type StartLinkUserOptions, type StartUnlinkUserOptions, type StateData, type StateStore, StatefulStateStore, type StatefulStateStoreOptions, StatelessStateStore, type TokenSet, type TransactionData, type TransactionStore, type UserClaims };
|
|
677
|
+
export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type ConnectionTokenSet, type CookieHandler, type CookieSerializeOptions, CookieTransactionStore, type DomainResolver, type EncryptedStoreOptions, type GetAccessTokenOptions, type InternalStateData, InvalidConfigurationError, IssuerValidationError, type LoginBackchannelOptions, type LoginBackchannelResult, type LogoutOptions, type LogoutTokenClaims, type MfaVerifyResponse, MissingRequiredArgumentError, MissingSessionError, MissingTransactionError, ServerClient, type ServerClientOptions, ServerMfaClient, type SessionConfiguration, type SessionCookieOptions, type SessionData, type SessionStore, type StartInteractiveLoginOptions, StartLinkUserError, type StartLinkUserOptions, type StartUnlinkUserOptions, type StateData, type StateStore, StatefulStateStore, type StatefulStateStoreOptions, StatelessStateStore, type TokenSet, type TransactionData, type TransactionStore, type UserClaims };
|
package/dist/index.js
CHANGED
|
@@ -57,6 +57,17 @@ var createUpdatedTokenSet = (audience, response) => ({
|
|
|
57
57
|
expiresAt: response.expiresAt
|
|
58
58
|
});
|
|
59
59
|
function updateStateData(audience, stateData, tokenEndpointResponse, context) {
|
|
60
|
+
if (stateData && tokenEndpointResponse.claims) {
|
|
61
|
+
const newSub = tokenEndpointResponse.claims.sub;
|
|
62
|
+
const newIss = tokenEndpointResponse.claims.iss;
|
|
63
|
+
const existingSub = stateData.user?.sub;
|
|
64
|
+
const existingIss = stateData.user?.iss;
|
|
65
|
+
const subMismatch = newSub !== void 0 && existingSub !== void 0 && newSub !== existingSub;
|
|
66
|
+
const issMismatch = newIss !== void 0 && existingIss !== void 0 && newIss !== existingIss;
|
|
67
|
+
if (subMismatch || issMismatch) {
|
|
68
|
+
stateData = void 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
60
71
|
if (stateData) {
|
|
61
72
|
const isNewTokenSet = !stateData.tokenSets.some(
|
|
62
73
|
(tokenSet) => tokenSet.audience === audience && tokenSet.scope === tokenEndpointResponse.scope
|
|
@@ -138,10 +149,90 @@ function getTelemetryConfig(config) {
|
|
|
138
149
|
return {
|
|
139
150
|
enabled: true,
|
|
140
151
|
name: config?.name ?? "@auth0/auth0-server-js",
|
|
141
|
-
version: config?.version ?? "1.
|
|
152
|
+
version: config?.version ?? "1.5.0"
|
|
142
153
|
};
|
|
143
154
|
}
|
|
144
155
|
|
|
156
|
+
// src/mfa/server-mfa-client.ts
|
|
157
|
+
var ServerMfaClient = class {
|
|
158
|
+
#options;
|
|
159
|
+
/**
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
constructor(options) {
|
|
163
|
+
this.#options = options;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Lists all MFA authenticators enrolled by the user.
|
|
167
|
+
*
|
|
168
|
+
* @param options - Options for listing authenticators
|
|
169
|
+
* @returns Promise resolving to an array of enrolled authenticators
|
|
170
|
+
* @throws {MfaListAuthenticatorsError} When the request fails
|
|
171
|
+
*/
|
|
172
|
+
async listAuthenticators(options) {
|
|
173
|
+
return this.#options.authClient.mfa.listAuthenticators(options);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Enrolls a new MFA authenticator for the user.
|
|
177
|
+
*
|
|
178
|
+
* @param options - Enrollment options
|
|
179
|
+
* @returns Promise resolving to enrollment response with authenticator details
|
|
180
|
+
* @throws {MfaEnrollmentError} When enrollment fails
|
|
181
|
+
*/
|
|
182
|
+
async enrollAuthenticator(options) {
|
|
183
|
+
return this.#options.authClient.mfa.enrollAuthenticator(options);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Initiates an MFA challenge for user verification.
|
|
187
|
+
*
|
|
188
|
+
* @param options - Challenge options
|
|
189
|
+
* @returns Promise resolving to challenge response with challenge details
|
|
190
|
+
* @throws {MfaChallengeError} When the challenge fails
|
|
191
|
+
*/
|
|
192
|
+
async challengeAuthenticator(options) {
|
|
193
|
+
return this.#options.authClient.mfa.challengeAuthenticator(options);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Verifies an MFA challenge and completes the authentication flow.
|
|
197
|
+
*
|
|
198
|
+
* Exchanges the MFA token and verification code for access, ID, and refresh tokens,
|
|
199
|
+
* then saves them into the user's session automatically.
|
|
200
|
+
*
|
|
201
|
+
* @param options - The MFA token, factor type (otp / oob / recovery-code), and the code to verify
|
|
202
|
+
* @param storeOptions - Optional options forwarded to the session store. Can be omitted when
|
|
203
|
+
* using the built-in stores; required if your custom store needs extra context (e.g. a request object).
|
|
204
|
+
* @returns The tokens returned by Auth0 after successful verification
|
|
205
|
+
* @throws {MfaVerifyError} When verification fails (e.g. invalid token, wrong code)
|
|
206
|
+
*/
|
|
207
|
+
async verify(options, storeOptions) {
|
|
208
|
+
const tokenResponse = await this.#options.authClient.mfa.verify(options);
|
|
209
|
+
const audience = options.audience ?? this.#options.defaultAudience;
|
|
210
|
+
const existingStateData = await this.#options.stateStore.get(
|
|
211
|
+
this.#options.stateStoreIdentifier,
|
|
212
|
+
storeOptions
|
|
213
|
+
);
|
|
214
|
+
const updatedStateData = updateStateData(audience, existingStateData, tokenResponse, {
|
|
215
|
+
domain: this.#options.domain
|
|
216
|
+
});
|
|
217
|
+
await this.#options.stateStore.set(
|
|
218
|
+
this.#options.stateStoreIdentifier,
|
|
219
|
+
updatedStateData,
|
|
220
|
+
true,
|
|
221
|
+
storeOptions
|
|
222
|
+
);
|
|
223
|
+
const result = {
|
|
224
|
+
accessToken: tokenResponse.accessToken,
|
|
225
|
+
tokenType: tokenResponse.tokenType ?? "bearer",
|
|
226
|
+
expiresAt: tokenResponse.expiresAt,
|
|
227
|
+
scope: tokenResponse.scope
|
|
228
|
+
};
|
|
229
|
+
if (tokenResponse.idToken) result.idToken = tokenResponse.idToken;
|
|
230
|
+
if (tokenResponse.refreshToken) result.refreshToken = tokenResponse.refreshToken;
|
|
231
|
+
if (tokenResponse.recoveryCode) result.recoveryCode = tokenResponse.recoveryCode;
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
145
236
|
// src/server-client.ts
|
|
146
237
|
var DEFAULT_SCOPES = "openid profile email offline_access";
|
|
147
238
|
var normalizeDomain = (value) => {
|
|
@@ -176,6 +267,7 @@ var ServerClient = class {
|
|
|
176
267
|
#authClientOptions;
|
|
177
268
|
#staticDomain;
|
|
178
269
|
#authClient;
|
|
270
|
+
#mfaClient;
|
|
179
271
|
/**
|
|
180
272
|
* The underlying `authClient` instance that can be used to interact with the Auth0 Authentication API.
|
|
181
273
|
* Generally, you should prefer to use the higher-level methods exposed on the `ServerClient` instance.
|
|
@@ -192,6 +284,24 @@ var ServerClient = class {
|
|
|
192
284
|
}
|
|
193
285
|
return this.#authClient;
|
|
194
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* The MFA client for managing multi-factor authentication operations.
|
|
289
|
+
*
|
|
290
|
+
* Provides methods to list, enroll, and challenge MFA authenticators,
|
|
291
|
+
* as well as verify MFA challenges to complete authentication.
|
|
292
|
+
*
|
|
293
|
+
* The `verify` method integrates with the session state store, persisting tokens
|
|
294
|
+
* and user data after successful MFA verification.
|
|
295
|
+
*
|
|
296
|
+
* This property can only be used when `domain` is configured as a static string.
|
|
297
|
+
* In resolver mode (`domain` as a function), MFA is not supported.
|
|
298
|
+
*/
|
|
299
|
+
get mfa() {
|
|
300
|
+
if (!this.#mfaClient) {
|
|
301
|
+
throw new InvalidConfigurationError("mfa is only available when using a static domain configuration.");
|
|
302
|
+
}
|
|
303
|
+
return this.#mfaClient;
|
|
304
|
+
}
|
|
195
305
|
constructor(options) {
|
|
196
306
|
this.#options = options;
|
|
197
307
|
this.#stateStoreIdentifier = this.#options.stateIdentifier || "__a0_session";
|
|
@@ -225,6 +335,13 @@ var ServerClient = class {
|
|
|
225
335
|
...this.#authClientOptions,
|
|
226
336
|
telemetry: getTelemetryConfig(this.#options.telemetry)
|
|
227
337
|
});
|
|
338
|
+
this.#mfaClient = new ServerMfaClient({
|
|
339
|
+
authClient: this.#authClient,
|
|
340
|
+
domain,
|
|
341
|
+
stateStore: this.#stateStore,
|
|
342
|
+
stateStoreIdentifier: this.#stateStoreIdentifier,
|
|
343
|
+
defaultAudience: this.#options.authorizationParams?.audience ?? "default"
|
|
344
|
+
});
|
|
228
345
|
}
|
|
229
346
|
}
|
|
230
347
|
async #resolveDomain(storeOptions) {
|
|
@@ -534,7 +651,7 @@ var ServerClient = class {
|
|
|
534
651
|
* Also updates the store when a new token was retrieved from Auth0.
|
|
535
652
|
* @param storeOptions Optional options used to pass to the Transaction and State Store.
|
|
536
653
|
*
|
|
537
|
-
* @throws {TokenByRefreshTokenError} If the refresh token was not found or there was an issue requesting the access token.
|
|
654
|
+
* @throws {TokenByRefreshTokenError} If the refresh token was not found or there was an issue requesting the access token. When the cause is `mfa_required`, use `isMfaRequiredError(error)` to narrow the error and read `cause.mfa_token`.
|
|
538
655
|
*
|
|
539
656
|
* @returns The Token Set, containing the access token, as well as additional information.
|
|
540
657
|
*/
|
|
@@ -1015,6 +1132,15 @@ var StatelessStateStore = class extends AbstractSessionStore {
|
|
|
1015
1132
|
};
|
|
1016
1133
|
}
|
|
1017
1134
|
};
|
|
1135
|
+
|
|
1136
|
+
// src/mfa/index.ts
|
|
1137
|
+
import {
|
|
1138
|
+
MfaListAuthenticatorsError,
|
|
1139
|
+
MfaEnrollmentError,
|
|
1140
|
+
MfaChallengeError,
|
|
1141
|
+
MfaVerifyError,
|
|
1142
|
+
isMfaRequiredError
|
|
1143
|
+
} from "@auth0/auth0-auth-js";
|
|
1018
1144
|
export {
|
|
1019
1145
|
AbstractStateStore,
|
|
1020
1146
|
AbstractTransactionStore,
|
|
@@ -1022,12 +1148,18 @@ export {
|
|
|
1022
1148
|
CookieTransactionStore,
|
|
1023
1149
|
InvalidConfigurationError,
|
|
1024
1150
|
IssuerValidationError,
|
|
1151
|
+
MfaChallengeError,
|
|
1152
|
+
MfaEnrollmentError,
|
|
1153
|
+
MfaListAuthenticatorsError,
|
|
1154
|
+
MfaVerifyError,
|
|
1025
1155
|
MissingRequiredArgumentError,
|
|
1026
1156
|
MissingSessionError,
|
|
1027
1157
|
MissingTransactionError,
|
|
1028
1158
|
ServerClient,
|
|
1159
|
+
ServerMfaClient,
|
|
1029
1160
|
StartLinkUserError,
|
|
1030
1161
|
StatefulStateStore,
|
|
1031
|
-
StatelessStateStore
|
|
1162
|
+
StatelessStateStore,
|
|
1163
|
+
isMfaRequiredError
|
|
1032
1164
|
};
|
|
1033
1165
|
//# sourceMappingURL=index.js.map
|