@auth0/auth0-server-js 1.13.0 → 1.15.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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ActClaim, AuthorizationDetails, ExchangeProfileOptions, DiscoveryCacheOptions, TelemetryConfig, AuthClient, ListAuthenticatorsOptions, RequestOptions, AuthenticatorResponse, EnrollAuthenticatorOptions, EnrollmentResponse, ChallengeOptions, ChallengeResponse, MfaVerifyOptions, PasskeySignupChallengeOptions, PasskeySignupChallengeResponse, PasskeyLoginChallengeOptions, PasskeyLoginChallengeResponse, GetTokenByPasskeyOptions, SignUpOptions, SignUpResult, ChangePasswordOptions, ApiResponse, GetUserInfoOptions, UserInfoResponse, TokenResponse } from '@auth0/auth0-auth-js';
2
- export { ActClaim, ApiResponse, AuthenticatorResponse, AuthenticatorType, ChallengeOptions, ChallengeResponse, ChangePasswordError, ChangePasswordOptions, DiscoveryCacheOptions, EnrollAuthenticatorOptions, EnrollEmailOptions, EnrollOobOptions, EnrollOtpOptions, EnrollmentResponse, FullResponseOption, GetUserInfoOptions, ListAuthenticatorsOptions, MfaChallengeError, MfaEnrollmentError, MfaFactorType, MfaListAuthenticatorsError, MfaRequirements, MfaVerifyError, MfaVerifyOobOptions, MfaVerifyOptions, MfaVerifyOtpOptions, MfaVerifyRecoveryCodeOptions, MissingClientAuthError, OobChannel, OobEnrollmentResponse, OrganizationValidationError, OtpEnrollmentResponse, PasskeyChallengeError, PasskeyLoginChallengeOptions as PasskeyChallengeOptions, PasskeyLoginChallengeResponse as PasskeyChallengeResponse, PasskeyCreationOptions, PasskeyCredentialResponse, PasskeyGetTokenError, GetTokenByPasskeyOptions as PasskeyGetTokenOptions, PasskeyRegisterError, PasskeySignupChallengeOptions as PasskeyRegisterOptions, PasskeySignupChallengeResponse as PasskeyRegisterResponse, PasskeyRequestOptions, PasswordlessStartError, PasswordlessVerifyError, RequestOptions, SignUpError, SignUpOptions, SignUpResult, TelemetryConfig, TokenExchangeError, TokenResponse, TokenRevocationError, UserInfoError, UserInfoResponse, isMfaRequiredError } from '@auth0/auth0-auth-js';
2
+ export { ActClaim, ApiResponse, AuthenticatorResponse, AuthenticatorType, ChallengeOptions, ChallengeResponse, ChangePasswordError, ChangePasswordOptions, DiscoveryCacheOptions, EnrollAuthenticatorOptions, EnrollEmailOptions, EnrollOobOptions, EnrollOtpOptions, EnrollmentResponse, EnterpriseConnectNotSupportedError, FullResponseOption, GetUserInfoOptions, IsFederatedDomainOptions, ListAuthenticatorsOptions, MfaChallengeError, MfaEnrollmentError, MfaFactorType, MfaListAuthenticatorsError, MfaRequirements, MfaVerifyError, MfaVerifyOobOptions, MfaVerifyOptions, MfaVerifyOtpOptions, MfaVerifyRecoveryCodeOptions, MissingClientAuthError, OobChannel, OobEnrollmentResponse, OrganizationValidationError, OtpEnrollmentResponse, PasskeyChallengeError, PasskeyLoginChallengeOptions as PasskeyChallengeOptions, PasskeyLoginChallengeResponse as PasskeyChallengeResponse, PasskeyCreationOptions, PasskeyCredentialResponse, PasskeyGetTokenError, GetTokenByPasskeyOptions as PasskeyGetTokenOptions, PasskeyRegisterError, PasskeySignupChallengeOptions as PasskeyRegisterOptions, PasskeySignupChallengeResponse as PasskeyRegisterResponse, PasskeyRequestOptions, PasswordlessStartError, PasswordlessVerifyError, RequestOptions, SignUpError, SignUpOptions, SignUpResult, TelemetryConfig, TokenExchangeError, TokenResponse, TokenRevocationError, UserInfoError, UserInfoResponse, isFederatedDomain, isMfaRequiredError } from '@auth0/auth0-auth-js';
3
3
  import { JWTPayload } from 'jose';
4
4
 
5
5
  /**
@@ -40,7 +40,11 @@ interface ServerClientOptions<TStoreOptions = unknown> {
40
40
  */
41
41
  customFetch?: typeof fetch;
42
42
  transactionStore: TransactionStore<TStoreOptions>;
