@auth0/auth0-server-js 1.1.0 → 1.3.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/state/utils.ts","../src/server-client.ts","../src/utils.ts","../src/encryption/index.ts","../src/store/abstract-store.ts","../src/store/abstract-state-store.ts","../src/store/abstract-transaction-store.ts","../src/store/cookie-transaction-store.ts","../src/store/abstract-session-store.ts","../src/store/stateful-state-store.ts","../src/store/stateless-state-store.ts"],"sourcesContent":["export { ServerClient } from './server-client.js';\nexport { AbstractStateStore } from './store/abstract-state-store.js';\nexport { AbstractTransactionStore } from './store/abstract-transaction-store.js';\n\nexport type { CookieHandler, CookieSerializeOptions } from './store/cookie-handler.js';\nexport { CookieTransactionStore } from './store/cookie-transaction-store.js';\n\nexport { StatefulStateStore } from './store/stateful-state-store.js';\nexport type { StatefulStateStoreOptions } from './store/stateful-state-store.js';\nexport { StatelessStateStore } from './store/stateless-state-store.js';\n\nexport * from './errors.js';\nexport * from './types.js';\n","/**\n * Error thrown when there is no transaction available.\n */\nexport class MissingTransactionError extends Error {\n public code: string = 'missing_transaction_error';\n\n constructor(message?: string) {\n super(message ?? 'The transaction is missing.');\n this.name = 'MissingTransactionError';\n }\n}\n\n\n/**\n * Error thrown when backchannel logout fails.\n */\nexport class BackchannelLogoutError extends Error {\n public code: string = 'backchannel_logout_error';\n\n constructor(message: string) {\n super(message);\n this.name = 'BackchannelLogoutError';\n }\n}\n\n/**\n * Error thrown when starting the user-linking failed.\n */\nexport class StartLinkUserError extends Error {\n public code: string = 'start_link_user_error';\n\n constructor(message: string) {\n super(message);\n this.name = 'StartLinkUserError';\n }\n}\n\n/**\n * Error thrown when a required argument is missing.\n */\nexport class MissingRequiredArgumentError extends Error {\n public code: string = 'missing_required_argument_error';\n\n constructor(argument: string) {\n super(`The argument '${argument}' is required but was not provided.`);\n this.name = 'MissingRequiredArgumentError';\n }\n}\n\n/**\n * Error thrown when a session is missing.\n */\nexport class MissingSessionError extends Error {\n public code: string = 'missing_session_error';\n\n constructor(message: string) {\n super(message);\n this.name = 'MissingSessionError';\n }\n}","import type { AccessTokenForConnectionOptions, StateData } from '../types.js';\nimport { TokenResponse } from '@auth0/auth0-auth-js';\n\n/**\n * Utility function to update the state with a new response from the token endpoint\n * @param audience The audience of the token endpoint response\n * @param stateDate The existing state data to update, or undefined if no state data available.\n * @param tokenEndpointResponse The response from the token endpoint.\n * @returns Updated state data.\n */\nexport function updateStateData(\n audience: string,\n stateDate: StateData | undefined,\n tokenEndpointResponse: TokenResponse\n): StateData {\n if (stateDate) {\n const isNewTokenSet = !stateDate.tokenSets.some(\n (tokenSet) => tokenSet.audience === audience && tokenSet.scope === tokenEndpointResponse.scope\n );\n\n const createUpdatedTokenSet = (response: TokenResponse) => ({\n audience,\n accessToken: response.accessToken,\n scope: response.scope,\n expiresAt: Math.floor(Date.now() / 1000) + Number(response.expiresAt),\n });\n\n const tokenSets = isNewTokenSet\n ? [...stateDate.tokenSets, createUpdatedTokenSet(tokenEndpointResponse)]\n : stateDate.tokenSets.map((tokenSet) =>\n tokenSet.audience === audience && tokenSet.scope === tokenEndpointResponse.scope\n ? createUpdatedTokenSet(tokenEndpointResponse)\n : tokenSet\n );\n\n return {\n ...stateDate,\n idToken: tokenEndpointResponse.idToken,\n refreshToken: tokenEndpointResponse.refreshToken ?? stateDate.refreshToken,\n tokenSets,\n };\n } else {\n const user = tokenEndpointResponse.claims;\n return {\n user,\n idToken: tokenEndpointResponse.idToken,\n refreshToken: tokenEndpointResponse.refreshToken,\n tokenSets: [\n {\n audience,\n accessToken: tokenEndpointResponse.accessToken,\n scope: tokenEndpointResponse.scope,\n expiresAt:tokenEndpointResponse.expiresAt,\n },\n ],\n internal: {\n sid: user?.sid as string,\n createdAt: Math.floor(Date.now() / 1000),\n },\n };\n }\n}\n\nexport function updateStateDataForConnectionTokenSet(\n options: AccessTokenForConnectionOptions,\n stateDate: StateData,\n tokenEndpointResponse: TokenResponse\n) {\n stateDate.connectionTokenSets = stateDate.connectionTokenSets || [];\n\n const isNewTokenSet = !stateDate.connectionTokenSets.some(\n (tokenSet) =>\n tokenSet.connection === options.connection && (!options.loginHint || tokenSet.loginHint === options.loginHint)\n );\n\n const connectionTokenSet = {\n connection: options.connection,\n loginHint: options.loginHint,\n accessToken: tokenEndpointResponse.accessToken,\n scope: tokenEndpointResponse.scope,\n expiresAt: tokenEndpointResponse.expiresAt,\n };\n\n const connectionTokenSets = isNewTokenSet\n ? [...stateDate.connectionTokenSets, connectionTokenSet]\n : stateDate.connectionTokenSets.map((tokenSet) =>\n tokenSet.connection === options.connection &&\n (!options.loginHint || tokenSet.loginHint === options.loginHint)\n ? connectionTokenSet\n : tokenSet\n );\n\n return {\n ...stateDate,\n connectionTokenSets,\n };\n}\n","import {\n AccessTokenForConnectionOptions,\n ConnectionTokenSet,\n LoginBackchannelOptions,\n LoginBackchannelResult,\n LogoutOptions,\n ServerClientOptions,\n SessionData,\n StartInteractiveLoginOptions,\n StartLinkUserOptions,\n StartUnlinkUserOptions,\n StateStore,\n TokenSet,\n TransactionData,\n TransactionStore,\n} from './types.js';\nimport {\n BackchannelLogoutError,\n MissingRequiredArgumentError,\n MissingSessionError,\n MissingTransactionError,\n} from './errors.js';\nimport { updateStateData, updateStateDataForConnectionTokenSet } from './state/utils.js';\nimport {\n TokenForConnectionError,\n AuthClient,\n AuthorizationDetails,\n TokenByRefreshTokenError,\n} from '@auth0/auth0-auth-js';\nimport { compareScopes } from './utils.js';\n\nexport class ServerClient<TStoreOptions = unknown> {\n readonly #options: ServerClientOptions<TStoreOptions>;\n readonly #transactionStore: TransactionStore<TStoreOptions>;\n readonly #transactionStoreIdentifier: string;\n readonly #stateStore: StateStore<TStoreOptions>;\n readonly #stateStoreIdentifier: string;\n\n /**\n * The underlying `authClient` instance that can be used to interact with the Auth0 Authentication API.\n * Generally, you should prefer to use the higher-level methods exposed on the `ServerClient` instance.\n * \n * Important: the methods exposed on the `authClient` instance do not handle any session or state management.\n */\n readonly authClient: AuthClient;\n\n constructor(options: ServerClientOptions<TStoreOptions>) {\n this.#options = options;\n this.#stateStoreIdentifier = this.#options.stateIdentifier || '__a0_session';\n this.#transactionStoreIdentifier = this.#options.transactionIdentifier || '__a0_tx';\n this.#transactionStore = options.transactionStore;\n this.#stateStore = options.stateStore;\n\n if (!this.#options.stateStore) {\n throw new MissingRequiredArgumentError('stateStore');\n }\n\n if (!this.#options.transactionStore) {\n throw new MissingRequiredArgumentError('transactionStore');\n }\n\n this.authClient = new AuthClient({\n domain: this.#options.domain,\n clientId: this.#options.clientId,\n clientSecret: this.#options.clientSecret,\n clientAssertionSigningKey: this.#options.clientAssertionSigningKey,\n clientAssertionSigningAlg: this.#options.clientAssertionSigningAlg,\n authorizationParams: this.#options.authorizationParams,\n customFetch: this.#options.customFetch,\n useMtls: this.#options.useMtls,\n });\n }\n\n /**\n * Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.\n * @param options Optional options used to configure the interactive login process.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {BuildAuthorizationUrlError} If there was an issue when building the Authorization URL.\n *\n * @returns A promise resolving to a URL object, representing the URL to redirect the user-agent to to request authorization at Auth0.\n */\n public async startInteractiveLogin(options?: StartInteractiveLoginOptions, storeOptions?: TStoreOptions) {\n const redirectUri = options?.authorizationParams?.redirect_uri ?? this.#options.authorizationParams?.redirect_uri;\n if (!redirectUri) {\n throw new MissingRequiredArgumentError('authorizationParams.redirect_uri');\n }\n\n const { codeVerifier, authorizationUrl } = await this.authClient.buildAuthorizationUrl({\n pushedAuthorizationRequests: options?.pushedAuthorizationRequests,\n authorizationParams: {\n ...options?.authorizationParams,\n redirect_uri: redirectUri,\n },\n });\n\n const transactionState: TransactionData = {\n audience: options?.authorizationParams?.audience ?? this.#options.authorizationParams?.audience,\n codeVerifier,\n };\n\n if (options?.appState) {\n transactionState.appState = options.appState;\n }\n\n await this.#transactionStore.set(this.#transactionStoreIdentifier, transactionState, false, storeOptions);\n\n return authorizationUrl;\n }\n\n /**\n * Completes the interactive login process.\n * Takes an URL, extract the Authorization Code flow query parameters and requests a token.\n * @param url The URl from which the query params should be extracted to exchange for a token.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {MissingTransactionError} When no transaction was found.\n * @throws {TokenByCodeError} If there was an issue requesting the access token.\n *\n * @returns A promise resolving to an object, containing the original appState (if present) and the authorizationDetails (when RAR was used).\n */\n public async completeInteractiveLogin<TAppState = unknown>(url: URL, storeOptions?: TStoreOptions) {\n const transactionData = await this.#transactionStore.get(this.#transactionStoreIdentifier, storeOptions);\n\n if (!transactionData) {\n throw new MissingTransactionError();\n }\n\n const tokenEndpointResponse = await this.authClient.getTokenByCode(url, {\n codeVerifier: transactionData.codeVerifier,\n });\n\n const existingStateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n const stateData = updateStateData(transactionData.audience ?? 'default', existingStateData, tokenEndpointResponse);\n\n await this.#stateStore.set(this.#stateStoreIdentifier, stateData, true, storeOptions);\n await this.#transactionStore.delete(this.#transactionStoreIdentifier, storeOptions);\n\n return { appState: transactionData.appState, authorizationDetails: tokenEndpointResponse.authorizationDetails } as {\n appState?: TAppState;\n authorizationDetails?: AuthorizationDetails[];\n };\n }\n\n /**\n * Starts the user linking process, and returns a URL to redirect the user-agent to to request authorization at Auth0.\n * @param options Options used to configure the user linking process.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {MissingSessionError} If there is no active session.\n * @throws {BuildLinkUserUrlError} If there was an issue when building the Authorization URL.\n *\n * @returns A promise resolving to a URL object, representing the URL to redirect the user-agent to to request authorization at Auth0.\n */\n public async startLinkUser(options: StartLinkUserOptions, storeOptions?: TStoreOptions) {\n const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n if (!stateData || !stateData.idToken) {\n throw new MissingSessionError(\n 'Unable to start the user linking process without a logged in user. Ensure to login using the SDK before starting the user linking process.'\n );\n }\n\n const { linkUserUrl, codeVerifier } = await this.authClient.buildLinkUserUrl({\n connection: options.connection,\n connectionScope: options.connectionScope,\n idToken: stateData.idToken,\n authorizationParams: options.authorizationParams,\n });\n\n const transactionState: TransactionData = {\n audience: options?.authorizationParams?.audience ?? this.#options.authorizationParams?.audience,\n codeVerifier,\n };\n\n if (options?.appState) {\n transactionState.appState = options.appState;\n }\n\n await this.#transactionStore.set(this.#transactionStoreIdentifier, transactionState, false, storeOptions);\n\n return linkUserUrl;\n }\n\n /**\n * Completes the user linking process.\n * Takes an URL, extract the Authorization Code flow query parameters and requests a token.\n * @param url The URl from which the query params should be extracted to exchange for a token.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {MissingTransactionError} When no transaction was found.\n * @throws {TokenByCodeError} If there was an issue requesting the access token.\n *\n * @returns A promise resolving to an object, containing the original appState (if present).\n */\n public async completeLinkUser<TAppState = unknown>(url: URL, storeOptions?: TStoreOptions) {\n // In order to complete the link user flow, we need to exchange the code for a token in the same\n // way as we do for the interactive login flow.\n const result = await this.completeInteractiveLogin<TAppState>(url, storeOptions);\n\n // As we currently do not support RAR when starting the user linking flow, we will ommit it from being returned as optional altogether.\n return {\n appState: result.appState,\n };\n }\n\n /**\n * Starts the user unlinking process, and returns a URL to redirect the user-agent to to initialize user unlinking at Auth0.\n * @param options Options used to configure the user unlinking process.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {MissingSessionError} If there is no active session.\n * @throws {BuildUnlinkUserUrlError} If there was an issue when building the User Unlinking URL.\n *\n * @returns A promise resolving to a URL object, representing the URL to redirect the user-agent to to request authorization at Auth0.\n */\n public async startUnlinkUser(options: StartUnlinkUserOptions, storeOptions?: TStoreOptions) {\n const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n if (!stateData || !stateData.idToken) {\n throw new MissingSessionError(\n 'Unable to start the user unlinking process without a logged in user. Ensure to login using the SDK before starting the user unlinking process.'\n );\n }\n\n const { unlinkUserUrl, codeVerifier } = await this.authClient.buildUnlinkUserUrl({\n connection: options.connection,\n idToken: stateData.idToken,\n authorizationParams: options.authorizationParams,\n });\n\n const transactionState: TransactionData = {\n audience: options?.authorizationParams?.audience ?? this.#options.authorizationParams?.audience,\n codeVerifier,\n };\n\n if (options?.appState) {\n transactionState.appState = options.appState;\n }\n\n await this.#transactionStore.set(this.#transactionStoreIdentifier, transactionState, false, storeOptions);\n\n return unlinkUserUrl;\n }\n\n /**\n * Completes the user unlinking process.\n * Takes an URL, extract the Authorization Code flow query parameters and requests a token.\n * @param url The URl from which the query params should be extracted to exchange for a token.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {MissingTransactionError} When no transaction was found.\n * @throws {TokenByCodeError} If there was an issue requesting the access token.\n *\n * @returns A promise resolving to an object, containing the original appState (if present).\n */\n public async completeUnlinkUser<TAppState = unknown>(url: URL, storeOptions?: TStoreOptions) {\n // In order to complete the link user flow, we need to exchange the code for a token in the same\n // way as we do for the interactive login flow.\n const result = await this.completeInteractiveLogin<TAppState>(url, storeOptions);\n\n // As we currently do not support RAR when starting the user unlinking flow, we will ommit it from being returned as optional altogether.\n return {\n appState: result.appState,\n };\n }\n\n /**\n * Logs in using Client-Initiated Backchannel Authentication.\n *\n * Using Client-Initiated Backchannel Authentication requires the feature to be enabled in the Auth0 dashboard.\n * @see https://auth0.com/docs/get-started/authentication-and-authorization-flow/client-initiated-backchannel-authentication-flow\n * @param options Options used to configure the backchannel login process.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {BackchannelAuthenticationError} If there was an issue when doing backchannel authentication.\n *\n * @returns A promise resolving to an object, containing the authorizationDetails (when RAR was used).\n */\n public async loginBackchannel(\n options: LoginBackchannelOptions,\n storeOptions?: TStoreOptions\n ): Promise<LoginBackchannelResult> {\n const tokenEndpointResponse = await this.authClient.backchannelAuthentication({\n bindingMessage: options.bindingMessage,\n loginHint: options.loginHint,\n authorizationParams: options.authorizationParams,\n });\n\n const existingStateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n const stateData = updateStateData(\n this.#options.authorizationParams?.audience ?? 'default',\n existingStateData,\n tokenEndpointResponse\n );\n\n await this.#stateStore.set(this.#stateStoreIdentifier, stateData, true, storeOptions);\n\n return {\n authorizationDetails: tokenEndpointResponse.authorizationDetails,\n };\n }\n\n /**\n * Retrieves the user from the store, or undefined if no user found.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n * @returns The user, or undefined if no user found in the store.\n */\n public async getUser(storeOptions?: TStoreOptions) {\n const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n return stateData?.user;\n }\n\n /**\n * Retrieve the user session from the store, or undefined if no session found.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n * @returns The sessionm or undefined if no session found in the store.\n */\n public async getSession(storeOptions?: TStoreOptions): Promise<SessionData | undefined> {\n const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n if (stateData) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { internal, ...sessionData } = stateData;\n return sessionData;\n }\n }\n\n /**\n * Retrieves the access token from the store, or calls Auth0 when the access token is expired and a refresh token is available in the store.\n * Also updates the store when a new token was retrieved from Auth0.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {TokenByRefreshTokenError} If the refresh token was not found or there was an issue requesting the access token.\n *\n * @returns The Token Set, containing the access token, as well as additional information.\n */\n public async getAccessToken(storeOptions?: TStoreOptions): Promise<TokenSet> {\n const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n const audience = this.#options.authorizationParams?.audience ?? 'default';\n const scope = this.#options.authorizationParams?.scope;\n\n const tokenSet = stateData?.tokenSets.find(\n (tokenSet) => tokenSet.audience === audience && (!scope || compareScopes(tokenSet.scope, scope))\n );\n\n if (tokenSet && tokenSet.expiresAt > Date.now() / 1000) {\n return tokenSet;\n }\n\n if (!stateData?.refreshToken) {\n throw new TokenByRefreshTokenError(\n 'The access token has expired and a refresh token was not provided. The user needs to re-authenticate.'\n );\n }\n\n const tokenEndpointResponse = await this.authClient.getTokenByRefreshToken({\n refreshToken: stateData.refreshToken,\n });\n const existingStateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n const updatedStateData = updateStateData(audience, existingStateData, tokenEndpointResponse);\n\n await this.#stateStore.set(this.#stateStoreIdentifier, updatedStateData, false, storeOptions);\n\n return {\n accessToken: tokenEndpointResponse.accessToken,\n scope: tokenEndpointResponse.scope,\n expiresAt: tokenEndpointResponse.expiresAt,\n audience: audience,\n };\n }\n\n /**\n * Retrieves an access token for a connection.\n *\n * This method attempts to obtain an access token for a specified connection.\n * It first checks if a refresh token exists in the store.\n * If no refresh token is found, it throws an `AccessTokenForConnectionError` indicating\n * that the refresh token was not found.\n *\n * @param options - Options for retrieving an access token for a connection.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {TokenForConnectionError} If the refresh token was not found or there was an issue requesting the access token.\n *\n * @returns The Connection Token Set, containing the access token for the connection, as well as additional information.\n */\n public async getAccessTokenForConnection(options: AccessTokenForConnectionOptions, storeOptions?: TStoreOptions): Promise<ConnectionTokenSet> {\n const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n const connectionTokenSet = stateData?.connectionTokenSets?.find(\n (tokenSet) => tokenSet.connection === options.connection\n );\n\n if (connectionTokenSet && connectionTokenSet.expiresAt > Date.now() / 1000) {\n return connectionTokenSet;\n }\n\n if (!stateData?.refreshToken) {\n throw new TokenForConnectionError(\n 'A refresh token was not found but is required to be able to retrieve an access token for a connection.'\n );\n }\n\n const tokenEndpointResponse = await this.authClient.getTokenForConnection({\n connection: options.connection,\n loginHint: options.loginHint,\n refreshToken: stateData.refreshToken,\n });\n\n const updatedStateData = updateStateDataForConnectionTokenSet(options, stateData, tokenEndpointResponse);\n\n await this.#stateStore.set(this.#stateStoreIdentifier, updatedStateData, false, storeOptions);\n\n return {\n accessToken: tokenEndpointResponse.accessToken,\n scope: tokenEndpointResponse.scope,\n expiresAt: tokenEndpointResponse.expiresAt,\n connection: options.connection,\n loginHint: options.loginHint,\n };\n }\n\n /**\n * Logs the user out and returns a URL to redirect the user-agent to after they log out.\n * @param options Options used to configure the logout process.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n * @returns {URL}\n */\n public async logout(options: LogoutOptions, storeOptions?: TStoreOptions) {\n await this.#stateStore.delete(this.#stateStoreIdentifier, storeOptions);\n\n return this.authClient.buildLogoutUrl(options);\n }\n\n /**\n * Handles the backchannel logout process by verifying the logout token and deleting the session from the store if the logout token was considered valid.\n * @param logoutToken The logout token to verify and use to delete the session from the store.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {BackchannelLogoutError} If the logout token is missing.\n * @throws {VerifyLogoutTokenError} If the logout token is invalid.\n */\n public async handleBackchannelLogout(logoutToken: string, storeOptions?: TStoreOptions) {\n if (!logoutToken) {\n throw new BackchannelLogoutError('Missing Logout Token');\n }\n\n const logoutTokenClaims = await this.authClient.verifyLogoutToken({ logoutToken });\n\n await this.#stateStore.deleteByLogoutToken(logoutTokenClaims, storeOptions);\n }\n}\n","/**\n * Compares two sets of scopes to determine if all required scopes are present in the provided scopes.\n * @param scopes Scopes to compare\n * @param requiredScopes Scopes required to be present in the scopes\n * @returns True if all required scopes are present in the scopes, false otherwise\n */\nexport const compareScopes = (scopes: string | undefined, requiredScopes: string | undefined) => {\n // When the scopes and requiredScopes are exactly the same, return true\n // This handles cases where both are empty or undefined or both are the same string\n if (scopes === requiredScopes) {\n return true;\n }\n\n if (!scopes || !requiredScopes) {\n return false;\n }\n\n const scopesSet = new Set(scopes.trim().split(' ').filter(Boolean));\n const requiredScopesArray = requiredScopes.trim().split(' ').filter(Boolean);\n\n return requiredScopesArray.every((scope) => scopesSet.has(scope));\n};\n","import { EncryptJWT, jwtDecrypt } from 'jose';\nimport type { JWTPayload } from 'jose';\n\nconst ENC = 'A256CBC-HS512';\nconst ALG = 'dir';\nconst DIGEST = 'SHA-256';\nconst BIT_LENGTH = 512;\nconst HKDF_INFO = 'derived cookie encryption secret';\n\nlet encoder: TextEncoder | undefined;\n\nasync function deriveEncryptionSecret(secret: string, salt: string, kid: string) {\n encoder ||= new TextEncoder();\n const key = await crypto.subtle.importKey('raw', encoder.encode(secret), 'HKDF', false, ['deriveBits']);\n\n return new Uint8Array(\n await crypto.subtle.deriveBits(\n {\n name: 'HKDF',\n hash: DIGEST,\n info: encoder.encode(HKDF_INFO),\n salt: encoder.encode(`${salt}${kid}`),\n } as HkdfParams,\n key,\n BIT_LENGTH\n )\n );\n}\n\nexport async function encrypt(payload: JWTPayload, secret: string, salt: string, expiration: number) {\n const kid = crypto.randomUUID();\n const encryptionSecret = await deriveEncryptionSecret(secret, salt, kid);\n\n return await new EncryptJWT(payload)\n .setProtectedHeader({ enc: ENC, alg: ALG, kid: kid })\n .setExpirationTime(expiration)\n .encrypt(encryptionSecret);\n}\n\nexport async function decrypt<T>(value: string, secret: string, salt: string) {\n const res = await jwtDecrypt<T>(\n value,\n async (protectedHeader) => {\n\n // This error shouldn't happen, as we always set a kid.\n // However, leaving this here as a safety net.\n if (!protectedHeader.kid) {\n throw new Error('Missing \"kid\" in JWE header');\n }\n\n return await deriveEncryptionSecret(secret, salt, protectedHeader.kid);\n },\n { clockTolerance: 15 }\n );\n return res.payload;\n}\n","import type { EncryptedStoreOptions, AbstractDataStore } from '../types.js';\nimport { encrypt, decrypt } from '../encryption/index.js';\nimport { JWTPayload } from 'jose';\n\n/**\n * Abstract class that can be used to implement an Encrypted JWT State Store, using the 'A256CBC-HS512' encryption algorithm.\n */\nexport abstract class AbstractStore<TData extends JWTPayload, TStoreOptions = unknown> implements AbstractDataStore<TData, TStoreOptions>\n{\n protected readonly options: EncryptedStoreOptions;\n\n constructor(options: EncryptedStoreOptions) {\n this.options = options;\n }\n\n abstract set(identifier: string, state: TData, removeIfExists?: boolean, options?: TStoreOptions | undefined): Promise<void>;\n abstract get(identifier: string, options?: TStoreOptions | undefined): Promise<TData | undefined>;\n abstract delete(identifier: string, options?: TStoreOptions | undefined): Promise<void>;\n\n protected async encrypt<TData extends JWTPayload>(identifier: string, stateData: TData, expiration: number) {\n return await encrypt(stateData, this.options.secret, identifier, expiration);\n }\n\n protected async decrypt<TData>(identifier: string, encryptedStateData: string) {\n return await decrypt(encryptedStateData, this.options.secret, identifier) as TData;\n }\n}\n","import type { StateData, EncryptedStoreOptions, StateStore, LogoutTokenClaims } from '../types.js';\nimport { AbstractStore } from './abstract-store.js';\n\n/**\n * Abstract class that can be used to implement an Encrypted JWT State Store, using the 'A256CBC-HS512' encryption algorithm.\n */\nexport abstract class AbstractStateStore<TStoreOptions = unknown> extends AbstractStore<StateData, TStoreOptions> implements StateStore<TStoreOptions> {\n constructor(options: EncryptedStoreOptions) {\n super(options);\n }\n\n abstract deleteByLogoutToken(claims: LogoutTokenClaims, options?: TStoreOptions | undefined): Promise<void>;\n}","import type { EncryptedStoreOptions, TransactionData, TransactionStore } from '../types.js';\nimport { AbstractStore } from './abstract-store.js';\n\n/**\n * Abstract class that can be used to implement an Encrypted JWT Transaction Store, using the 'A256CBC-HS512' encryption algorithm.\n */\nexport abstract class AbstractTransactionStore<TStoreOptions = unknown> extends AbstractStore<TransactionData, TStoreOptions> implements TransactionStore<TStoreOptions> {\n constructor(options: EncryptedStoreOptions) {\n super(options);\n }\n}","import type { EncryptedStoreOptions, TransactionData } from './../types.js';\nimport { AbstractTransactionStore } from './abstract-transaction-store.js';\nimport type { CookieHandler, CookieSerializeOptions } from './cookie-handler.js';\n\nexport class CookieTransactionStore<TStoreOptions> extends AbstractTransactionStore<TStoreOptions> {\n readonly #cookieHandler: CookieHandler<TStoreOptions>;\n\n constructor(options: EncryptedStoreOptions, cookieHandler: CookieHandler<TStoreOptions>) {\n super(options);\n this.#cookieHandler = cookieHandler;\n }\n\n async set(\n identifier: string,\n transactionData: TransactionData,\n removeIfExists?: boolean,\n options?: TStoreOptions\n ): Promise<void> { \n const maxAge = 60 * 60;\n const cookieOpts: CookieSerializeOptions = { httpOnly: true, sameSite: 'lax', path: '/', maxAge };\n const expiration = Math.floor(Date.now() / 1000 + maxAge);\n const encryptedStateData = await this.encrypt(identifier, transactionData, expiration);\n\n this.#cookieHandler.setCookie(identifier, encryptedStateData, cookieOpts, options);\n }\n\n async get(identifier: string, options?: TStoreOptions): Promise<TransactionData | undefined> {\n const cookieValue = this.#cookieHandler.getCookie(identifier, options);\n\n if (cookieValue) {\n return await this.decrypt(identifier, cookieValue);\n }\n }\n\n async delete(identifier: string, options?: TStoreOptions | undefined): Promise<void> {\n this.#cookieHandler.deleteCookie(identifier, options);\n }\n}\n","import { AbstractStateStore } from './abstract-state-store.js';\nimport type { EncryptedStoreOptions, SessionConfiguration } from '../types.js';\n\nexport abstract class AbstractSessionStore<TStoreOptions> extends AbstractStateStore<TStoreOptions> {\n readonly #rolling: boolean;\n readonly #absoluteDuration: number;\n readonly #inactivityDuration: number;\n\n constructor(options: SessionConfiguration & EncryptedStoreOptions) {\n super(options);\n\n this.#rolling = options.rolling ?? true;\n this.#absoluteDuration = options.absoluteDuration ?? 60 * 60 * 24 * 3;\n this.#inactivityDuration = options.inactivityDuration ?? 60 * 60 * 24 * 1;\n }\n\n /**\n * calculateMaxAge calculates the max age of the session based on createdAt and the rolling and absolute durations.\n */\n protected calculateMaxAge(createdAt: number) {\n if (!this.#rolling) {\n return this.#absoluteDuration;\n }\n\n const now = (Date.now() / 1000) | 0;\n const expiresAt = Math.min(now + this.#inactivityDuration, createdAt + this.#absoluteDuration);\n const maxAge = expiresAt - now;\n\n return maxAge > 0 ? maxAge : 0;\n }\n}","import type {\n EncryptedStoreOptions,\n LogoutTokenClaims,\n SessionConfiguration,\n SessionCookieOptions,\n SessionStore,\n StateData,\n} from '../types.js';\nimport { AbstractSessionStore } from './abstract-session-store.js';\nimport type { CookieHandler, CookieSerializeOptions } from './cookie-handler.js';\n\nexport interface StatefulStateStoreOptions<TStoreOptions> extends EncryptedStoreOptions {\n store: SessionStore<TStoreOptions>;\n}\n\nconst generateId = () => {\n const bytes = new Uint8Array(16);\n crypto.getRandomValues(bytes);\n return Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n};\n\nexport class StatefulStateStore<TStoreOptions> extends AbstractSessionStore<TStoreOptions> {\n readonly #store: SessionStore<TStoreOptions>;\n readonly #cookieOptions: SessionCookieOptions | undefined;\n readonly #cookieHandler: CookieHandler<TStoreOptions>;\n\n constructor(\n options: StatefulStateStoreOptions<TStoreOptions> & SessionConfiguration,\n cookieHandler: CookieHandler<TStoreOptions>\n ) {\n super(options);\n\n this.#store = options.store;\n this.#cookieOptions = options.cookie;\n this.#cookieHandler = cookieHandler;\n }\n\n async set(\n identifier: string,\n stateData: StateData,\n removeIfExists?: boolean,\n options?: TStoreOptions | undefined\n ): Promise<void> {\n let sessionId = await this.getSessionId(identifier, options);\n\n // if this is a new session created by a new login we need to remove the old session\n // from the store and regenerate the session ID to prevent session fixation.\n if (sessionId && removeIfExists) {\n await this.#store.delete(sessionId);\n sessionId = generateId();\n }\n\n sessionId ??= generateId();\n\n const maxAge = this.calculateMaxAge(stateData.internal.createdAt);\n const cookieOpts: CookieSerializeOptions = {\n httpOnly: true,\n sameSite: this.#cookieOptions?.sameSite ?? 'lax',\n path: '/',\n secure: this.#cookieOptions?.secure,\n maxAge,\n };\n const expiration = Date.now() / 1000 + maxAge;\n const encryptedStateData = await this.encrypt<{ id: string }>(\n identifier,\n {\n id: sessionId,\n },\n expiration\n );\n\n await this.#store.set(sessionId, stateData);\n\n this.#cookieHandler.setCookie(identifier, encryptedStateData, cookieOpts, options);\n }\n\n async get(identifier: string, options?: TStoreOptions | undefined): Promise<StateData | undefined> {\n const sessionId = await this.getSessionId(identifier, options);\n\n if (sessionId) {\n const stateData = await this.#store.get(sessionId);\n\n // If we have a session cookie, but no `stateData`, we should remove the cookie.\n if (!stateData) {\n this.#cookieHandler.deleteCookie(identifier, options);\n }\n\n return stateData;\n }\n }\n\n async delete(identifier: string, options?: TStoreOptions | undefined): Promise<void> {\n const sessionId = await this.getSessionId(identifier, options);\n\n if (sessionId) {\n await this.#store.delete(sessionId);\n }\n\n this.#cookieHandler.deleteCookie(identifier, options);\n }\n\n private async getSessionId(identifier: string, options?: TStoreOptions) {\n const cookieValue = this.#cookieHandler.getCookie(identifier, options);\n if (cookieValue) {\n const sessionCookie = await this.decrypt<{ id: string }>(identifier, cookieValue);\n return sessionCookie.id;\n }\n }\n\n deleteByLogoutToken(claims: LogoutTokenClaims, options?: TStoreOptions | undefined): Promise<void> {\n return this.#store.deleteByLogoutToken(claims, options);\n }\n}\n","import type { EncryptedStoreOptions, SessionConfiguration, SessionCookieOptions, StateData } from '../types.js';\nimport { AbstractSessionStore } from './abstract-session-store.js';\nimport type { CookieHandler, CookieSerializeOptions } from './cookie-handler.js';\n\nexport class StatelessStateStore<TStoreOptions> extends AbstractSessionStore<TStoreOptions> {\n readonly #cookieOptions: SessionCookieOptions | undefined;\n readonly #cookieHandler: CookieHandler<TStoreOptions>;\n\n constructor(options: SessionConfiguration & EncryptedStoreOptions, cookieHandler: CookieHandler<TStoreOptions>) {\n super(options);\n\n this.#cookieOptions = options.cookie;\n this.#cookieHandler = cookieHandler;\n }\n\n async set(\n identifier: string,\n stateData: StateData,\n removeIfExists?: boolean,\n options?: TStoreOptions | undefined\n ): Promise<void> {\n const maxAge = this.calculateMaxAge(stateData.internal.createdAt);\n const cookieOpts: CookieSerializeOptions = {\n httpOnly: true,\n sameSite: this.#cookieOptions?.sameSite ?? 'lax',\n path: '/',\n secure: this.#cookieOptions?.secure ?? true,\n maxAge,\n };\n const expiration = Math.floor(Date.now() / 1000 + maxAge);\n const encryptedStateData = await this.encrypt(identifier, stateData, expiration);\n\n const chunkSize = 3072;\n const chunkCount = Math.ceil(encryptedStateData.length / chunkSize);\n const chunks = [...Array(chunkCount).keys()].map((i) => ({\n value: encryptedStateData.substring(i * chunkSize, (i + 1) * chunkSize),\n name: `${identifier}.${i}`,\n }));\n\n chunks.forEach((chunk) => {\n this.#cookieHandler.setCookie(chunk.name, chunk.value, cookieOpts, options);\n });\n\n const existingCookieKeys = this.getCookieKeys(identifier, options);\n const cookieKeysToRemove = existingCookieKeys.filter((key) => !chunks.some((chunk) => chunk.name === key));\n cookieKeysToRemove.forEach((key) => {\n this.#cookieHandler.deleteCookie(key, options);\n });\n }\n\n async get(identifier: string, options?: TStoreOptions | undefined): Promise<StateData | undefined> {\n const cookieKeys = this.getCookieKeys(identifier, options);\n const encryptedStateData = cookieKeys\n .map((key) => ({\n index: parseInt(key.split('.')[1] as string, 10),\n value: this.#cookieHandler.getCookie(key, options),\n }))\n .sort((a, b) => a.index - b.index)\n .map((item) => item.value)\n .join('');\n\n if (encryptedStateData) {\n return await this.decrypt(identifier, encryptedStateData);\n }\n }\n\n async delete(identifier: string, options?: TStoreOptions | undefined): Promise<void> {\n const cookieKeys = this.getCookieKeys(identifier, options);\n for (const key of cookieKeys) {\n this.#cookieHandler.deleteCookie(key, options);\n }\n }\n\n deleteByLogoutToken(): Promise<void> {\n throw new Error(\n 'Backchannel logout is not available when using Stateless Storage. Use Stateful Storage by providing a `sessionStore`'\n );\n }\n\n private getCookieKeys(identifier: string, options?: TStoreOptions): string[] {\n return Object.keys(this.#cookieHandler.getCookies(options)).filter((key) => key.startsWith(identifier));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,0BAAN,cAAsC,MAAM;AAAA,EAC1C,OAAe;AAAA,EAEtB,YAAY,SAAkB;AAC5B,UAAM,WAAW,6BAA6B;AAC9C,SAAK,OAAO;AAAA,EACd;AACF;AAMO,IAAM,yBAAN,cAAqC,MAAM;AAAA,EACzC,OAAe;AAAA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,YAAY,kBAAkB;AAAA,IAC1D;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,YAAoB,SAAoD;AACnF,UAAM,aAAa,KAAK,cAAc,YAAY,OAAO;AACzD,eAAW,OAAO,YAAY;AAC5B,WAAK,eAAe,aAAa,KAAK,OAAO;AAAA,IAC/C;AAAA,EACF;AAAA,EAEA,sBAAqC;AACnC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,cAAc,YAAoB,SAAmC;AAC3E,WAAO,OAAO,KAAK,KAAK,eAAe,WAAW,OAAO,CAAC,EAAE,OAAO,CAAC,QAAQ,IAAI,WAAW,UAAU,CAAC;AAAA,EACxG;AACF;","names":["tokenSet"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/state/utils.ts","../src/server-client.ts","../src/utils.ts","../src/telemetry.ts","../src/encryption/index.ts","../src/store/abstract-store.ts","../src/store/abstract-state-store.ts","../src/store/abstract-transaction-store.ts","../src/store/cookie-transaction-store.ts","../src/store/abstract-session-store.ts","../src/store/stateful-state-store.ts","../src/store/stateless-state-store.ts"],"sourcesContent":["export { ServerClient } from './server-client.js';\nexport { AbstractStateStore } from './store/abstract-state-store.js';\nexport { AbstractTransactionStore } from './store/abstract-transaction-store.js';\n\nexport type { CookieHandler, CookieSerializeOptions } from './store/cookie-handler.js';\nexport { CookieTransactionStore } from './store/cookie-transaction-store.js';\n\nexport { StatefulStateStore } from './store/stateful-state-store.js';\nexport type { StatefulStateStoreOptions } from './store/stateful-state-store.js';\nexport { StatelessStateStore } from './store/stateless-state-store.js';\n\nexport * from './errors.js';\nexport * from './types.js';\n","/**\n * Error thrown when there is no transaction available.\n */\nexport class MissingTransactionError extends Error {\n public code: string = 'missing_transaction_error';\n\n constructor(message?: string) {\n super(message ?? 'The transaction is missing.');\n this.name = 'MissingTransactionError';\n }\n}\n\n\n/**\n * Error thrown when backchannel logout fails.\n */\nexport class BackchannelLogoutError extends Error {\n public code: string = 'backchannel_logout_error';\n\n constructor(message: string) {\n super(message);\n this.name = 'BackchannelLogoutError';\n }\n}\n\n/**\n * Error thrown when starting the user-linking failed.\n */\nexport class StartLinkUserError extends Error {\n public code: string = 'start_link_user_error';\n\n constructor(message: string) {\n super(message);\n this.name = 'StartLinkUserError';\n }\n}\n\n/**\n * Error thrown when a required argument is missing.\n */\nexport class MissingRequiredArgumentError extends Error {\n public code: string = 'missing_required_argument_error';\n\n constructor(argument: string) {\n super(`The argument '${argument}' is required but was not provided.`);\n this.name = 'MissingRequiredArgumentError';\n }\n}\n\n/**\n * Error thrown when a session is missing.\n */\nexport class MissingSessionError extends Error {\n public code: string = 'missing_session_error';\n\n constructor(message: string) {\n super(message);\n this.name = 'MissingSessionError';\n }\n}\n\n/**\n * Error thrown when a configuration is invalid.\n */\nexport class InvalidConfigurationError extends Error {\n public code: string = 'invalid_configuration_error';\n\n constructor(message: string) {\n super(message);\n this.name = 'InvalidConfigurationError';\n }\n}","import type { AccessTokenForConnectionOptions, StateData } from '../types.js';\nimport { TokenResponse } from '@auth0/auth0-auth-js';\n\n/**\n * Creates an updated token set object from the token endpoint response\n * @param audience The audience for which the token was requested\n * @param response The response from the token endpoint\n * @returns Updated token set object\n */\nconst createUpdatedTokenSet = (audience: string, response: TokenResponse) => ({\n audience,\n accessToken: response.accessToken,\n scope: response.scope,\n expiresAt: response.expiresAt,\n});\n\n/**\n * Utility function to update the state with a new response from the token endpoint\n * @param audience The audience of the token endpoint response\n * @param stateData The existing state data to update, or undefined if no state data available.\n * @param tokenEndpointResponse The response from the token endpoint.\n * @returns Updated state data.\n */\nexport function updateStateData(\n audience: string,\n stateData: StateData | undefined,\n tokenEndpointResponse: TokenResponse\n): StateData {\n if (stateData) {\n const isNewTokenSet = !stateData.tokenSets.some(\n (tokenSet) => tokenSet.audience === audience && tokenSet.scope === tokenEndpointResponse.scope\n );\n\n const tokenSets = isNewTokenSet\n ? [...stateData.tokenSets, createUpdatedTokenSet(audience, tokenEndpointResponse)]\n : stateData.tokenSets.map((tokenSet) =>\n tokenSet.audience === audience && tokenSet.scope === tokenEndpointResponse.scope\n ? createUpdatedTokenSet(audience, tokenEndpointResponse)\n : tokenSet\n );\n\n return {\n ...stateData,\n idToken: tokenEndpointResponse.idToken ?? stateData.idToken,\n refreshToken: tokenEndpointResponse.refreshToken ?? stateData.refreshToken,\n tokenSets,\n };\n } else {\n const user = tokenEndpointResponse.claims;\n return {\n user,\n idToken: tokenEndpointResponse.idToken,\n refreshToken: tokenEndpointResponse.refreshToken,\n tokenSets: [\n createUpdatedTokenSet(audience, tokenEndpointResponse),\n ],\n internal: {\n sid: user?.sid as string,\n createdAt: Math.floor(Date.now() / 1000),\n },\n };\n }\n}\n\nexport function updateStateDataForConnectionTokenSet(\n options: AccessTokenForConnectionOptions,\n stateData: StateData,\n tokenEndpointResponse: TokenResponse\n) {\n stateData.connectionTokenSets = stateData.connectionTokenSets || [];\n\n const isNewTokenSet = !stateData.connectionTokenSets.some(\n (tokenSet) =>\n tokenSet.connection === options.connection && (!options.loginHint || tokenSet.loginHint === options.loginHint)\n );\n\n const connectionTokenSet = {\n connection: options.connection,\n loginHint: options.loginHint,\n accessToken: tokenEndpointResponse.accessToken,\n scope: tokenEndpointResponse.scope,\n expiresAt: tokenEndpointResponse.expiresAt,\n };\n\n const connectionTokenSets = isNewTokenSet\n ? [...stateData.connectionTokenSets, connectionTokenSet]\n : stateData.connectionTokenSets.map((tokenSet) =>\n tokenSet.connection === options.connection && (!options.loginHint || tokenSet.loginHint === options.loginHint)\n ? connectionTokenSet\n : tokenSet\n );\n\n return {\n ...stateData,\n connectionTokenSets,\n };\n}\n","import {\n AccessTokenForConnectionOptions,\n ConnectionTokenSet,\n GetAccessTokenOptions,\n LoginBackchannelOptions,\n LoginBackchannelResult,\n LogoutOptions,\n ServerClientOptions,\n SessionData,\n StartInteractiveLoginOptions,\n StartLinkUserOptions,\n StartUnlinkUserOptions,\n StateStore,\n TokenSet,\n TransactionData,\n TransactionStore,\n} from './types.js';\nimport {\n BackchannelLogoutError,\n MissingRequiredArgumentError,\n MissingSessionError,\n MissingTransactionError,\n} from './errors.js';\nimport { updateStateData, updateStateDataForConnectionTokenSet } from './state/utils.js';\nimport {\n TokenForConnectionError,\n AuthClient,\n AuthorizationDetails,\n TokenByRefreshTokenError,\n TokenByRefreshTokenOptions,\n} from '@auth0/auth0-auth-js';\nimport { compareScopes } from './utils.js';\nimport { getTelemetryConfig } from './telemetry.js';\n\nconst DEFAULT_SCOPES = 'openid profile email offline_access';\n\n/**\n * Ensures that the \"openid\" scope is always included in the scope string.\n *\n * @param scope - The scope provided by the user (optional)\n * @returns A scope string that includes \"openid\" if it was not already present.\n */\nfunction ensureOpenIdScope(scope?: string): string {\n if (!scope) {\n return DEFAULT_SCOPES;\n }\n\n const scopes = scope.split(' ');\n if (!scopes.includes('openid')) {\n scopes.unshift('openid');\n }\n\n return scopes.join(' ');\n}\n\nexport class ServerClient<TStoreOptions = unknown> {\n readonly #options: ServerClientOptions<TStoreOptions>;\n readonly #transactionStore: TransactionStore<TStoreOptions>;\n readonly #transactionStoreIdentifier: string;\n readonly #stateStore: StateStore<TStoreOptions>;\n readonly #stateStoreIdentifier: string;\n\n /**\n * The underlying `authClient` instance that can be used to interact with the Auth0 Authentication API.\n * Generally, you should prefer to use the higher-level methods exposed on the `ServerClient` instance.\n * \n * Important: the methods exposed on the `authClient` instance do not handle any session or state management.\n */\n readonly authClient: AuthClient;\n\n constructor(options: ServerClientOptions<TStoreOptions>) {\n this.#options = options;\n this.#stateStoreIdentifier = this.#options.stateIdentifier || '__a0_session';\n this.#transactionStoreIdentifier = this.#options.transactionIdentifier || '__a0_tx';\n this.#transactionStore = options.transactionStore;\n this.#stateStore = options.stateStore;\n\n if (!this.#options.stateStore) {\n throw new MissingRequiredArgumentError('stateStore');\n }\n\n if (!this.#options.transactionStore) {\n throw new MissingRequiredArgumentError('transactionStore');\n }\n\n this.authClient = new AuthClient({\n domain: this.#options.domain,\n clientId: this.#options.clientId,\n clientSecret: this.#options.clientSecret,\n clientAssertionSigningKey: this.#options.clientAssertionSigningKey,\n clientAssertionSigningAlg: this.#options.clientAssertionSigningAlg,\n authorizationParams: this.#options.authorizationParams,\n customFetch: this.#options.customFetch,\n useMtls: this.#options.useMtls,\n telemetry: getTelemetryConfig(this.#options.telemetry),\n });\n }\n\n /**\n * Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.\n * @param options Optional options used to configure the interactive login process.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {BuildAuthorizationUrlError} If there was an issue when building the Authorization URL.\n *\n * @returns A promise resolving to a URL object, representing the URL to redirect the user-agent to to request authorization at Auth0.\n */\n public async startInteractiveLogin(options?: StartInteractiveLoginOptions, storeOptions?: TStoreOptions) {\n const redirectUri = options?.authorizationParams?.redirect_uri ?? this.#options.authorizationParams?.redirect_uri;\n if (!redirectUri) {\n throw new MissingRequiredArgumentError('authorizationParams.redirect_uri');\n }\n\n const scope = ensureOpenIdScope(options?.authorizationParams?.scope ?? this.#options.authorizationParams?.scope);\n\n const { codeVerifier, authorizationUrl } = await this.authClient.buildAuthorizationUrl({\n pushedAuthorizationRequests: options?.pushedAuthorizationRequests,\n authorizationParams: {\n ...options?.authorizationParams,\n redirect_uri: redirectUri,\n scope,\n },\n });\n\n const transactionState: TransactionData = {\n audience: options?.authorizationParams?.audience ?? this.#options.authorizationParams?.audience,\n codeVerifier,\n };\n\n if (options?.appState) {\n transactionState.appState = options.appState;\n }\n\n await this.#transactionStore.set(this.#transactionStoreIdentifier, transactionState, false, storeOptions);\n\n return authorizationUrl;\n }\n\n /**\n * Completes the interactive login process.\n * Takes an URL, extract the Authorization Code flow query parameters and requests a token.\n * @param url The URl from which the query params should be extracted to exchange for a token.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {MissingTransactionError} When no transaction was found.\n * @throws {TokenByCodeError} If there was an issue requesting the access token.\n *\n * @returns A promise resolving to an object, containing the original appState (if present) and the authorizationDetails (when RAR was used).\n */\n public async completeInteractiveLogin<TAppState = unknown>(url: URL, storeOptions?: TStoreOptions) {\n const transactionData = await this.#transactionStore.get(this.#transactionStoreIdentifier, storeOptions);\n\n if (!transactionData) {\n throw new MissingTransactionError();\n }\n\n const tokenEndpointResponse = await this.authClient.getTokenByCode(url, {\n codeVerifier: transactionData.codeVerifier,\n });\n\n const existingStateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n const stateData = updateStateData(transactionData.audience ?? 'default', existingStateData, tokenEndpointResponse);\n\n await this.#stateStore.set(this.#stateStoreIdentifier, stateData, true, storeOptions);\n await this.#transactionStore.delete(this.#transactionStoreIdentifier, storeOptions);\n\n return { appState: transactionData.appState, authorizationDetails: tokenEndpointResponse.authorizationDetails } as {\n appState?: TAppState;\n authorizationDetails?: AuthorizationDetails[];\n };\n }\n\n /**\n * Starts the user linking process, and returns a URL to redirect the user-agent to to request authorization at Auth0.\n * @param options Options used to configure the user linking process.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {MissingSessionError} If there is no active session.\n * @throws {BuildLinkUserUrlError} If there was an issue when building the Authorization URL.\n *\n * @returns A promise resolving to a URL object, representing the URL to redirect the user-agent to to request authorization at Auth0.\n */\n public async startLinkUser(options: StartLinkUserOptions, storeOptions?: TStoreOptions) {\n const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n if (!stateData || !stateData.idToken) {\n throw new MissingSessionError(\n 'Unable to start the user linking process without a logged in user. Ensure to login using the SDK before starting the user linking process.'\n );\n }\n\n const { linkUserUrl, codeVerifier } = await this.authClient.buildLinkUserUrl({\n connection: options.connection,\n connectionScope: options.connectionScope,\n idToken: stateData.idToken,\n authorizationParams: options.authorizationParams,\n });\n\n const transactionState: TransactionData = {\n audience: options?.authorizationParams?.audience ?? this.#options.authorizationParams?.audience,\n codeVerifier,\n };\n\n if (options?.appState) {\n transactionState.appState = options.appState;\n }\n\n await this.#transactionStore.set(this.#transactionStoreIdentifier, transactionState, false, storeOptions);\n\n return linkUserUrl;\n }\n\n /**\n * Completes the user linking process.\n * Takes an URL, extract the Authorization Code flow query parameters and requests a token.\n * @param url The URl from which the query params should be extracted to exchange for a token.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {MissingTransactionError} When no transaction was found.\n * @throws {TokenByCodeError} If there was an issue requesting the access token.\n *\n * @returns A promise resolving to an object, containing the original appState (if present).\n */\n public async completeLinkUser<TAppState = unknown>(url: URL, storeOptions?: TStoreOptions) {\n // In order to complete the link user flow, we need to exchange the code for a token in the same\n // way as we do for the interactive login flow.\n const result = await this.completeInteractiveLogin<TAppState>(url, storeOptions);\n\n // As we currently do not support RAR when starting the user linking flow, we will ommit it from being returned as optional altogether.\n return {\n appState: result.appState,\n };\n }\n\n /**\n * Starts the user unlinking process, and returns a URL to redirect the user-agent to to initialize user unlinking at Auth0.\n * @param options Options used to configure the user unlinking process.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {MissingSessionError} If there is no active session.\n * @throws {BuildUnlinkUserUrlError} If there was an issue when building the User Unlinking URL.\n *\n * @returns A promise resolving to a URL object, representing the URL to redirect the user-agent to to request authorization at Auth0.\n */\n public async startUnlinkUser(options: StartUnlinkUserOptions, storeOptions?: TStoreOptions) {\n const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n if (!stateData || !stateData.idToken) {\n throw new MissingSessionError(\n 'Unable to start the user unlinking process without a logged in user. Ensure to login using the SDK before starting the user unlinking process.'\n );\n }\n\n const { unlinkUserUrl, codeVerifier } = await this.authClient.buildUnlinkUserUrl({\n connection: options.connection,\n idToken: stateData.idToken,\n authorizationParams: options.authorizationParams,\n });\n\n const transactionState: TransactionData = {\n audience: options?.authorizationParams?.audience ?? this.#options.authorizationParams?.audience,\n codeVerifier,\n };\n\n if (options?.appState) {\n transactionState.appState = options.appState;\n }\n\n await this.#transactionStore.set(this.#transactionStoreIdentifier, transactionState, false, storeOptions);\n\n return unlinkUserUrl;\n }\n\n /**\n * Completes the user unlinking process.\n * Takes an URL, extract the Authorization Code flow query parameters and requests a token.\n * @param url The URl from which the query params should be extracted to exchange for a token.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {MissingTransactionError} When no transaction was found.\n * @throws {TokenByCodeError} If there was an issue requesting the access token.\n *\n * @returns A promise resolving to an object, containing the original appState (if present).\n */\n public async completeUnlinkUser<TAppState = unknown>(url: URL, storeOptions?: TStoreOptions) {\n // In order to complete the link user flow, we need to exchange the code for a token in the same\n // way as we do for the interactive login flow.\n const result = await this.completeInteractiveLogin<TAppState>(url, storeOptions);\n\n // As we currently do not support RAR when starting the user unlinking flow, we will ommit it from being returned as optional altogether.\n return {\n appState: result.appState,\n };\n }\n\n /**\n * Logs in using Client-Initiated Backchannel Authentication.\n *\n * Using Client-Initiated Backchannel Authentication requires the feature to be enabled in the Auth0 dashboard.\n * @see https://auth0.com/docs/get-started/authentication-and-authorization-flow/client-initiated-backchannel-authentication-flow\n * @param options Options used to configure the backchannel login process.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {BackchannelAuthenticationError} If there was an issue when doing backchannel authentication.\n *\n * @returns A promise resolving to an object, containing the authorizationDetails (when RAR was used).\n */\n public async loginBackchannel(\n options: LoginBackchannelOptions,\n storeOptions?: TStoreOptions\n ): Promise<LoginBackchannelResult> {\n const scope = ensureOpenIdScope(options.authorizationParams?.scope ?? this.#options.authorizationParams?.scope);\n\n const tokenEndpointResponse = await this.authClient.backchannelAuthentication({\n bindingMessage: options.bindingMessage,\n loginHint: options.loginHint,\n authorizationParams: {\n ...options.authorizationParams,\n scope,\n },\n });\n\n const existingStateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n const stateData = updateStateData(\n this.#options.authorizationParams?.audience ?? 'default',\n existingStateData,\n tokenEndpointResponse\n );\n\n await this.#stateStore.set(this.#stateStoreIdentifier, stateData, true, storeOptions);\n\n return {\n authorizationDetails: tokenEndpointResponse.authorizationDetails,\n };\n }\n\n /**\n * Retrieves the user from the store, or undefined if no user found.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n * @returns The user, or undefined if no user found in the store.\n */\n public async getUser(storeOptions?: TStoreOptions) {\n const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n return stateData?.user;\n }\n\n /**\n * Retrieve the user session from the store, or undefined if no session found.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n * @returns The sessionm or undefined if no session found in the store.\n */\n public async getSession(storeOptions?: TStoreOptions): Promise<SessionData | undefined> {\n const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n if (stateData) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { internal, ...sessionData } = stateData;\n return sessionData;\n }\n }\n\n // TEMPORARY: Overloads for backwards compatibility in minor version.\n // In the next major version, remove the first overload and use only the second signature.\n public async getAccessToken(storeOptions?: TStoreOptions): Promise<TokenSet>;\n public async getAccessToken(options: GetAccessTokenOptions, storeOptions?: TStoreOptions): Promise<TokenSet>;\n /**\n * Retrieves the access token from the store, or calls Auth0 when the access token is expired and a refresh token is available in the store.\n * Also updates the store when a new token was retrieved from Auth0.\n *\n * @param options Optional options for requesting specific audience/scope.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {TokenByRefreshTokenError} If the refresh token was not found or there was an issue requesting the access token.\n *\n * @returns The Token Set, containing the access token, as well as additional information.\n */\n public async getAccessToken(\n tokenOptionsOrStoreOptions?: GetAccessTokenOptions | TStoreOptions,\n storeOptions?: TStoreOptions\n ): Promise<TokenSet> {\n // TEMPORARY: Detect if first arg is GetAccessTokenOptions (has audience/scope)\n // or storeOptions (old behavior). Remove in next major version.\n const hasTokenOptions =\n // If second arg exists, first arg must be GetAccessTokenOptions\n storeOptions !== undefined ||\n // OR if first arg has audience/scope properties\n (tokenOptionsOrStoreOptions &&\n typeof tokenOptionsOrStoreOptions === 'object' &&\n ('audience' in tokenOptionsOrStoreOptions || 'scope' in tokenOptionsOrStoreOptions));\n\n const [resolvedOptions, resolvedStoreOptions] = hasTokenOptions\n ? [tokenOptionsOrStoreOptions as GetAccessTokenOptions, storeOptions]\n : [undefined, tokenOptionsOrStoreOptions as TStoreOptions];\n\n const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, resolvedStoreOptions);\n const audience = resolvedOptions?.audience ?? this.#options.authorizationParams?.audience ?? 'default';\n const scope = resolvedOptions?.scope ?? this.#options.authorizationParams?.scope;\n\n const tokenSet = stateData?.tokenSets.find(\n (tokenSet) => tokenSet.audience === audience && (!scope || compareScopes(tokenSet.scope, scope))\n );\n\n if (tokenSet && tokenSet.expiresAt > Date.now() / 1000) {\n return tokenSet;\n }\n\n if (!stateData?.refreshToken) {\n throw new TokenByRefreshTokenError(\n 'The access token has expired and a refresh token was not provided. The user needs to re-authenticate.'\n );\n }\n\n const tokenByRefreshTokenOptions: TokenByRefreshTokenOptions = {\n refreshToken: stateData.refreshToken,\n ...(hasTokenOptions && { audience, scope }),\n };\n\n const tokenEndpointResponse = await this.authClient.getTokenByRefreshToken(tokenByRefreshTokenOptions);\n const existingStateData = await this.#stateStore.get(this.#stateStoreIdentifier, resolvedStoreOptions);\n const updatedStateData = updateStateData(audience, existingStateData, tokenEndpointResponse);\n\n await this.#stateStore.set(this.#stateStoreIdentifier, updatedStateData, false, resolvedStoreOptions);\n\n return {\n accessToken: tokenEndpointResponse.accessToken,\n scope: tokenEndpointResponse.scope,\n expiresAt: tokenEndpointResponse.expiresAt,\n audience: audience,\n };\n }\n\n /**\n * Retrieves an access token for a connection.\n *\n * This method attempts to obtain an access token for a specified connection.\n * It first checks if a refresh token exists in the store.\n * If no refresh token is found, it throws an `AccessTokenForConnectionError` indicating\n * that the refresh token was not found.\n *\n * @param options - Options for retrieving an access token for a connection.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {TokenForConnectionError} If the refresh token was not found or there was an issue requesting the access token.\n *\n * @returns The Connection Token Set, containing the access token for the connection, as well as additional information.\n */\n public async getAccessTokenForConnection(options: AccessTokenForConnectionOptions, storeOptions?: TStoreOptions): Promise<ConnectionTokenSet> {\n const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);\n\n const connectionTokenSet = stateData?.connectionTokenSets?.find(\n (tokenSet) => tokenSet.connection === options.connection\n );\n\n if (connectionTokenSet && connectionTokenSet.expiresAt > Date.now() / 1000) {\n return connectionTokenSet;\n }\n\n if (!stateData?.refreshToken) {\n throw new TokenForConnectionError(\n 'A refresh token was not found but is required to be able to retrieve an access token for a connection.'\n );\n }\n\n const tokenEndpointResponse = await this.authClient.getTokenForConnection({\n connection: options.connection,\n loginHint: options.loginHint,\n refreshToken: stateData.refreshToken,\n });\n\n const updatedStateData = updateStateDataForConnectionTokenSet(options, stateData, tokenEndpointResponse);\n\n await this.#stateStore.set(this.#stateStoreIdentifier, updatedStateData, false, storeOptions);\n\n return {\n accessToken: tokenEndpointResponse.accessToken,\n scope: tokenEndpointResponse.scope,\n expiresAt: tokenEndpointResponse.expiresAt,\n connection: options.connection,\n loginHint: options.loginHint,\n };\n }\n\n /**\n * Logs the user out and returns a URL to redirect the user-agent to after they log out.\n * @param options Options used to configure the logout process.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n * @returns {URL}\n */\n public async logout(options: LogoutOptions, storeOptions?: TStoreOptions) {\n await this.#stateStore.delete(this.#stateStoreIdentifier, storeOptions);\n\n return this.authClient.buildLogoutUrl(options);\n }\n\n /**\n * Handles the backchannel logout process by verifying the logout token and deleting the session from the store if the logout token was considered valid.\n * @param logoutToken The logout token to verify and use to delete the session from the store.\n * @param storeOptions Optional options used to pass to the Transaction and State Store.\n *\n * @throws {BackchannelLogoutError} If the logout token is missing.\n * @throws {VerifyLogoutTokenError} If the logout token is invalid.\n */\n public async handleBackchannelLogout(logoutToken: string, storeOptions?: TStoreOptions) {\n if (!logoutToken) {\n throw new BackchannelLogoutError('Missing Logout Token');\n }\n\n const logoutTokenClaims = await this.authClient.verifyLogoutToken({ logoutToken });\n\n await this.#stateStore.deleteByLogoutToken(logoutTokenClaims, storeOptions);\n }\n}\n","/**\n * Compares two sets of scopes to determine if all required scopes are present in the provided scopes.\n * @param scopes Scopes to compare\n * @param requiredScopes Scopes required to be present in the scopes\n * @returns True if all required scopes are present in the scopes, false otherwise\n */\nexport const compareScopes = (scopes: string | undefined, requiredScopes: string | undefined) => {\n // When the scopes and requiredScopes are exactly the same, return true\n // This handles cases where both are empty or undefined or both are the same string\n if (scopes === requiredScopes) {\n return true;\n }\n\n if (!scopes || !requiredScopes) {\n return false;\n }\n\n const scopesSet = new Set(scopes.trim().split(' ').filter(Boolean));\n const requiredScopesArray = requiredScopes.trim().split(' ').filter(Boolean);\n\n return requiredScopesArray.every((scope) => scopesSet.has(scope));\n};\n","import { TelemetryConfig } from '@auth0/auth0-auth-js';\n\n// These constants are injected at build time via tsup\ndeclare const __AUTH0_SERVER_JS_PACKAGE_NAME__: string;\ndeclare const __AUTH0_SERVER_JS_PACKAGE_VERSION__: string;\n\nexport function getTelemetryConfig(config?: TelemetryConfig): TelemetryConfig {\n if (config?.enabled === false) {\n return config;\n }\n\n return {\n enabled: true,\n name: config?.name ?? __AUTH0_SERVER_JS_PACKAGE_NAME__,\n version: config?.version ?? __AUTH0_SERVER_JS_PACKAGE_VERSION__,\n };\n}\n","import { EncryptJWT, jwtDecrypt, errors } from 'jose';\nimport type { JWTPayload } from 'jose';\nimport { InvalidConfigurationError } from '../errors.js';\n\nconst ENC = 'A256CBC-HS512';\nconst ALG = 'dir';\nconst DIGEST = 'SHA-256';\nconst BIT_LENGTH = 512;\nconst HKDF_INFO = 'derived cookie encryption secret';\n\nlet encoder: TextEncoder | undefined;\n\n/**\n * Type guard to determine if an error is a decryption-related error.\n * Decryption errors (JWEDecryptionFailed, JWEInvalid) indicate issues with the encryption key or data format.\n * These are distinct from claim validation errors (like expiration), which indicate a valid token with invalid claims.\n * @param e - The error thrown during decryption\n * @returns True if the error is a decryption error, false otherwise\n */\nexport function isDecryptionError(e: unknown): e is Error {\n return e instanceof errors.JWEDecryptionFailed || e instanceof errors.JWEInvalid;\n}\n\nasync function deriveEncryptionSecret(secret: string, salt: string, kid: string) {\n encoder ||= new TextEncoder();\n const key = await crypto.subtle.importKey('raw', encoder.encode(secret), 'HKDF', false, ['deriveBits']);\n\n return new Uint8Array(\n await crypto.subtle.deriveBits(\n {\n name: 'HKDF',\n hash: DIGEST,\n info: encoder.encode(HKDF_INFO),\n salt: encoder.encode(`${salt}${kid}`),\n } as HkdfParams,\n key,\n BIT_LENGTH\n )\n );\n}\n\n/**\n * Encrypts a payload using the provided secret and salt, with an expiration time.\n * @param payload The payload to encrypt.\n * @param secret The secret to use for encryption.\n * @param salt The salt to use for encryption.\n * @param expiration The expiration time for the encrypted payload.\n * @returns The encrypted payload.\n */\nasync function _encrypt(payload: JWTPayload, secret: string, salt: string, expiration: number) {\n const kid = crypto.randomUUID();\n const encryptionSecret = await deriveEncryptionSecret(secret, salt, kid);\n\n return await new EncryptJWT(payload)\n .setProtectedHeader({ enc: ENC, alg: ALG, kid: kid })\n .setExpirationTime(expiration)\n .encrypt(encryptionSecret);\n}\n\n/**\n * Encrypts a payload using the provided secret and salt, with an expiration time.\n * The secret can be a single string or an array of strings for secret rotation support.\n * When using an array of secrets, only the first one is used for encryption (all secrets are tried for decryption).\n * @param payload The payload to encrypt.\n * @param secret The secret(s) to use for encryption. Can be a single string or an array of strings for secret rotation support.\n * @param salt The salt to use for encryption.\n * @param expiration The expiration time for the encrypted payload.\n * @returns The encrypted payload.\n */\nexport async function encrypt(payload: JWTPayload, secret: string | string[], salt: string, expiration: number) {\n if (typeof secret === 'string') {\n return await _encrypt(payload, secret, salt, expiration);\n } else {\n // For encryption, we only use the newest secret, as the old secrets are only used for backward compatibility during decryption.\n const [newSecret] = secret;\n\n if (!newSecret) {\n throw new InvalidConfigurationError('At least one secret must be provided');\n }\n\n return await _encrypt(payload, newSecret, salt, expiration);\n }\n}\n\n/**\n * Decrypts an encrypted payload using the provided secret(s) and salt.\n * @param value The encrypted payload to decrypt.\n * @param secret The secret to use for decryption.\n * @param salt The salt to use for decryption.\n * @returns The decrypted payload.\n */\nexport async function _decrypt<T>(value: string, secret: string, salt: string) {\n const res = await jwtDecrypt<T>(\n value,\n async (protectedHeader) => {\n // This error shouldn't happen, as we always set a kid.\n // However, leaving this here as a safety net.\n if (!protectedHeader.kid) {\n throw new Error('Missing \"kid\" in JWE header');\n }\n\n return await deriveEncryptionSecret(secret, salt, protectedHeader.kid);\n },\n { clockTolerance: 15 }\n );\n return res.payload;\n}\n\n/**\n * Decrypts an encrypted payload using the provided secret(s) and salt.\n * The secret can be a single string or an array of strings for secret rotation support.\n * When using an array of secrets, the function will try to decrypt with each secret in order until it succeeds or exhausts all options.\n * Only decryption-related errors (JWEDecryptionFailed, JWEInvalid) will trigger fallback to old secrets.\n * Other errors (like expiration) will be thrown immediately.\n * @param value The encrypted payload to decrypt.\n * @param secret The secret(s) to use for decryption. Can be a single string or an array of strings for secret rotation support.\n * @param salt The salt to use for decryption.\n * @returns The decrypted payload.\n */\nexport async function decrypt<T>(value: string, secret: string | string[], salt: string) {\n if (typeof secret === 'string') {\n return await _decrypt<T>(value, secret, salt);\n } else {\n const [newSecret, ...oldSecrets] = secret;\n\n if (!newSecret) {\n throw new InvalidConfigurationError('At least one secret must be provided');\n }\n\n let firstError: Error | undefined;\n\n try {\n return await _decrypt<T>(value, newSecret, salt);\n } catch (err) {\n firstError = err as Error;\n\n // Only try old secrets if this is a decryption-related error\n // Other errors (like expiration) should be thrown immediately\n if (!isDecryptionError(err)) {\n throw firstError;\n }\n\n for (const oldSecret of oldSecrets) {\n try {\n return await _decrypt(value, oldSecret, salt);\n } catch (fallbackErr) {\n // Only ignore decryption errors with old secrets and continue trying with the next one\n // If it's a different type of error, throw it\n if (!isDecryptionError(fallbackErr)) {\n throw fallbackErr;\n }\n }\n }\n\n // If we've exhausted all secrets and still can't decrypt, throw the original error.\n throw firstError;\n }\n }\n}\n","import type { EncryptedStoreOptions, AbstractDataStore } from '../types.js';\nimport { encrypt, decrypt, isDecryptionError } from '../encryption/index.js';\nimport { JWTPayload } from 'jose';\n\n/**\n * Abstract class that can be used to implement an Encrypted JWT State Store, using the 'A256CBC-HS512' encryption algorithm.\n */\nexport abstract class AbstractStore<TData extends JWTPayload, TStoreOptions = unknown> implements AbstractDataStore<TData, TStoreOptions>\n{\n protected readonly options: EncryptedStoreOptions;\n\n constructor(options: EncryptedStoreOptions) {\n this.options = options;\n }\n\n abstract set(identifier: string, state: TData, removeIfExists?: boolean, options?: TStoreOptions | undefined): Promise<void>;\n abstract get(identifier: string, options?: TStoreOptions | undefined): Promise<TData | undefined>;\n abstract delete(identifier: string, options?: TStoreOptions | undefined): Promise<void>;\n\n protected async encrypt<TData extends JWTPayload>(identifier: string, stateData: TData, expiration: number) {\n return await encrypt(stateData, this.options.secret, identifier, expiration);\n }\n\n protected async decrypt<TData>(identifier: string, encryptedStateData: string) {\n try {\n return (await decrypt(encryptedStateData, this.options.secret, identifier)) as TData;\n } catch (e: unknown){\n // When the error is a decryption failure, we want to ignore it and return undefined, as this likely means the session has expired or the data is invalid.\n if (isDecryptionError(e)) {\n return;\n }\n\n throw e;\n }\n }\n}\n","import type { StateData, EncryptedStoreOptions, StateStore, LogoutTokenClaims } from '../types.js';\nimport { AbstractStore } from './abstract-store.js';\n\n/**\n * Abstract class that can be used to implement an Encrypted JWT State Store, using the 'A256CBC-HS512' encryption algorithm.\n */\nexport abstract class AbstractStateStore<TStoreOptions = unknown> extends AbstractStore<StateData, TStoreOptions> implements StateStore<TStoreOptions> {\n constructor(options: EncryptedStoreOptions) {\n super(options);\n }\n\n abstract deleteByLogoutToken(claims: LogoutTokenClaims, options?: TStoreOptions | undefined): Promise<void>;\n}","import type { EncryptedStoreOptions, TransactionData, TransactionStore } from '../types.js';\nimport { AbstractStore } from './abstract-store.js';\n\n/**\n * Abstract class that can be used to implement an Encrypted JWT Transaction Store, using the 'A256CBC-HS512' encryption algorithm.\n */\nexport abstract class AbstractTransactionStore<TStoreOptions = unknown> extends AbstractStore<TransactionData, TStoreOptions> implements TransactionStore<TStoreOptions> {\n constructor(options: EncryptedStoreOptions) {\n super(options);\n }\n}","import type { EncryptedStoreOptions, TransactionData } from './../types.js';\nimport { AbstractTransactionStore } from './abstract-transaction-store.js';\nimport type { CookieHandler, CookieSerializeOptions } from './cookie-handler.js';\n\nexport class CookieTransactionStore<TStoreOptions> extends AbstractTransactionStore<TStoreOptions> {\n readonly #cookieHandler: CookieHandler<TStoreOptions>;\n\n constructor(options: EncryptedStoreOptions, cookieHandler: CookieHandler<TStoreOptions>) {\n super(options);\n this.#cookieHandler = cookieHandler;\n }\n\n async set(\n identifier: string,\n transactionData: TransactionData,\n removeIfExists?: boolean,\n options?: TStoreOptions\n ): Promise<void> { \n const maxAge = 60 * 60;\n const cookieOpts: CookieSerializeOptions = { httpOnly: true, sameSite: 'lax', path: '/', maxAge };\n const expiration = Math.floor(Date.now() / 1000 + maxAge);\n const encryptedStateData = await this.encrypt(identifier, transactionData, expiration);\n\n this.#cookieHandler.setCookie(identifier, encryptedStateData, cookieOpts, options);\n }\n\n async get(identifier: string, options?: TStoreOptions): Promise<TransactionData | undefined> {\n const cookieValue = this.#cookieHandler.getCookie(identifier, options);\n\n if (cookieValue) {\n return await this.decrypt(identifier, cookieValue);\n }\n }\n\n async delete(identifier: string, options?: TStoreOptions | undefined): Promise<void> {\n this.#cookieHandler.deleteCookie(identifier, options);\n }\n}\n","import { AbstractStateStore } from './abstract-state-store.js';\nimport type { EncryptedStoreOptions, SessionConfiguration } from '../types.js';\n\nexport abstract class AbstractSessionStore<TStoreOptions> extends AbstractStateStore<TStoreOptions> {\n readonly #rolling: boolean;\n readonly #absoluteDuration: number;\n readonly #inactivityDuration: number;\n\n constructor(options: SessionConfiguration & EncryptedStoreOptions) {\n super(options);\n\n this.#rolling = options.rolling ?? true;\n this.#absoluteDuration = options.absoluteDuration ?? 60 * 60 * 24 * 3;\n this.#inactivityDuration = options.inactivityDuration ?? 60 * 60 * 24 * 1;\n }\n\n /**\n * calculateMaxAge calculates the max age of the session based on createdAt and the rolling and absolute durations.\n */\n protected calculateMaxAge(createdAt: number) {\n if (!this.#rolling) {\n return this.#absoluteDuration;\n }\n\n const now = (Date.now() / 1000) | 0;\n const expiresAt = Math.min(now + this.#inactivityDuration, createdAt + this.#absoluteDuration);\n const maxAge = expiresAt - now;\n\n return maxAge > 0 ? maxAge : 0;\n }\n}","import type {\n EncryptedStoreOptions,\n LogoutTokenClaims,\n SessionConfiguration,\n SessionCookieOptions,\n SessionStore,\n StateData,\n} from '../types.js';\nimport { AbstractSessionStore } from './abstract-session-store.js';\nimport type { CookieHandler, CookieSerializeOptions } from './cookie-handler.js';\n\nexport interface StatefulStateStoreOptions<TStoreOptions> extends EncryptedStoreOptions {\n store: SessionStore<TStoreOptions>;\n}\n\nconst generateId = () => {\n const bytes = new Uint8Array(16);\n crypto.getRandomValues(bytes);\n return Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n};\n\nexport class StatefulStateStore<TStoreOptions> extends AbstractSessionStore<TStoreOptions> {\n readonly #store: SessionStore<TStoreOptions>;\n readonly #cookieOptions: SessionCookieOptions | undefined;\n readonly #cookieHandler: CookieHandler<TStoreOptions>;\n\n constructor(\n options: StatefulStateStoreOptions<TStoreOptions> & SessionConfiguration,\n cookieHandler: CookieHandler<TStoreOptions>\n ) {\n super(options);\n\n this.#store = options.store;\n this.#cookieOptions = options.cookie;\n this.#cookieHandler = cookieHandler;\n }\n\n async set(\n identifier: string,\n stateData: StateData,\n removeIfExists?: boolean,\n options?: TStoreOptions | undefined\n ): Promise<void> {\n let sessionId = await this.getSessionId(identifier, options);\n\n // if this is a new session created by a new login we need to remove the old session\n // from the store and regenerate the session ID to prevent session fixation.\n if (sessionId && removeIfExists) {\n await this.#store.delete(sessionId);\n sessionId = generateId();\n }\n\n sessionId ??= generateId();\n\n const maxAge = this.calculateMaxAge(stateData.internal.createdAt);\n const cookieOpts = this.#getCookieOptions({\n maxAge,\n });\n const expiration = Date.now() / 1000 + maxAge;\n const encryptedStateData = await this.encrypt<{ id: string }>(\n identifier,\n {\n id: sessionId,\n },\n expiration\n );\n\n await this.#store.set(sessionId, stateData);\n\n this.#cookieHandler.setCookie(identifier, encryptedStateData, cookieOpts, options);\n }\n\n async get(identifier: string, options?: TStoreOptions | undefined): Promise<StateData | undefined> {\n const sessionId = await this.getSessionId(identifier, options);\n\n if (sessionId) {\n const stateData = await this.#store.get(sessionId);\n\n // If we have a session cookie, but no `stateData`, we should remove the cookie.\n if (!stateData) {\n this.#cookieHandler.deleteCookie(identifier, options, this.#getCookieOptions());\n }\n\n return stateData;\n }\n }\n\n async delete(identifier: string, options?: TStoreOptions | undefined): Promise<void> {\n const sessionId = await this.getSessionId(identifier, options);\n\n if (sessionId) {\n await this.#store.delete(sessionId);\n }\n\n this.#cookieHandler.deleteCookie(identifier, options, this.#getCookieOptions());\n }\n\n private async getSessionId(identifier: string, options?: TStoreOptions) {\n const cookieValue = this.#cookieHandler.getCookie(identifier, options);\n if (cookieValue) {\n const sessionCookie = await this.decrypt<{ id: string }>(identifier, cookieValue);\n \n if (sessionCookie) {\n return sessionCookie.id;\n }\n }\n }\n\n deleteByLogoutToken(claims: LogoutTokenClaims, options?: TStoreOptions | undefined): Promise<void> {\n return this.#store.deleteByLogoutToken(claims, options);\n }\n\n #getCookieOptions(partial?: Partial<CookieSerializeOptions>): CookieSerializeOptions {\n return {\n httpOnly: true,\n sameSite: this.#cookieOptions?.sameSite ?? 'lax',\n path: this.#cookieOptions?.path ?? '/',\n secure: this.#cookieOptions?.secure ?? true,\n ...partial,\n };\n }\n}\n","import type { EncryptedStoreOptions, SessionConfiguration, SessionCookieOptions, StateData } from '../types.js';\nimport { AbstractSessionStore } from './abstract-session-store.js';\nimport type { CookieHandler, CookieSerializeOptions } from './cookie-handler.js';\n\nexport class StatelessStateStore<TStoreOptions> extends AbstractSessionStore<TStoreOptions> {\n readonly #cookieOptions: SessionCookieOptions | undefined;\n readonly #cookieHandler: CookieHandler<TStoreOptions>;\n\n constructor(options: SessionConfiguration & EncryptedStoreOptions, cookieHandler: CookieHandler<TStoreOptions>) {\n super(options);\n\n this.#cookieOptions = options.cookie;\n this.#cookieHandler = cookieHandler;\n }\n\n async set(\n identifier: string,\n stateData: StateData,\n removeIfExists?: boolean,\n options?: TStoreOptions | undefined\n ): Promise<void> {\n const maxAge = this.calculateMaxAge(stateData.internal.createdAt);\n const cookieOpts = this.#getCookieOptions({\n maxAge,\n });\n const expiration = Math.floor(Date.now() / 1000 + maxAge);\n const encryptedStateData = await this.encrypt(identifier, stateData, expiration);\n\n const chunkSize = 3072;\n const chunkCount = Math.ceil(encryptedStateData.length / chunkSize);\n const chunks = [...Array(chunkCount).keys()].map((i) => ({\n value: encryptedStateData.substring(i * chunkSize, (i + 1) * chunkSize),\n name: `${identifier}.${i}`,\n }));\n\n chunks.forEach((chunk) => {\n this.#cookieHandler.setCookie(chunk.name, chunk.value, cookieOpts, options);\n });\n\n const existingCookieKeys = this.getCookieKeys(identifier, options);\n const cookieKeysToRemove = existingCookieKeys.filter((key) => !chunks.some((chunk) => chunk.name === key));\n cookieKeysToRemove.forEach((key) => {\n this.#cookieHandler.deleteCookie(key, options, cookieOpts);\n });\n }\n\n async get(identifier: string, options?: TStoreOptions | undefined): Promise<StateData | undefined> {\n const cookieKeys = this.getCookieKeys(identifier, options);\n const encryptedStateData = cookieKeys\n .map((key) => ({\n index: parseInt(key.split('.')[1] as string, 10),\n value: this.#cookieHandler.getCookie(key, options),\n }))\n .sort((a, b) => a.index - b.index)\n .map((item) => item.value)\n .join('');\n\n if (encryptedStateData) {\n return await this.decrypt(identifier, encryptedStateData);\n }\n }\n\n async delete(identifier: string, options?: TStoreOptions | undefined): Promise<void> {\n const cookieKeys = this.getCookieKeys(identifier, options);\n for (const key of cookieKeys) {\n this.#cookieHandler.deleteCookie(key, options, this.#getCookieOptions());\n }\n }\n\n deleteByLogoutToken(): Promise<void> {\n throw new Error(\n 'Backchannel logout is not available when using Stateless Storage. Use Stateful Storage by providing a `sessionStore`'\n );\n }\n\n private getCookieKeys(identifier: string, options?: TStoreOptions): string[] {\n return Object.keys(this.#cookieHandler.getCookies(options)).filter((key) => key.startsWith(identifier));\n }\n\n #getCookieOptions(partial?: Partial<CookieSerializeOptions>): CookieSerializeOptions {\n return {\n httpOnly: true,\n sameSite: this.#cookieOptions?.sameSite ?? 'lax',\n path: this.#cookieOptions?.path ?? '/',\n secure: this.#cookieOptions?.secure ?? true,\n ...partial,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,0BAAN,cAAsC,MAAM;AAAA,EAC1C,OAAe;AAAA,EAEtB,YAAY,SAAkB;AAC5B,UAAM,WAAW,6BAA6B;AAC9C,SAAK,OAAO;AAAA,EACd;AACF;AAMO,IAAM,yBAAN,cAAqC,MAAM;AAAA,EACzC,OAAe;AAAA,EAEtB,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,qBAAN,cAAiC,MAAM;AAAA,EACrC,OAAe;AAAA,EAEtB,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,+BAAN,cAA2C,MAAM;AAAA,EAC/C,OAAe;AAAA,EAEtB,YAAY,UAAkB;AAC5B,UAAM,iBAAiB,QAAQ,qCAAqC;AACpE,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EACtC,OAAe;AAAA,EAEtB,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,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;","names":["tokenSet"]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- import { AuthorizationDetails, AuthClient } from '@auth0/auth0-auth-js';
1
+ import { AuthorizationDetails, TelemetryConfig, AuthClient } from '@auth0/auth0-auth-js';
2
+ export { TelemetryConfig } from '@auth0/auth0-auth-js';
2
3
  import { JWTPayload } from 'jose';
3
4
 
4
5
  interface ServerClientOptions<TStoreOptions = unknown> {
@@ -22,6 +23,11 @@ interface ServerClientOptions<TStoreOptions = unknown> {
22
23
  * When set to `true`, using a `customFetch` is required.
23
24
  */
24
25
  useMtls?: boolean;
26
+ /**
27
+ * Optional telemetry configuration.
28
+ * Telemetry is enabled by default and sends the Auth0-Client header with package name and version.
29
+ */
30
+ telemetry?: TelemetryConfig;
25
31
  }
26
32
  interface UserClaims {
27
33
  sub: string;
@@ -89,7 +95,11 @@ interface StateStore<TStoreOptions = unknown> extends AbstractDataStore<StateDat
89
95
  interface TransactionStore<TStoreOptions = unknown> extends AbstractDataStore<TransactionData, TStoreOptions> {
90
96
  }
91
97
  interface EncryptedStoreOptions {
92
- secret: string;
98
+ /**
99
+ * The secret(s) to use for encryption and decryption. Can be a single string or an array of strings for secret rotation support.
100
+ * When using an array of secrets, the first one is used for encryption, while all secrets are tried, in-order, for decryption.
101
+ */
102
+ secret: string | string[];
93
103
  }
94
104
  interface StartInteractiveLoginOptions<TAppState = unknown> {
95
105
  pushedAuthorizationRequests?: boolean;
@@ -110,6 +120,25 @@ interface AccessTokenForConnectionOptions {
110
120
  connection: string;
111
121
  loginHint?: string;
112
122
  }
123
+ /**
124
+ * Options for retrieving an access token with MRRT support.
125
+ * Allows requesting tokens for specific audiences and scopes at runtime.
126
+ */
127
+ interface GetAccessTokenOptions {
128
+ /**
129
+ * Optional audience for the requested access token.
130
+ * If not provided, falls back to configuration audience or 'default'.
131
+ * @example 'https://api.example.com'
132
+ */
133
+ audience?: string;
134
+ /**
135
+ * Optional scope for the requested access token.
136
+ * If not provided, falls back to configuration scope.
137
+ * Space-separated scope string.
138
+ * @example 'read:data write:data'
139
+ */
140
+ scope?: string;
141
+ }
113
142
  interface LogoutOptions {
114
143
  returnTo: string;
115
144
  }
@@ -180,6 +209,20 @@ interface SessionCookieOptions {
180
209
  * Default: depends on the protocol of the application's base URL. If the protocol is `https`, then `true`, otherwise `false`.
181
210
  */
182
211
  secure?: boolean;
212
+ /**
213
+ * The path attribute of the session cookie.
214
+ *
215
+ * Default: `/`.
216
+ *
217
+ * @remarks
218
+ * Changing the cookie path will cause existing cookies to behave differently:
219
+ *
220
+ * - If the cookie path is currently "/" (which is the default) and you change it to "/something", existing cookies (using "/" as the path) will be picked up when using "/something", but also for anything outside of "/something", additionally logout will not correctly delete the cookie.
221
+ * - If the cookiepath is "/something" and you change it to "/", the existing cookie will not be picked up by anything other than "/something".
222
+ *
223
+ * In general, changing the cookie path affects existing cookies and needs to be done with extra care around existing cookie implications.
224
+ */
225
+ path?: string;
183
226
  }
184
227
 
185
228
  declare class ServerClient<TStoreOptions = unknown> {
@@ -292,16 +335,8 @@ declare class ServerClient<TStoreOptions = unknown> {
292
335
  * @returns The sessionm or undefined if no session found in the store.
293
336
  */
294
337
  getSession(storeOptions?: TStoreOptions): Promise<SessionData | undefined>;
295
- /**
296
- * Retrieves the access token from the store, or calls Auth0 when the access token is expired and a refresh token is available in the store.
297
- * Also updates the store when a new token was retrieved from Auth0.
298
- * @param storeOptions Optional options used to pass to the Transaction and State Store.
299
- *
300
- * @throws {TokenByRefreshTokenError} If the refresh token was not found or there was an issue requesting the access token.
301
- *
302
- * @returns The Token Set, containing the access token, as well as additional information.
303
- */
304
338
  getAccessToken(storeOptions?: TStoreOptions): Promise<TokenSet>;
339
+ getAccessToken(options: GetAccessTokenOptions, storeOptions?: TStoreOptions): Promise<TokenSet>;
305
340
  /**
306
341
  * Retrieves an access token for a connection.
307
342
  *
@@ -346,7 +381,7 @@ declare abstract class AbstractStore<TData extends JWTPayload, TStoreOptions = u
346
381
  abstract get(identifier: string, options?: TStoreOptions | undefined): Promise<TData | undefined>;
347
382
  abstract delete(identifier: string, options?: TStoreOptions | undefined): Promise<void>;
348
383
  protected encrypt<TData extends JWTPayload>(identifier: string, stateData: TData, expiration: number): Promise<string>;
349
- protected decrypt<TData>(identifier: string, encryptedStateData: string): Promise<TData>;
384
+ protected decrypt<TData>(identifier: string, encryptedStateData: string): Promise<TData | undefined>;
350
385
  }
351
386
 
352
387
  /**
@@ -372,6 +407,13 @@ interface CookieSerializeOptions {
372
407
  domain?: string;
373
408
  expires?: Date;
374
409
  httpOnly?: boolean;
410
+ /**
411
+ * MaxAge value of the cookie in seconds.
412
+ *
413
+ * Note for implementors of {@link CookieHandler}: this value is always in seconds.
414
+ * Some frameworks (e.g. Express) expect `maxAge` in milliseconds, so you may need to convert
415
+ * before passing it to the underlying framework (e.g. `maxAge * 1000`).
416
+ */
375
417
  maxAge?: number;
376
418
  path?: string;
377
419
  secure?: boolean;
@@ -409,8 +451,9 @@ interface CookieHandler<TStoreOptions> {
409
451
  * Delete a cookie using the framework specific integration.
410
452
  * @param name The name of the cookie to delete.
411
453
  * @param storeOptions The options for the store, which may include framework-specific configurations.
454
+ * @param options The options for serializing the cookie.
412
455
  */
413
- deleteCookie: (name: string, storeOptions?: TStoreOptions) => void;
456
+ deleteCookie: (name: string, storeOptions?: TStoreOptions, options?: CookieSerializeOptions) => void;
414
457
  }
415
458
 
416
459
  declare class CookieTransactionStore<TStoreOptions> extends AbstractTransactionStore<TStoreOptions> {
@@ -488,5 +531,12 @@ declare class MissingSessionError extends Error {
488
531
  code: string;
489
532
  constructor(message: string);
490
533
  }
534
+ /**
535
+ * Error thrown when a configuration is invalid.
536
+ */
537
+ declare class InvalidConfigurationError extends Error {
538
+ code: string;
539
+ constructor(message: string);
540
+ }
491
541
 
492
- export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type ConnectionTokenSet, type CookieHandler, type CookieSerializeOptions, CookieTransactionStore, type EncryptedStoreOptions, type InternalStateData, 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 };
542
+ export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type ConnectionTokenSet, type CookieHandler, type CookieSerializeOptions, CookieTransactionStore, type EncryptedStoreOptions, type GetAccessTokenOptions, type InternalStateData, InvalidConfigurationError, 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 };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { AuthorizationDetails, AuthClient } from '@auth0/auth0-auth-js';
1
+ import { AuthorizationDetails, TelemetryConfig, AuthClient } from '@auth0/auth0-auth-js';
2
+ export { TelemetryConfig } from '@auth0/auth0-auth-js';
2
3
  import { JWTPayload } from 'jose';
3
4
 
4
5
  interface ServerClientOptions<TStoreOptions = unknown> {
@@ -22,6 +23,11 @@ interface ServerClientOptions<TStoreOptions = unknown> {
22
23
  * When set to `true`, using a `customFetch` is required.
23
24
  */
24
25
  useMtls?: boolean;
26
+ /**
27
+ * Optional telemetry configuration.
28
+ * Telemetry is enabled by default and sends the Auth0-Client header with package name and version.
29
+ */
30
+ telemetry?: TelemetryConfig;
25
31
  }
26
32
  interface UserClaims {
27
33
  sub: string;
@@ -89,7 +95,11 @@ interface StateStore<TStoreOptions = unknown> extends AbstractDataStore<StateDat
89
95
  interface TransactionStore<TStoreOptions = unknown> extends AbstractDataStore<TransactionData, TStoreOptions> {
90
96
  }
91
97
  interface EncryptedStoreOptions {
92
- secret: string;
98
+ /**
99
+ * The secret(s) to use for encryption and decryption. Can be a single string or an array of strings for secret rotation support.
100
+ * When using an array of secrets, the first one is used for encryption, while all secrets are tried, in-order, for decryption.
101
+ */
102
+ secret: string | string[];
93
103
  }
94
104
  interface StartInteractiveLoginOptions<TAppState = unknown> {
95
105
  pushedAuthorizationRequests?: boolean;
@@ -110,6 +120,25 @@ interface AccessTokenForConnectionOptions {
110
120
  connection: string;
111
121
  loginHint?: string;
112
122
  }
123
+ /**
124
+ * Options for retrieving an access token with MRRT support.
125
+ * Allows requesting tokens for specific audiences and scopes at runtime.
126
+ */
127
+ interface GetAccessTokenOptions {
128
+ /**
129
+ * Optional audience for the requested access token.
130
+ * If not provided, falls back to configuration audience or 'default'.
131
+ * @example 'https://api.example.com'
132
+ */
133
+ audience?: string;
134
+ /**
135
+ * Optional scope for the requested access token.
136
+ * If not provided, falls back to configuration scope.
137
+ * Space-separated scope string.
138
+ * @example 'read:data write:data'
139
+ */
140
+ scope?: string;
141
+ }
113
142
  interface LogoutOptions {
114
143
  returnTo: string;
115
144
  }
@@ -180,6 +209,20 @@ interface SessionCookieOptions {
180
209
  * Default: depends on the protocol of the application's base URL. If the protocol is `https`, then `true`, otherwise `false`.
181
210
  */
182
211
  secure?: boolean;
212
+ /**
213
+ * The path attribute of the session cookie.
214
+ *
215
+ * Default: `/`.
216
+ *
217
+ * @remarks
218
+ * Changing the cookie path will cause existing cookies to behave differently:
219
+ *
220
+ * - If the cookie path is currently "/" (which is the default) and you change it to "/something", existing cookies (using "/" as the path) will be picked up when using "/something", but also for anything outside of "/something", additionally logout will not correctly delete the cookie.
221
+ * - If the cookiepath is "/something" and you change it to "/", the existing cookie will not be picked up by anything other than "/something".
222
+ *
223
+ * In general, changing the cookie path affects existing cookies and needs to be done with extra care around existing cookie implications.
224
+ */
225
+ path?: string;
183
226
  }
184
227
 
185
228
  declare class ServerClient<TStoreOptions = unknown> {
@@ -292,16 +335,8 @@ declare class ServerClient<TStoreOptions = unknown> {
292
335
  * @returns The sessionm or undefined if no session found in the store.
293
336
  */
294
337
  getSession(storeOptions?: TStoreOptions): Promise<SessionData | undefined>;
295
- /**
296
- * Retrieves the access token from the store, or calls Auth0 when the access token is expired and a refresh token is available in the store.
297
- * Also updates the store when a new token was retrieved from Auth0.
298
- * @param storeOptions Optional options used to pass to the Transaction and State Store.
299
- *
300
- * @throws {TokenByRefreshTokenError} If the refresh token was not found or there was an issue requesting the access token.
301
- *
302
- * @returns The Token Set, containing the access token, as well as additional information.
303
- */
304
338
  getAccessToken(storeOptions?: TStoreOptions): Promise<TokenSet>;
339
+ getAccessToken(options: GetAccessTokenOptions, storeOptions?: TStoreOptions): Promise<TokenSet>;
305
340
  /**
306
341
  * Retrieves an access token for a connection.
307
342
  *
@@ -346,7 +381,7 @@ declare abstract class AbstractStore<TData extends JWTPayload, TStoreOptions = u
346
381
  abstract get(identifier: string, options?: TStoreOptions | undefined): Promise<TData | undefined>;
347
382
  abstract delete(identifier: string, options?: TStoreOptions | undefined): Promise<void>;
348
383
  protected encrypt<TData extends JWTPayload>(identifier: string, stateData: TData, expiration: number): Promise<string>;
349
- protected decrypt<TData>(identifier: string, encryptedStateData: string): Promise<TData>;
384
+ protected decrypt<TData>(identifier: string, encryptedStateData: string): Promise<TData | undefined>;
350
385
  }
351
386
 
352
387
  /**
@@ -372,6 +407,13 @@ interface CookieSerializeOptions {
372
407
  domain?: string;
373
408
  expires?: Date;
374
409
  httpOnly?: boolean;
410
+ /**
411
+ * MaxAge value of the cookie in seconds.
412
+ *
413
+ * Note for implementors of {@link CookieHandler}: this value is always in seconds.
414
+ * Some frameworks (e.g. Express) expect `maxAge` in milliseconds, so you may need to convert
415
+ * before passing it to the underlying framework (e.g. `maxAge * 1000`).
416
+ */
375
417
  maxAge?: number;
376
418
  path?: string;
377
419
  secure?: boolean;
@@ -409,8 +451,9 @@ interface CookieHandler<TStoreOptions> {
409
451
  * Delete a cookie using the framework specific integration.
410
452
  * @param name The name of the cookie to delete.
411
453
  * @param storeOptions The options for the store, which may include framework-specific configurations.
454
+ * @param options The options for serializing the cookie.
412
455
  */
413
- deleteCookie: (name: string, storeOptions?: TStoreOptions) => void;
456
+ deleteCookie: (name: string, storeOptions?: TStoreOptions, options?: CookieSerializeOptions) => void;
414
457
  }
415
458
 
416
459
  declare class CookieTransactionStore<TStoreOptions> extends AbstractTransactionStore<TStoreOptions> {
@@ -488,5 +531,12 @@ declare class MissingSessionError extends Error {
488
531
  code: string;
489
532
  constructor(message: string);
490
533
  }
534
+ /**
535
+ * Error thrown when a configuration is invalid.
536
+ */
537
+ declare class InvalidConfigurationError extends Error {
538
+ code: string;
539
+ constructor(message: string);
540
+ }
491
541
 
492
- export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type ConnectionTokenSet, type CookieHandler, type CookieSerializeOptions, CookieTransactionStore, type EncryptedStoreOptions, type InternalStateData, 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 };
542
+ export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type ConnectionTokenSet, type CookieHandler, type CookieSerializeOptions, CookieTransactionStore, type EncryptedStoreOptions, type GetAccessTokenOptions, type InternalStateData, InvalidConfigurationError, 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 };