/** * Error thrown when trying to use authentication methods before the unidy-login component is mounted */ export declare class UnidyNotMounted extends Error { constructor(); } export interface UnidyAuthConfig { /** The client ID for the application */ clientId: string; /** The OAuth scopes to request, defaults to "openid email" */ scope?: Scope; /** The OAuth response type, defaults to "id_token" */ responseType?: ResponseType; /** The prompt option for authentication, can be "none", "login", "consent", "select_account" or null */ prompt?: PromptOption; /** Whether to store the token in session storage, defaults to true */ storeTokenInSession?: boolean; /** Whether to fallback to silent auth request when checking authentication status, defaults to false */ fallbackToSilentAuthRequest?: boolean; /** Callback function called when authentication is successful */ onAuth?: (token: string) => void; /** Whether to enable logging, defaults to true */ enableLogging?: boolean; /** The rendering mode - 'dialog' for modal popup, 'inline' for embedded in page, defaults to 'dialog' */ mode?: "dialog" | "inline"; /** The target element where the component should be mounted in inline mode - can be element ID, CSS selector, or HTMLElement, defaults to document.body */ mountTarget?: string | HTMLElement; /** Whether to use the special redirect behavior, for browsers limitation access to third party cookies. * This should be disabled, when the Unidy instance runs on the same second level domain */ redirectFlowForLimitedThirdPartyCookieAccess?: boolean; /** When in inline mode and the browser has no access to third-party cookies, * a login button is rendered with this label. Defaults to "Login" */ redirectFlowLoginButtonLabel?: string; } export declare const UNIDY_ID_TOKEN_SESSION_KEY = "unidy_id_token"; export type BasePayload = { /** The subject of the token */ sub: string; /** The expiration time of the token */ exp: number; /** The issued at time of the token */ iat: number; /** The issuer of the token */ iss: string; /** The audience of the token */ aud: string; /** The nonce of the token */ nonce: string; /** The authentication time of the token */ auth_time: number; [key: string]: string | number | boolean | undefined; } & (Scope extends `${string}email${string}` ? { email: string; email_verified: boolean; } : {}) & (Scope extends `${string}profile${string}` ? { name: string; given_name: string; family_name: string; gender: "male" | "female" | "other"; updated_at: number; } : {}); export type AuthResult = Record, Scope extends string = string> = { success: true; token: string; userTokenData: BasePayload & CustomPayload; } | { success: false; error: string; }; export type LogoutResult = { success: boolean; }; export type PromptOption = "none" | "login" | "consent" | "select_account" | null; export type ResponseType = "code" | "id_token" | "token"; export declare class Auth = Record, Scope extends string = string> { /** The base URL of the Unidy authentication server, example: https://your-domain.unidy.de */ readonly baseUrl: string; /** Configuration options for the authentication process */ readonly config: UnidyAuthConfig; /** The web component instance which contains the authentication UI and handles the authentication process */ readonly component: HTMLUnidyLoginElement | null; /** The state of the initialization process */ private initState; /** Whether to store the token in session storage, defaults to true */ private storeTokenInSession; /** Whether to fallback to silent auth request when checking authentication status, defaults to false */ private fallbackToSilentAuthRequest; private readonly logger; /** * Initializes a new instance of the Auth class. * @param baseUrl - The base URL of the Unidy authentication server. * @param config - Configuration options for the authentication process. */ constructor(baseUrl: string, config: UnidyAuthConfig); /** * Mounts the authentication web component to the DOM. * This method should be called once to initialize the component. */ mountComponent(): void; /** * Initiates the authentication process * @param {Object} options - Authentication options * @param {boolean} [options.silent=false] - If true, attempts silent authentication without showing UI * @returns {Promise} Promise resolving to authentication result containing success status and token/error */ auth({ silent }?: { silent?: boolean; }): Promise; /** * Logs the user out by clearing the session token and performing a logout request to the Unidy authentication server * @returns A promise that resolves with the logout result. */ logout(): Promise; /** * Shows the authentication dialog. * @returns A promise that resolves when the dialog is shown. */ show(): Promise; /** * Hides the authentication dialog. * @returns A promise that resolves when the dialog is hidden. */ hide(): Promise; /** * Checks if the authentication component has been initialized. * @returns True if the component is initialized (mounted with `mountComponent` to the DOM), false otherwise. */ get isInitialized(): boolean; /** * Retrieves the ID token from session storage. * * @returns The ID token, or null if not found or if `storeTokenInSession` is disabled (false). */ get idToken(): string | null; /** * Checks if the user is authenticated. * If not authenticated and fallbackToSilentAuthRequest is enabled, it attempts a silent login. * * Note: method should be used if `storeTokenInSession` is enabled (true) which is the default behavior. * If storeTokenInSession is disabled (false), the method will always return false. * * @returns A promise that resolves to true if the user is authenticated, false otherwise. */ isAuthenticated(): Promise; /** * Retrieves the decoded user token data. * * Note: method should be used if `storeTokenInSession` is enabled (true) which is the default behavior. * If `storeTokenInSession` is disabled (false), the method will always return null. * * @returns The decoded token payload, or null if the token is invalid or not present. */ userTokenData(): (BasePayload & CustomPayload) | null; /** * Parses a JWT token and returns the payload with proper typing. * * @param token - The JWT token to parse * @returns The parsed token payload or null if parsing fails */ parseToken(token: string): (BasePayload & CustomPayload) | null; /** * Validates a JWT token by decoding it and checking its expiration time. * * @param token - The JWT token to validate (can be string or decoded token) * @returns True if the token is valid and not expired, false otherwise */ validateToken(token: string | (BasePayload & CustomPayload) | null): boolean; private storeToken; private storeTokenAndDispatchEvent; private dispatchAuthEvent; }