@auth0/auth0-server-js 1.5.0 → 1.6.1

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.d.cts CHANGED
@@ -1,5 +1,5 @@
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';
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, MissingClientAuthError, OobChannel, OobEnrollmentResponse, OtpEnrollmentResponse, TelemetryConfig, TokenExchangeError, 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.
@@ -488,6 +515,45 @@ declare class ServerClient<TStoreOptions = unknown> {
488
515
  * @returns {URL}
489
516
  */
490
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>;
491
557
  /**
492
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.
493
559
  * @param logoutToken The logout token to verify and use to delete the session from the store.
@@ -674,4 +740,4 @@ declare class IssuerValidationError extends Error {
674
740
  constructor(message: string);
675
741
  }
676
742
 
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 };
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.d.ts CHANGED
@@ -1,5 +1,5 @@
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';
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, MissingClientAuthError, OobChannel, OobEnrollmentResponse, OtpEnrollmentResponse, TelemetryConfig, TokenExchangeError, 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.
@@ -488,6 +515,45 @@ declare class ServerClient<TStoreOptions = unknown> {
488
515
  * @returns {URL}
489
516
  */
490
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>;
491
557
  /**
492
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.
493
559
  * @param logoutToken The logout token to verify and use to delete the session from the store.
@@ -674,4 +740,4 @@ declare class IssuerValidationError extends Error {
674
740
  constructor(message: string);
675
741
  }
676
742
 
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 };
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
@@ -149,7 +149,7 @@ function getTelemetryConfig(config) {
149
149
  return {
150
150
  enabled: true,
151
151
  name: config?.name ?? "@auth0/auth0-server-js",
152
- version: config?.version ?? "1.5.0"
152
+ version: config?.version ?? "1.6.1"
153
153
  };
154
154
  }
155
155
 
@@ -786,6 +786,65 @@ var ServerClient = class {
786
786
  }
787
787
  return authClient.buildLogoutUrl(options);
788
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
+ }
789
848
  /**
790
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.
791
850
  * @param logoutToken The logout token to verify and use to delete the session from the store.
@@ -939,6 +998,9 @@ var AbstractTransactionStore = class extends AbstractStore {
939
998
  }
940
999
  };
941
1000
 
1001
+ // src/index.ts
1002
+ import { TokenExchangeError, MissingClientAuthError } from "@auth0/auth0-auth-js";
1003
+
942
1004
  // src/store/cookie-transaction-store.ts
943
1005
  var CookieTransactionStore = class extends AbstractTransactionStore {
944
1006
  #cookieHandler;
@@ -1152,6 +1214,7 @@ export {
1152
1214
  MfaEnrollmentError,
1153
1215
  MfaListAuthenticatorsError,
1154
1216
  MfaVerifyError,
1217
+ MissingClientAuthError,
1155
1218
  MissingRequiredArgumentError,
1156
1219
  MissingSessionError,
1157
1220
  MissingTransactionError,
@@ -1160,6 +1223,7 @@ export {
1160
1223
  StartLinkUserError,
1161
1224
  StatefulStateStore,
1162
1225
  StatelessStateStore,
1226
+ TokenExchangeError,
1163
1227
  isMfaRequiredError
1164
1228
  };
1165
1229
  //# sourceMappingURL=index.js.map