@auth0/auth0-server-js 1.4.0 → 1.6.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 +195 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +159 -4
- package/dist/index.d.ts +159 -4
- package/dist/index.js +194 -3
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
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 { ExchangeProfileOptions, AuthorizationDetails, DiscoveryCacheOptions, TelemetryConfig, AuthClient, ListAuthenticatorsOptions, AuthenticatorResponse, EnrollAuthenticatorOptions, EnrollmentResponse, ChallengeOptions, ChallengeResponse, MfaVerifyOptions, TokenResponse } from '@auth0/auth0-auth-js';
|
|
2
|
+
export { ActClaim, 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, TokenResponse, isMfaRequiredError } from '@auth0/auth0-auth-js';
|
|
3
3
|
import { JWTPayload } from 'jose';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -217,6 +217,33 @@ interface SessionStore<TStoreOptions> {
|
|
|
217
217
|
get(identifier: string): Promise<StateData | undefined>;
|
|
218
218
|
deleteByLogoutToken(claims: LogoutTokenClaims, options?: TStoreOptions | undefined): Promise<void>;
|
|
219
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Options for exchanging a custom token and persisting the resulting session (RFC 8693).
|
|
222
|
+
*
|
|
223
|
+
* Mirrors `ExchangeProfileOptions` from `auth0-auth-js`. The `audience` field is
|
|
224
|
+
* also used to key the token set stored in the session.
|
|
225
|
+
*
|
|
226
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc8693 RFC 8693: OAuth 2.0 Token Exchange}
|
|
227
|
+
*/
|
|
228
|
+
type LoginWithCustomTokenExchangeOptions = ExchangeProfileOptions;
|
|
229
|
+
/**
|
|
230
|
+
* Options for performing a custom token exchange without any session side effects (RFC 8693).
|
|
231
|
+
*
|
|
232
|
+
* Use this when you need delegated tokens for downstream service calls but do not want
|
|
233
|
+
* to establish a user session (e.g. impersonation, service-to-service delegation).
|
|
234
|
+
*
|
|
235
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc8693 RFC 8693: OAuth 2.0 Token Exchange}
|
|
236
|
+
*/
|
|
237
|
+
type CustomTokenExchangeOptions = ExchangeProfileOptions;
|
|
238
|
+
/**
|
|
239
|
+
* Result of a successful custom token exchange with session persistence.
|
|
240
|
+
*/
|
|
241
|
+
interface LoginWithCustomTokenExchangeResult {
|
|
242
|
+
/**
|
|
243
|
+
* Authorization details returned by the token endpoint when RAR was used.
|
|
244
|
+
*/
|
|
245
|
+
authorizationDetails?: AuthorizationDetails[];
|
|
246
|
+
}
|
|
220
247
|
interface SessionCookieOptions {
|
|
221
248
|
/**
|
|
222
249
|
* The name of the session cookie.
|
|
@@ -252,6 +279,82 @@ interface SessionCookieOptions {
|
|
|
252
279
|
path?: string;
|
|
253
280
|
}
|
|
254
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Response from a successful MFA verification.
|
|
284
|
+
*/
|
|
285
|
+
interface MfaVerifyResponse {
|
|
286
|
+
/** The access token */
|
|
287
|
+
accessToken: string;
|
|
288
|
+
/** The ID token (if openid scope was requested) */
|
|
289
|
+
idToken?: string;
|
|
290
|
+
/** The refresh token (if offline_access scope was requested) */
|
|
291
|
+
refreshToken?: string;
|
|
292
|
+
/** The token type (typically "bearer") */
|
|
293
|
+
tokenType: string;
|
|
294
|
+
/** Unix timestamp (seconds) at which the access token expires */
|
|
295
|
+
expiresAt: number;
|
|
296
|
+
/** The granted scopes */
|
|
297
|
+
scope?: string;
|
|
298
|
+
/** A new recovery code (only returned when verifying with a recovery code) */
|
|
299
|
+
recoveryCode?: string;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* @internal
|
|
303
|
+
* Options for constructing a ServerMfaClient.
|
|
304
|
+
*/
|
|
305
|
+
interface ServerMfaClientOptions<TStoreOptions = unknown> {
|
|
306
|
+
authClient: AuthClient;
|
|
307
|
+
domain: string;
|
|
308
|
+
stateStore: StateStore<TStoreOptions>;
|
|
309
|
+
stateStoreIdentifier: string;
|
|
310
|
+
defaultAudience: string;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
declare class ServerMfaClient<TStoreOptions = unknown> {
|
|
314
|
+
#private;
|
|
315
|
+
/**
|
|
316
|
+
* @internal
|
|
317
|
+
*/
|
|
318
|
+
constructor(options: ServerMfaClientOptions<TStoreOptions>);
|
|
319
|
+
/**
|
|
320
|
+
* Lists all MFA authenticators enrolled by the user.
|
|
321
|
+
*
|
|
322
|
+
* @param options - Options for listing authenticators
|
|
323
|
+
* @returns Promise resolving to an array of enrolled authenticators
|
|
324
|
+
* @throws {MfaListAuthenticatorsError} When the request fails
|
|
325
|
+
*/
|
|
326
|
+
listAuthenticators(options: ListAuthenticatorsOptions): Promise<AuthenticatorResponse[]>;
|
|
327
|
+
/**
|
|
328
|
+
* Enrolls a new MFA authenticator for the user.
|
|
329
|
+
*
|
|
330
|
+
* @param options - Enrollment options
|
|
331
|
+
* @returns Promise resolving to enrollment response with authenticator details
|
|
332
|
+
* @throws {MfaEnrollmentError} When enrollment fails
|
|
333
|
+
*/
|
|
334
|
+
enrollAuthenticator(options: EnrollAuthenticatorOptions): Promise<EnrollmentResponse>;
|
|
335
|
+
/**
|
|
336
|
+
* Initiates an MFA challenge for user verification.
|
|
337
|
+
*
|
|
338
|
+
* @param options - Challenge options
|
|
339
|
+
* @returns Promise resolving to challenge response with challenge details
|
|
340
|
+
* @throws {MfaChallengeError} When the challenge fails
|
|
341
|
+
*/
|
|
342
|
+
challengeAuthenticator(options: ChallengeOptions): Promise<ChallengeResponse>;
|
|
343
|
+
/**
|
|
344
|
+
* Verifies an MFA challenge and completes the authentication flow.
|
|
345
|
+
*
|
|
346
|
+
* Exchanges the MFA token and verification code for access, ID, and refresh tokens,
|
|
347
|
+
* then saves them into the user's session automatically.
|
|
348
|
+
*
|
|
349
|
+
* @param options - The MFA token, factor type (otp / oob / recovery-code), and the code to verify
|
|
350
|
+
* @param storeOptions - Optional options forwarded to the session store. Can be omitted when
|
|
351
|
+
* using the built-in stores; required if your custom store needs extra context (e.g. a request object).
|
|
352
|
+
* @returns The tokens returned by Auth0 after successful verification
|
|
353
|
+
* @throws {MfaVerifyError} When verification fails (e.g. invalid token, wrong code)
|
|
354
|
+
*/
|
|
355
|
+
verify(options: MfaVerifyOptions, storeOptions?: TStoreOptions): Promise<MfaVerifyResponse>;
|
|
356
|
+
}
|
|
357
|
+
|
|
255
358
|
declare class ServerClient<TStoreOptions = unknown> {
|
|
256
359
|
#private;
|
|
257
360
|
/**
|
|
@@ -265,6 +368,19 @@ declare class ServerClient<TStoreOptions = unknown> {
|
|
|
265
368
|
* Important: the methods exposed on the `authClient` instance do not handle any session or state management.
|
|
266
369
|
*/
|
|
267
370
|
get authClient(): AuthClient;
|
|
371
|
+
/**
|
|
372
|
+
* The MFA client for managing multi-factor authentication operations.
|
|
373
|
+
*
|
|
374
|
+
* Provides methods to list, enroll, and challenge MFA authenticators,
|
|
375
|
+
* as well as verify MFA challenges to complete authentication.
|
|
376
|
+
*
|
|
377
|
+
* The `verify` method integrates with the session state store, persisting tokens
|
|
378
|
+
* and user data after successful MFA verification.
|
|
379
|
+
*
|
|
380
|
+
* This property can only be used when `domain` is configured as a static string.
|
|
381
|
+
* In resolver mode (`domain` as a function), MFA is not supported.
|
|
382
|
+
*/
|
|
383
|
+
get mfa(): ServerMfaClient<TStoreOptions>;
|
|
268
384
|
constructor(options: ServerClientOptions<TStoreOptions>);
|
|
269
385
|
/**
|
|
270
386
|
* Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
|
|
@@ -371,7 +487,7 @@ declare class ServerClient<TStoreOptions = unknown> {
|
|
|
371
487
|
* Also updates the store when a new token was retrieved from Auth0.
|
|
372
488
|
* @param storeOptions Optional options used to pass to the Transaction and State Store.
|
|
373
489
|
*
|
|
374
|
-
* @throws {TokenByRefreshTokenError} If the refresh token was not found or there was an issue requesting the access token.
|
|
490
|
+
* @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
491
|
*
|
|
376
492
|
* @returns The Token Set, containing the access token, as well as additional information.
|
|
377
493
|
*/
|
|
@@ -399,6 +515,45 @@ declare class ServerClient<TStoreOptions = unknown> {
|
|
|
399
515
|
* @returns {URL}
|
|
400
516
|
*/
|
|
401
517
|
logout(options: LogoutOptions, storeOptions?: TStoreOptions): Promise<URL>;
|
|
518
|
+
/**
|
|
519
|
+
* Exchanges a custom token for Auth0 tokens and persists the resulting session (RFC 8693).
|
|
520
|
+
*
|
|
521
|
+
* Calls the token endpoint using the RFC 8693 Token Exchange grant, then stores the
|
|
522
|
+
* resulting tokens in the StateStore — effectively logging the user in without an
|
|
523
|
+
* interactive browser flow. Use this when the caller already holds a trusted external
|
|
524
|
+
* token (e.g. a Google ID token, a legacy system token) and wants to establish an
|
|
525
|
+
* Auth0 session from it.
|
|
526
|
+
*
|
|
527
|
+
* Requires a Token Exchange Profile configured in your Auth0 tenant.
|
|
528
|
+
*
|
|
529
|
+
* @param options Options for the custom token exchange, including the subject token and its type.
|
|
530
|
+
* @param storeOptions Optional options passed to the StateStore.
|
|
531
|
+
*
|
|
532
|
+
* @throws {TokenExchangeError} If the exchange fails or the subject token is invalid.
|
|
533
|
+
* @throws {MissingClientAuthError} If client credentials are not configured.
|
|
534
|
+
*
|
|
535
|
+
* @returns A promise resolving to an object containing `authorizationDetails` when RAR was used.
|
|
536
|
+
*/
|
|
537
|
+
loginWithCustomTokenExchange(options: LoginWithCustomTokenExchangeOptions, storeOptions?: TStoreOptions): Promise<LoginWithCustomTokenExchangeResult>;
|
|
538
|
+
/**
|
|
539
|
+
* Exchanges a custom token for Auth0 tokens without establishing a session (RFC 8693).
|
|
540
|
+
*
|
|
541
|
+
* Performs the same RFC 8693 Token Exchange as `loginWithCustomTokenExchange` but
|
|
542
|
+
* returns the raw token response without writing anything to the StateStore. Use this
|
|
543
|
+
* for delegation or impersonation flows where you need downstream tokens but do not
|
|
544
|
+
* want to create or modify the current user session.
|
|
545
|
+
*
|
|
546
|
+
* Requires a Token Exchange Profile configured in your Auth0 tenant.
|
|
547
|
+
*
|
|
548
|
+
* @param options Options for the custom token exchange, including the subject token and its type.
|
|
549
|
+
* @param storeOptions Optional options passed to the StateStore (used only for domain resolution in resolver mode).
|
|
550
|
+
*
|
|
551
|
+
* @throws {TokenExchangeError} If the exchange fails or the subject token is invalid.
|
|
552
|
+
* @throws {MissingClientAuthError} If client credentials are not configured.
|
|
553
|
+
*
|
|
554
|
+
* @returns A promise resolving to the token response from Auth0.
|
|
555
|
+
*/
|
|
556
|
+
customTokenExchange(options: CustomTokenExchangeOptions, storeOptions?: TStoreOptions): Promise<TokenResponse>;
|
|
402
557
|
/**
|
|
403
558
|
* Handles the backchannel logout process by verifying the logout token and deleting the session from the store if the logout token was considered valid.
|
|
404
559
|
* @param logoutToken The logout token to verify and use to delete the session from the store.
|
|
@@ -585,4 +740,4 @@ declare class IssuerValidationError extends Error {
|
|
|
585
740
|
constructor(message: string);
|
|
586
741
|
}
|
|
587
742
|
|
|
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 };
|
|
743
|
+
export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type ConnectionTokenSet, type CookieHandler, type CookieSerializeOptions, CookieTransactionStore, type CustomTokenExchangeOptions, type DomainResolver, type EncryptedStoreOptions, type GetAccessTokenOptions, type InternalStateData, InvalidConfigurationError, IssuerValidationError, type LoginBackchannelOptions, type LoginBackchannelResult, type LoginWithCustomTokenExchangeOptions, type LoginWithCustomTokenExchangeResult, 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.6.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
|
*/
|
|
@@ -669,6 +786,65 @@ var ServerClient = class {
|
|
|
669
786
|
}
|
|
670
787
|
return authClient.buildLogoutUrl(options);
|
|
671
788
|
}
|
|
789
|
+
/**
|
|
790
|
+
* Exchanges a custom token for Auth0 tokens and persists the resulting session (RFC 8693).
|
|
791
|
+
*
|
|
792
|
+
* Calls the token endpoint using the RFC 8693 Token Exchange grant, then stores the
|
|
793
|
+
* resulting tokens in the StateStore — effectively logging the user in without an
|
|
794
|
+
* interactive browser flow. Use this when the caller already holds a trusted external
|
|
795
|
+
* token (e.g. a Google ID token, a legacy system token) and wants to establish an
|
|
796
|
+
* Auth0 session from it.
|
|
797
|
+
*
|
|
798
|
+
* Requires a Token Exchange Profile configured in your Auth0 tenant.
|
|
799
|
+
*
|
|
800
|
+
* @param options Options for the custom token exchange, including the subject token and its type.
|
|
801
|
+
* @param storeOptions Optional options passed to the StateStore.
|
|
802
|
+
*
|
|
803
|
+
* @throws {TokenExchangeError} If the exchange fails or the subject token is invalid.
|
|
804
|
+
* @throws {MissingClientAuthError} If client credentials are not configured.
|
|
805
|
+
*
|
|
806
|
+
* @returns A promise resolving to an object containing `authorizationDetails` when RAR was used.
|
|
807
|
+
*/
|
|
808
|
+
async loginWithCustomTokenExchange(options, storeOptions) {
|
|
809
|
+
const domain = await this.#resolveDomain(storeOptions);
|
|
810
|
+
const authClient = this.#getAuthClient(domain);
|
|
811
|
+
const tokenEndpointResponse = await authClient.exchangeToken({
|
|
812
|
+
...options,
|
|
813
|
+
scope: ensureOpenIdScope(options.scope)
|
|
814
|
+
});
|
|
815
|
+
const existingStateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);
|
|
816
|
+
const stateData = updateStateData(
|
|
817
|
+
this.#options.authorizationParams?.audience ?? "default",
|
|
818
|
+
existingStateData,
|
|
819
|
+
tokenEndpointResponse,
|
|
820
|
+
{ domain }
|
|
821
|
+
);
|
|
822
|
+
await this.#stateStore.set(this.#stateStoreIdentifier, stateData, true, storeOptions);
|
|
823
|
+
return { authorizationDetails: tokenEndpointResponse.authorizationDetails };
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Exchanges a custom token for Auth0 tokens without establishing a session (RFC 8693).
|
|
827
|
+
*
|
|
828
|
+
* Performs the same RFC 8693 Token Exchange as `loginWithCustomTokenExchange` but
|
|
829
|
+
* returns the raw token response without writing anything to the StateStore. Use this
|
|
830
|
+
* for delegation or impersonation flows where you need downstream tokens but do not
|
|
831
|
+
* want to create or modify the current user session.
|
|
832
|
+
*
|
|
833
|
+
* Requires a Token Exchange Profile configured in your Auth0 tenant.
|
|
834
|
+
*
|
|
835
|
+
* @param options Options for the custom token exchange, including the subject token and its type.
|
|
836
|
+
* @param storeOptions Optional options passed to the StateStore (used only for domain resolution in resolver mode).
|
|
837
|
+
*
|
|
838
|
+
* @throws {TokenExchangeError} If the exchange fails or the subject token is invalid.
|
|
839
|
+
* @throws {MissingClientAuthError} If client credentials are not configured.
|
|
840
|
+
*
|
|
841
|
+
* @returns A promise resolving to the token response from Auth0.
|
|
842
|
+
*/
|
|
843
|
+
async customTokenExchange(options, storeOptions) {
|
|
844
|
+
const domain = await this.#resolveDomain(storeOptions);
|
|
845
|
+
const authClient = this.#getAuthClient(domain);
|
|
846
|
+
return authClient.exchangeToken(options);
|
|
847
|
+
}
|
|
672
848
|
/**
|
|
673
849
|
* Handles the backchannel logout process by verifying the logout token and deleting the session from the store if the logout token was considered valid.
|
|
674
850
|
* @param logoutToken The logout token to verify and use to delete the session from the store.
|
|
@@ -1015,6 +1191,15 @@ var StatelessStateStore = class extends AbstractSessionStore {
|
|
|
1015
1191
|
};
|
|
1016
1192
|
}
|
|
1017
1193
|
};
|
|
1194
|
+
|
|
1195
|
+
// src/mfa/index.ts
|
|
1196
|
+
import {
|
|
1197
|
+
MfaListAuthenticatorsError,
|
|
1198
|
+
MfaEnrollmentError,
|
|
1199
|
+
MfaChallengeError,
|
|
1200
|
+
MfaVerifyError,
|
|
1201
|
+
isMfaRequiredError
|
|
1202
|
+
} from "@auth0/auth0-auth-js";
|
|
1018
1203
|
export {
|
|
1019
1204
|
AbstractStateStore,
|
|
1020
1205
|
AbstractTransactionStore,
|
|
@@ -1022,12 +1207,18 @@ export {
|
|
|
1022
1207
|
CookieTransactionStore,
|
|
1023
1208
|
InvalidConfigurationError,
|
|
1024
1209
|
IssuerValidationError,
|
|
1210
|
+
MfaChallengeError,
|
|
1211
|
+
MfaEnrollmentError,
|
|
1212
|
+
MfaListAuthenticatorsError,
|
|
1213
|
+
MfaVerifyError,
|
|
1025
1214
|
MissingRequiredArgumentError,
|
|
1026
1215
|
MissingSessionError,
|
|
1027
1216
|
MissingTransactionError,
|
|
1028
1217
|
ServerClient,
|
|
1218
|
+
ServerMfaClient,
|
|
1029
1219
|
StartLinkUserError,
|
|
1030
1220
|
StatefulStateStore,
|
|
1031
|
-
StatelessStateStore
|
|
1221
|
+
StatelessStateStore,
|
|
1222
|
+
isMfaRequiredError
|
|
1032
1223
|
};
|
|
1033
1224
|
//# sourceMappingURL=index.js.map
|