UNPKG

@auth0/nextjs-auth0

Version:
57 lines (56 loc) 2.57 kB
/** * Options for fetching an access token. * * **Important for Multi-API Applications**: When your application calls multiple APIs with different * audiences, you **must** specify the `audience` parameter to ensure the correct access token is retrieved. * Without specifying the audience, the default access token from the session will be used, which may be * intended for a different API. * * @example * ```typescript * // Single API - no audience needed (uses session token) * const token = await getAccessToken(); * * // Multi-API - specify audience for correct token * const profileToken = await getAccessToken({ * audience: 'https://profile-api.example.com' * }); * const ordersToken = await getAccessToken({ * audience: 'https://orders-api.example.com' * }); * ``` */ export type AccessTokenOptions = { /** * Additional scopes to request beyond those granted during login. * Requires the Auth0 Application to be configured for Multi-Resource Refresh Tokens (MRRT). * * @example 'read:profile write:profile' */ scope?: string; /** * The unique identifier of the target API. This should match the API identifier configured in Auth0. * * **Critical for Multi-API Applications**: If your application calls multiple APIs, you must specify * this parameter to ensure the correct access token is used for each API. Each API requires its own * access token with the appropriate audience. * * **Configuration Requirement**: When using `audience` or `scope`, ensure that the audiences and scopes * are part of your Auth0 Application's Refresh Token Policies. This requires configuring * Multi-Resource Refresh Tokens (MRRT) in your Auth0 Application settings. * * @see https://auth0.com/docs/secure/tokens/refresh-tokens/multi-resource-refresh-token - Multi-Resource Refresh Tokens documentation * * @example 'https://api.example.com' * @example 'https://orders-api.mycompany.com' */ audience?: string; }; /** * Fetches an access token for the currently logged-in user. * @param options Options for fetching the access token, including optional audience and scope. * @returns The access token as a string. * @note Passing audience or scope relies on MRRT to be configured in your Auth0 Application. * @see https://auth0.com/docs/secure/tokens/refresh-tokens/multi-resource-refresh-token/configure-and-implement-multi-resource-refresh-token */ export declare function getAccessToken(options?: AccessTokenOptions): Promise<string>;