43
- stateStore: StateStore<TStoreOptions>;
43
+ /**
44
+ * The state store for persisting session state. Required for non-Enterprise Connect mode.
45
+ * When `enterpriseConnect: true`, the state store is not needed (Auth0 does not manage a session).
46
+ */
47
+ stateStore?: StateStore<TStoreOptions>;
44
48
  /**
45
49
  * Indicates whether the SDK should use the mTLS endpoints if they are available.
46
50
  *
@@ -52,6 +56,15 @@ interface ServerClientOptions<TStoreOptions = unknown> {
52
56
  * Telemetry is enabled by default and sends the Auth0-Client header with package name and version.
53
57
  */
54
58
  telemetry?: TelemetryConfig;
59
+ /**
60
+ * Set to true when using Enterprise Connect.
61
+ *
62
+ * Auth0 acts as a pure SSO relay — it authenticates the user via the enterprise
63
+ * IdP and hands back an ID token, but holds no session and issues no refresh
64
+ * tokens. Any method that depends on an Auth0-managed session or refresh token
65
+ * throws a clear error instead of returning null silently.
66
+ */
67
+ enterpriseConnect?: true;
55
68
  }
56
69
  interface UserClaims {
57
70
  sub: string;
@@ -82,6 +95,28 @@ interface AuthorizationParameters {
82
95
  * this is supported for backwards compatibility.
83
96
  */
84
97
  organization?: string;
98
+ /**
99
+ * Selects the Experiment Center experiment to override for this authorization
100
+ * request, bypassing the server-side deterministic assignment. Use together
101
+ * with `variation_id` to force a specific variant.
102
+ *
103
+ * Pass per-call via `startInteractiveLogin` rather than at client construction
104
+ * time, so the override does not apply to every login.
105
+ */
106
+ experiment_id?: string;
107
+ /**
108
+ * The variation to assign the user to within the experiment identified by
109
+ * `experiment_id`. The override applies to this request only — the next login
110
+ * without these params reverts to normal server-side assignment.
111
+ * Requires `experiment_id`.
112
+ */
113
+ variation_id?: string;
114
+ /**
115
+ * Scopes the experiment override to a specific segment for this authorization
116
+ * request. Requires `experiment_id`. Only needed when the experiment uses
117
+ * segment targeting.
118
+ */
119
+ segment_id?: string;
85
120
  [key: string]: unknown;
86
121
  }
87
122
  interface TokenSet {
@@ -345,6 +380,22 @@ interface RevokeRefreshTokenOptions {
345
380
  }
346
381
  interface LogoutOptions {
347
382
  returnTo: string;
383
+ /**
384
+ * When true, terminates the upstream identity provider session via federated logout.
385
+ * Required for Enterprise Connect to end the enterprise IdP session.
386
+ */
387
+ federated?: boolean;
388
+ }
389
+ interface StartEnterpriseLoginOptions {
390
+ /**
391
+ * The user's email address. The domain part is used for WebFinger discovery
392
+ * and the full email is forwarded as `login_hint` to Auth0's /authorize.
393
+ */
394
+ email: string;
395
+ /**
396
+ * The URL to redirect to after login completes.
397
+ */
398
+ returnTo?: string;
348
399
  }
349
400
  interface StartLinkUserOptions<TAppState = unknown> {
350
401
  connection: string;
@@ -852,6 +903,16 @@ declare class ServerClient<TStoreOptions = unknown> {
852
903
  */
853
904
  get database(): ServerDatabaseClient<TStoreOptions>;
854
905
  constructor(options: ServerClientOptions<TStoreOptions>);
906
+ /**
907
+ * Starts the Enterprise Connect login flow. Performs WebFinger domain discovery
908
+ * and, if the email domain is federated, initiates an interactive login with `login_hint`.
909
+ *
910
+ * @param options Options including the user's email and optional returnTo URL.
911
+ * @param storeOptions Optional options passed to the Transaction Store.
912
+ *
913
+ * @returns A URL to redirect to (federated domain) or null (not federated / invalid email).
914
+ */
915
+ startEnterpriseLogin(options: StartEnterpriseLoginOptions, storeOptions?: TStoreOptions): Promise<URL | null>;
855
916
  /**
856
917
  * Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
857
918
  *
@@ -882,6 +943,7 @@ declare class ServerClient<TStoreOptions = unknown> {
882
943
  * @throws {SessionExpiredError} When the ID token's `session_expiry` is already in the past at login (the session is born expired); nothing is persisted.
883
944
  *
884
945
  * @returns A promise resolving to an object, containing the original appState (if present) and the authorizationDetails (when RAR was used).
946
+ * In Enterprise Connect mode, also includes `idTokenClaims` and `user`.
885
947
  *
886
948
  * @remarks
887
949
  * This method does not support the `fullResponse` opt-in in v1. It accepts
@@ -893,6 +955,8 @@ declare class ServerClient<TStoreOptions = unknown> {
893
955
  completeInteractiveLogin<TAppState = unknown>(url: URL, storeOptions?: TStoreOptions, requestOptions?: RequestOptions): Promise<{
894
956
  appState?: TAppState;
895
957
  authorizationDetails?: AuthorizationDetails[];
958
+ idTokenClaims?: Record<string, unknown>;
959
+ user?: UserClaims;
896
960
  }>;
897
961
  /**
898
962
  * Starts the user linking process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
@@ -1481,4 +1545,4 @@ declare class SessionExpiredError extends Error {
1481
1545
  constructor(message?: string);
1482
1546
  }
1483
1547
 
1484
- export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type BuildSessionTransferRedirectOptions, type CompletePasswordlessEmailOptions, type CompletePasswordlessOptions, type CompletePasswordlessResult, type CompletePasswordlessSmsOptions, 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, type PasskeyGetTokenResult, type RequestSessionTransferTokenOptions, type RevokeRefreshTokenOptions, ServerClient, type ServerClientOptions, ServerDatabaseClient, ServerMfaClient, ServerPasskeyClient, type SessionConfiguration, type SessionCookieOptions, type SessionData, SessionExpiredError, type SessionStore, type SessionTransferActor, type SessionTransferTokenResult, type StartInteractiveLoginOptions, StartLinkUserError, type StartLinkUserOptions, type StartPasswordlessEmailCodeOptions, type StartPasswordlessEmailLinkOptions, type StartPasswordlessOptions, type StartPasswordlessSmsOptions, type StartUnlinkUserOptions, type StateData, type StateStore, StatefulStateStore, type StatefulStateStoreOptions, StatelessStateStore, TokenExchangeErrorCode, type TokenSet, type TransactionData, type TransactionStore, type UserClaims };
1548
+ export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type BuildSessionTransferRedirectOptions, type CompletePasswordlessEmailOptions, type CompletePasswordlessOptions, type CompletePasswordlessResult, type CompletePasswordlessSmsOptions, 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, type PasskeyGetTokenResult, type RequestSessionTransferTokenOptions, type RevokeRefreshTokenOptions, ServerClient, type ServerClientOptions, ServerDatabaseClient, ServerMfaClient, ServerPasskeyClient, type SessionConfiguration, type SessionCookieOptions, type SessionData, SessionExpiredError, type SessionStore, type SessionTransferActor, type SessionTransferTokenResult, type StartEnterpriseLoginOptions, type StartInteractiveLoginOptions, StartLinkUserError, type StartLinkUserOptions, type StartPasswordlessEmailCodeOptions, type StartPasswordlessEmailLinkOptions, type StartPasswordlessOptions, type StartPasswordlessSmsOptions, type StartUnlinkUserOptions, type StateData, type StateStore, StatefulStateStore, type StatefulStateStoreOptions, StatelessStateStore, TokenExchangeErrorCode, type TokenSet, type TransactionData, type TransactionStore, type UserClaims };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ActClaim, AuthorizationDetails, ExchangeProfileOptions, DiscoveryCacheOptions, TelemetryConfig, AuthClient, ListAuthenticatorsOptions, RequestOptions, AuthenticatorResponse, EnrollAuthenticatorOptions, EnrollmentResponse, ChallengeOptions, ChallengeResponse, MfaVerifyOptions, PasskeySignupChallengeOptions, PasskeySignupChallengeResponse, PasskeyLoginChallengeOptions, PasskeyLoginChallengeResponse, GetTokenByPasskeyOptions, SignUpOptions, SignUpResult, ChangePasswordOptions, ApiResponse, GetUserInfoOptions, UserInfoResponse, TokenResponse } from '@auth0/auth0-auth-js';
2
- export { ActClaim, ApiResponse, AuthenticatorResponse, AuthenticatorType, ChallengeOptions, ChallengeResponse, ChangePasswordError, ChangePasswordOptions, DiscoveryCacheOptions, EnrollAuthenticatorOptions, EnrollEmailOptions, EnrollOobOptions, EnrollOtpOptions, EnrollmentResponse, FullResponseOption, GetUserInfoOptions, ListAuthenticatorsOptions, MfaChallengeError, MfaEnrollmentError, MfaFactorType, MfaListAuthenticatorsError, MfaRequirements, MfaVerifyError, MfaVerifyOobOptions, MfaVerifyOptions, MfaVerifyOtpOptions, MfaVerifyRecoveryCodeOptions, MissingClientAuthError, OobChannel, OobEnrollmentResponse, OrganizationValidationError, OtpEnrollmentResponse, PasskeyChallengeError, PasskeyLoginChallengeOptions as PasskeyChallengeOptions, PasskeyLoginChallengeResponse as PasskeyChallengeResponse, PasskeyCreationOptions, PasskeyCredentialResponse, PasskeyGetTokenError, GetTokenByPasskeyOptions as PasskeyGetTokenOptions, PasskeyRegisterError, PasskeySignupChallengeOptions as PasskeyRegisterOptions, PasskeySignupChallengeResponse as PasskeyRegisterResponse, PasskeyRequestOptions, PasswordlessStartError, PasswordlessVerifyError, RequestOptions, SignUpError, SignUpOptions, SignUpResult, TelemetryConfig, TokenExchangeError, TokenResponse, TokenRevocationError, UserInfoError, UserInfoResponse, isMfaRequiredError } from '@auth0/auth0-auth-js';
2
+ export { ActClaim, ApiResponse, AuthenticatorResponse, AuthenticatorType, ChallengeOptions, ChallengeResponse, ChangePasswordError, ChangePasswordOptions, DiscoveryCacheOptions, EnrollAuthenticatorOptions, EnrollEmailOptions, EnrollOobOptions, EnrollOtpOptions, EnrollmentResponse, EnterpriseConnectNotSupportedError, FullResponseOption, GetUserInfoOptions, IsFederatedDomainOptions, ListAuthenticatorsOptions, MfaChallengeError, MfaEnrollmentError, MfaFactorType, MfaListAuthenticatorsError, MfaRequirements, MfaVerifyError, MfaVerifyOobOptions, MfaVerifyOptions, MfaVerifyOtpOptions, MfaVerifyRecoveryCodeOptions, MissingClientAuthError, OobChannel, OobEnrollmentResponse, OrganizationValidationError, OtpEnrollmentResponse, PasskeyChallengeError, PasskeyLoginChallengeOptions as PasskeyChallengeOptions, PasskeyLoginChallengeResponse as PasskeyChallengeResponse, PasskeyCreationOptions, PasskeyCredentialResponse, PasskeyGetTokenError, GetTokenByPasskeyOptions as PasskeyGetTokenOptions, PasskeyRegisterError, PasskeySignupChallengeOptions as PasskeyRegisterOptions, PasskeySignupChallengeResponse as PasskeyRegisterResponse, PasskeyRequestOptions, PasswordlessStartError, PasswordlessVerifyError, RequestOptions, SignUpError, SignUpOptions, SignUpResult, TelemetryConfig, TokenExchangeError, TokenResponse, TokenRevocationError, UserInfoError, UserInfoResponse, isFederatedDomain, isMfaRequiredError } from '@auth0/auth0-auth-js';
3
3
  import { JWTPayload } from 'jose';
4
4
 
5
5
  /**
@@ -40,7 +40,11 @@ interface ServerClientOptions<TStoreOptions = unknown> {
40
40
  */
41
41
  customFetch?: typeof fetch;
42
42
  transactionStore: TransactionStore<TStoreOptions>;
43
- stateStore: StateStore<TStoreOptions>;
43
+ /**
44
+ * The state store for persisting session state. Required for non-Enterprise Connect mode.
45
+ * When `enterpriseConnect: true`, the state store is not needed (Auth0 does not manage a session).
46
+ */
47
+ stateStore?: StateStore<TStoreOptions>;
44
48
  /**
45
49
  * Indicates whether the SDK should use the mTLS endpoints if they are available.
46
50
  *
@@ -52,6 +56,15 @@ interface ServerClientOptions<TStoreOptions = unknown> {
52
56
  * Telemetry is enabled by default and sends the Auth0-Client header with package name and version.
53
57
  */
54
58
  telemetry?: TelemetryConfig;
59
+ /**
60
+ * Set to true when using Enterprise Connect.
61
+ *
62
+ * Auth0 acts as a pure SSO relay — it authenticates the user via the enterprise
63
+ * IdP and hands back an ID token, but holds no session and issues no refresh
64
+ * tokens. Any method that depends on an Auth0-managed session or refresh token
65
+ * throws a clear error instead of returning null silently.
66
+ */
67
+ enterpriseConnect?: true;
55
68
  }
56
69
  interface UserClaims {
57
70
  sub: string;
@@ -82,6 +95,28 @@ interface AuthorizationParameters {
82
95
  * this is supported for backwards compatibility.
83
96
  */
84
97
  organization?: string;
98
+ /**
99
+ * Selects the Experiment Center experiment to override for this authorization
100
+ * request, bypassing the server-side deterministic assignment. Use together
101
+ * with `variation_id` to force a specific variant.
102
+ *
103
+ * Pass per-call via `startInteractiveLogin` rather than at client construction
104
+ * time, so the override does not apply to every login.
105
+ */
106
+ experiment_id?: string;
107
+ /**
108
+ * The variation to assign the user to within the experiment identified by
109
+ * `experiment_id`. The override applies to this request only — the next login
110
+ * without these params reverts to normal server-side assignment.
111
+ * Requires `experiment_id`.
112
+ */
113
+ variation_id?: string;
114
+ /**
115
+ * Scopes the experiment override to a specific segment for this authorization
116
+ * request. Requires `experiment_id`. Only needed when the experiment uses
117
+ * segment targeting.
118
+ */
119
+ segment_id?: string;
85
120
  [key: string]: unknown;
86
121
  }
87
122
  interface TokenSet {
@@ -345,6 +380,22 @@ interface RevokeRefreshTokenOptions {
345
380
  }
346
381
  interface LogoutOptions {
347
382
  returnTo: string;
383
+ /**
384
+ * When true, terminates the upstream identity provider session via federated logout.
385
+ * Required for Enterprise Connect to end the enterprise IdP session.
386
+ */
387
+ federated?: boolean;
388
+ }
389
+ interface StartEnterpriseLoginOptions {
390
+ /**
391
+ * The user's email address. The domain part is used for WebFinger discovery
392
+ * and the full email is forwarded as `login_hint` to Auth0's /authorize.
393
+ */
394
+ email: string;
395
+ /**
396
+ * The URL to redirect to after login completes.
397
+ */
398
+ returnTo?: string;
348
399
  }
349
400
  interface StartLinkUserOptions<TAppState = unknown> {
350
401
  connection: string;
@@ -852,6 +903,16 @@ declare class ServerClient<TStoreOptions = unknown> {
852
903
  */
853
904
  get database(): ServerDatabaseClient<TStoreOptions>;
854
905
  constructor(options: ServerClientOptions<TStoreOptions>);
906
+ /**
907
+ * Starts the Enterprise Connect login flow. Performs WebFinger domain discovery
908
+ * and, if the email domain is federated, initiates an interactive login with `login_hint`.
909
+ *
910
+ * @param options Options including the user's email and optional returnTo URL.
911
+ * @param storeOptions Optional options passed to the Transaction Store.
912
+ *
913
+ * @returns A URL to redirect to (federated domain) or null (not federated / invalid email).
914
+ */
915
+ startEnterpriseLogin(options: StartEnterpriseLoginOptions, storeOptions?: TStoreOptions): Promise<URL | null>;
855
916
  /**
856
917
  * Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
857
918
  *
@@ -882,6 +943,7 @@ declare class ServerClient<TStoreOptions = unknown> {
882
943
  * @throws {SessionExpiredError} When the ID token's `session_expiry` is already in the past at login (the session is born expired); nothing is persisted.
883
944
  *
884
945
  * @returns A promise resolving to an object, containing the original appState (if present) and the authorizationDetails (when RAR was used).
946
+ * In Enterprise Connect mode, also includes `idTokenClaims` and `user`.
885
947
  *
886
948
  * @remarks
887
949
  * This method does not support the `fullResponse` opt-in in v1. It accepts
@@ -893,6 +955,8 @@ declare class ServerClient<TStoreOptions = unknown> {
893
955
  completeInteractiveLogin<TAppState = unknown>(url: URL, storeOptions?: TStoreOptions, requestOptions?: RequestOptions): Promise<{
894
956
  appState?: TAppState;
895
957
  authorizationDetails?: AuthorizationDetails[];
958
+ idTokenClaims?: Record<string, unknown>;
959
+ user?: UserClaims;
896
960
  }>;
897
961
  /**
898
962
  * Starts the user linking process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
@@ -1481,4 +1545,4 @@ declare class SessionExpiredError extends Error {
1481
1545
  constructor(message?: string);
1482
1546
  }
1483
1547
 
1484
- export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type BuildSessionTransferRedirectOptions, type CompletePasswordlessEmailOptions, type CompletePasswordlessOptions, type CompletePasswordlessResult, type CompletePasswordlessSmsOptions, 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, type PasskeyGetTokenResult, type RequestSessionTransferTokenOptions, type RevokeRefreshTokenOptions, ServerClient, type ServerClientOptions, ServerDatabaseClient, ServerMfaClient, ServerPasskeyClient, type SessionConfiguration, type SessionCookieOptions, type SessionData, SessionExpiredError, type SessionStore, type SessionTransferActor, type SessionTransferTokenResult, type StartInteractiveLoginOptions, StartLinkUserError, type StartLinkUserOptions, type StartPasswordlessEmailCodeOptions, type StartPasswordlessEmailLinkOptions, type StartPasswordlessOptions, type StartPasswordlessSmsOptions, type StartUnlinkUserOptions, type StateData, type StateStore, StatefulStateStore, type StatefulStateStoreOptions, StatelessStateStore, TokenExchangeErrorCode, type TokenSet, type TransactionData, type TransactionStore, type UserClaims };
1548
+ export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type BuildSessionTransferRedirectOptions, type CompletePasswordlessEmailOptions, type CompletePasswordlessOptions, type CompletePasswordlessResult, type CompletePasswordlessSmsOptions, 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, type PasskeyGetTokenResult, type RequestSessionTransferTokenOptions, type RevokeRefreshTokenOptions, ServerClient, type ServerClientOptions, ServerDatabaseClient, ServerMfaClient, ServerPasskeyClient, type SessionConfiguration, type SessionCookieOptions, type SessionData, SessionExpiredError, type SessionStore, type SessionTransferActor, type SessionTransferTokenResult, type StartEnterpriseLoginOptions, type StartInteractiveLoginOptions, StartLinkUserError, type StartLinkUserOptions, type StartPasswordlessEmailCodeOptions, type StartPasswordlessEmailLinkOptions, type StartPasswordlessOptions, type StartPasswordlessSmsOptions, type StartUnlinkUserOptions, type StateData, type StateStore, StatefulStateStore, type StatefulStateStoreOptions, StatelessStateStore, TokenExchangeErrorCode, type TokenSet, type TransactionData, type TransactionStore, type UserClaims };
package/dist/index.js CHANGED
@@ -168,6 +168,7 @@ function updateStateDataForConnectionTokenSet(options, stateData, tokenEndpointR
168
168
  import {
169
169
  TokenForConnectionError,
170
170
  AuthClient,
171
+ isFederatedDomain,
171
172
  MissingCapturedResponseError,
172
173
  OrganizationValidationError,
173
174
  PasswordlessStartError,
@@ -212,7 +213,7 @@ function getTelemetryConfig(config) {
212
213
  return {
213
214
  enabled: true,
214
215
  name: config?.name ?? "@auth0/auth0-server-js",
215
- version: config?.version ?? "1.13.0"
216
+ version: config?.version ?? "1.15.0"
216
217
  };
217
218
  }
218
219
 
@@ -447,6 +448,47 @@ var ServerDatabaseClient = class {
447
448
  }
448
449
  };
449
450
 
451
+ // src/enterprise-connect.ts
452
+ import { EnterpriseConnectNotSupportedError } from "@auth0/auth0-auth-js";
453
+ var EC_ALLOWED_METHODS = /* @__PURE__ */ new Set([
454
+ "startInteractiveLogin",
455
+ "startEnterpriseLogin",
456
+ "completeInteractiveLogin",
457
+ "logout",
458
+ "customTokenExchange",
459
+ "handleBackchannelLogout"
460
+ ]);
461
+ var EC_ALLOWED_GETTERS = /* @__PURE__ */ new Set(["authClient"]);
462
+ var NullStateStore = class {
463
+ async get() {
464
+ return void 0;
465
+ }
466
+ async set() {
467
+ }
468
+ async delete() {
469
+ }
470
+ async deleteByLogoutToken() {
471
+ }
472
+ };
473
+ function applyEnterpriseConnectRestrictions(instance) {
474
+ const proto = Object.getPrototypeOf(instance);
475
+ for (const [name, desc] of Object.entries(Object.getOwnPropertyDescriptors(proto))) {
476
+ if (name === "constructor") continue;
477
+ if (desc.get && !EC_ALLOWED_GETTERS.has(name)) {
478
+ Object.defineProperty(instance, name, {
479
+ get: () => {
480
+ throw new EnterpriseConnectNotSupportedError(name);
481
+ },
482
+ configurable: true
483
+ });
484
+ } else if (typeof desc.value === "function" && !EC_ALLOWED_METHODS.has(name)) {
485
+ instance[name] = () => {
486
+ throw new EnterpriseConnectNotSupportedError(name);
487
+ };
488
+ }
489
+ }
490
+ }
491
+
450
492
  // src/server-client.ts
451
493
  var normalizeDomain = (value) => {
452
494
  const trimmed = value.trim();
@@ -485,6 +527,7 @@ var ServerClient = class {
485
527
  #transactionStoreIdentifier;
486
528
  #stateStore;
487
529
  #stateStoreIdentifier;
530
+ #enterpriseConnect;
488
531
  #authClientOptions;
489
532
  #staticDomain;
490
533
  #authClient;
@@ -555,16 +598,36 @@ var ServerClient = class {
555
598
  }
556
599
  constructor(options) {
557
600
  this.#options = options;
601
+ this.#enterpriseConnect = !!options.enterpriseConnect;
558
602
  this.#stateStoreIdentifier = this.#options.stateIdentifier || "__a0_session";
559
603
  this.#transactionStoreIdentifier = this.#options.transactionIdentifier || "__a0_tx";
560
604
  this.#transactionStore = options.transactionStore;
561
- this.#stateStore = options.stateStore;
562
- if (!this.#options.stateStore) {
605
+ if (!this.#enterpriseConnect && !this.#options.stateStore) {
563
606
  throw new MissingRequiredArgumentError("stateStore");
564
607
  }
608
+ this.#stateStore = this.#enterpriseConnect ? new NullStateStore() : this.#options.stateStore;
565
609
  if (!this.#options.transactionStore) {
566
610
  throw new MissingRequiredArgumentError("transactionStore");
567
611
  }
612
+ if (this.#enterpriseConnect) {
613
+ if (typeof this.#options.domain === "function") {
614
+ throw new InvalidConfigurationError(
615
+ "Enterprise Connect requires a static domain string. DomainResolver is not supported because isFederatedDomain needs a concrete domain."
616
+ );
617
+ }
618
+ const scope = this.#options.authorizationParams?.scope ?? "";
619
+ if (scope.includes("offline_access")) {
620
+ console.warn(
621
+ '[Auth0] Enterprise Connect: "offline_access" in scope has no effect. B2B Integration clients are not issued refresh tokens.'
622
+ );
623
+ }
624
+ if (this.#options.organization || this.#options.authorizationParams?.organization) {
625
+ console.warn(
626
+ '[Auth0] Enterprise Connect: static "organization" is set. The organization is resolved per login by HRD from the login_hint email domain. A static value routes all enterprise users to the same organization.'
627
+ );
628
+ }
629
+ applyEnterpriseConnectRestrictions(this);
630
+ }
568
631
  if (typeof this.#options.domain !== "string" && typeof this.#options.domain !== "function") {
569
632
  throw new InvalidConfigurationError("domain must be a string or resolver function");
570
633
  }
@@ -655,6 +718,33 @@ var ServerClient = class {
655
718
  const resolvedDomain = await this.#resolveDomain(storeOptions);
656
719
  return sessionDomain === resolvedDomain;
657
720
  }
721
+ /**
722
+ * Starts the Enterprise Connect login flow. Performs WebFinger domain discovery
723
+ * and, if the email domain is federated, initiates an interactive login with `login_hint`.
724
+ *
725
+ * @param options Options including the user's email and optional returnTo URL.
726
+ * @param storeOptions Optional options passed to the Transaction Store.
727
+ *
728
+ * @returns A URL to redirect to (federated domain) or null (not federated / invalid email).
729
+ */
730
+ async startEnterpriseLogin(options, storeOptions) {
731
+ const parts = options.email.split("@");
732
+ if (parts.length !== 2 || !parts[0] || !parts[1]) return null;
733
+ const emailDomain = parts[1].toLowerCase();
734
+ const domain = await this.#resolveDomain(storeOptions);
735
+ const isFederated = await isFederatedDomain(domain, emailDomain, {
736
+ customFetch: this.#options.customFetch,
737
+ telemetry: getTelemetryConfig(this.#options.telemetry)
738
+ });
739
+ if (!isFederated) return null;
740
+ return this.startInteractiveLogin(
741
+ {
742
+ authorizationParams: { login_hint: options.email },
743
+ appState: options.returnTo ? { returnTo: options.returnTo } : void 0
744
+ },
745
+ storeOptions
746
+ );
747
+ }
658
748
  /**
659
749
  * Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
660
750
  *
@@ -676,7 +766,8 @@ var ServerClient = class {
676
766
  if (!redirectUri) {
677
767
  throw new MissingRequiredArgumentError("authorizationParams.redirect_uri");
678
768
  }
679
- const scope = ensureOpenIdScope(options?.authorizationParams?.scope ?? this.#options.authorizationParams?.scope);
769
+ const rawScope = ensureOpenIdScope(options?.authorizationParams?.scope ?? this.#options.authorizationParams?.scope);
770
+ const scope = this.#enterpriseConnect ? rawScope.split(" ").filter((s) => s !== "offline_access").join(" ") : rawScope;
680
771
  const perLoginAuthParamsOrganization = typeof options?.authorizationParams?.organization === "string" ? options.authorizationParams.organization : void 0;
681
772
  const clientAuthParamsOrganization = typeof this.#options.authorizationParams?.organization === "string" ? this.#options.authorizationParams.organization : void 0;
682
773
  const resolvedOrganization = options?.organization ?? perLoginAuthParamsOrganization ?? this.#options.organization ?? clientAuthParamsOrganization;
@@ -726,6 +817,7 @@ var ServerClient = class {
726
817
  * @throws {SessionExpiredError} When the ID token's `session_expiry` is already in the past at login (the session is born expired); nothing is persisted.
727
818
  *
728
819
  * @returns A promise resolving to an object, containing the original appState (if present) and the authorizationDetails (when RAR was used).
820
+ * In Enterprise Connect mode, also includes `idTokenClaims` and `user`.
729
821
  *
730
822
  * @remarks
731
823
  * This method does not support the `fullResponse` opt-in in v1. It accepts
@@ -747,6 +839,16 @@ var ServerClient = class {
747
839
  organization: transactionData.organization
748
840
  }, requestOptions);
749
841
  await this.#transactionStore.delete(this.#transactionStoreIdentifier, storeOptions);
842
+ if (this.#enterpriseConnect) {
843
+ const claims = tokenEndpointResponse.claims;
844
+ const user = claims ? Object.fromEntries(Object.entries(claims).filter(([, v]) => v !== void 0)) : void 0;
845
+ return {
846
+ appState: transactionData.appState,
847
+ authorizationDetails: tokenEndpointResponse.authorizationDetails,
848
+ idTokenClaims: claims,
849
+ user
850
+ };
851
+ }
750
852
  const existingStateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);
751
853
  const stateData = applySessionExpiryAtLogin(
752
854
  updateStateData(transactionData.audience ?? "default", existingStateData, tokenEndpointResponse, {
@@ -755,7 +857,10 @@ var ServerClient = class {
755
857
  tokenEndpointResponse.claims
756
858
  );
757
859
  await this.#stateStore.set(this.#stateStoreIdentifier, stateData, true, storeOptions);
758
- return { appState: transactionData.appState, authorizationDetails: tokenEndpointResponse.authorizationDetails };
860
+ return {
861
+ appState: transactionData.appState,
862
+ authorizationDetails: tokenEndpointResponse.authorizationDetails
863
+ };
759
864
  }
760
865
  /**
761
866
  * Starts the user linking process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
@@ -1428,6 +1533,14 @@ var ServerClient = class {
1428
1533
  * @returns {URL}
1429
1534
  */
1430
1535
  async logout(options, storeOptions, requestOptions) {
1536
+ if (this.#enterpriseConnect) {
1537
+ if (options.federated === false) {
1538
+ console.warn(
1539
+ "[Auth0] Enterprise Connect: logout() called with federated=false. The enterprise IdP session will remain active; the user may silently re-authenticate on the next login."
1540
+ );
1541
+ }
1542
+ return this.authClient.buildLogoutUrl({ returnTo: options.returnTo, federated: options.federated ?? true });
1543
+ }
1431
1544
  if (!this.#isResolverMode()) {
1432
1545
  try {
1433
1546
  await this.revokeRefreshToken({}, storeOptions, requestOptions);
@@ -1856,7 +1969,9 @@ import {
1856
1969
  OrganizationValidationError as OrganizationValidationError3,
1857
1970
  PasswordlessStartError as PasswordlessStartError2,
1858
1971
  PasswordlessVerifyError as PasswordlessVerifyError2,
1972
+ EnterpriseConnectNotSupportedError as EnterpriseConnectNotSupportedError2,
1859
1973
  isMfaRequiredError as isMfaRequiredError2,
1974
+ isFederatedDomain as isFederatedDomain2,
1860
1975
  UserInfoError
1861
1976
  } from "@auth0/auth0-auth-js";
1862
1977
 
@@ -2079,6 +2194,7 @@ export {
2079
2194
  BackchannelLogoutError,
2080
2195
  ChangePasswordError,
2081
2196
  CookieTransactionStore,
2197
+ EnterpriseConnectNotSupportedError2 as EnterpriseConnectNotSupportedError,
2082
2198
  InvalidConfigurationError,
2083
2199
  IssuerValidationError,
2084
2200
  MfaChallengeError,
@@ -2108,6 +2224,7 @@ export {
2108
2224
  TokenExchangeErrorCode,
2109
2225
  TokenRevocationError,
2110
2226
  UserInfoError,
2227
+ isFederatedDomain2 as isFederatedDomain,
2111
2228
  isMfaRequiredError2 as isMfaRequiredError
2112
2229
  };
2113
2230
  //# sourceMappingURL=index.js.map