UNPKG

@auth0/nextjs-auth0

Version:
67 lines (66 loc) 3.59 kB
import { AccessTokenSet, SessionData, TokenSet } from "../types/index.js"; /** * Converts a TokenSet to an AccessTokenSet, including optional audience and scope. * @param tokenSet the TokenSet to convert * @param options object containing optional audience * @returns AccessTokenSet */ export declare function accessTokenSetFromTokenSet(tokenSet: TokenSet, options: { audience: string; }): AccessTokenSet; /** * Converts an AccessTokenSet and a partial TokenSet into a partial TokenSet. * This is useful for merging an AccessTokenSet back into a TokenSet structure, * while preserving other properties of the TokenSet. * @param accessTokenSet the AccessTokenSet to convert * @param tokenSet the partial TokenSet to merge with * @returns The merged partial TokenSet */ export declare function tokenSetFromAccessTokenSet(accessTokenSet: AccessTokenSet | undefined, tokenSet: Partial<TokenSet>): Partial<TokenSet>; /** * Compares two sets of scopes to determine if all required scopes are present in the provided scopes. * @param scopes Scopes to compare (space-separated string) * @param requiredScopes Scopes required to be present in the scopes (space-separated string) * @param options Optional settings for comparison * @param options.strict If true, requires an exact match of scopes (no extra scopes allowed) * @returns True if all required scopes are present in the scopes, false otherwise */ export declare const compareScopes: (scopes: string | null | undefined, requiredScopes: string | undefined, options?: { strict?: boolean; }) => boolean; /** * Merges two space-separated scope strings into one, removing duplicates. * Properly handles whitespace by trimming and normalizing scope values. * @param scopes1 The first scope string * @param scopes2 The second scope string * @returns Merged scope string with unique scopes, sorted alphabetically for consistency */ export declare function mergeScopes(scopes1: string | undefined | null, scopes2: string | undefined | null): string; /** * Finds the best matching AccessTokenSet in the session by audience and scope. * * The function determines a "match" if an AccessTokenSet's scope property contains all the items * from the `options.scope`. From the potential matches, it selects the best one * based on the following criteria, in order of priority: * * 1. An "exact match" is preferred above all. This is where the AccessTokenSet's scope * has the exact same items as the `options.scope` (length and content are identical, * order does not matter). * 2. If no exact match is found, the "best partial match" is chosen. This is the * matching AccessTokenSet whose scope has the fewest additional items. * 3. If multiple matches with the exact same scopes are found, we take the first one. * However, this should not happen in practice as the session should not contain * duplicate AccessTokenSet's. * * @param sessionData The session data containing accessTokens array. * @param {Object} options * @param {number} options.scope - The scope to match against (space-separated string). * @param {string} options.audience - The audience to match against. * @param {"requestedScope" | "scope"} [options.matchMode="requestedScope"] - The mode to use for matching scopes. * @returns The best matching AccessTokenSet, or undefined if no match is found. */ export declare function findAccessTokenSet(sessionData: SessionData | undefined, options: { scope?: string; audience: string; matchMode?: "requestedScope" | "scope"; }): AccessTokenSet | undefined;