import { IAuthConfiguration } from './config'; import { AuthModuleConfiguration, User, DirectLoginOptions, DeviceTokenResponse, LoginOptions, AuthEventMap, UserZkEvm } from './types'; import TypedEventEmitter from './utils/typedEventEmitter'; /** * Public-facing Auth class for authentication * Provides login/logout helpers and exposes auth state events */ export declare class Auth { private readonly config; private readonly userManager; private readonly deviceCredentialsManager; private readonly embeddedLoginPrompt; private readonly logoutMode; /** * Promise that is used to prevent multiple concurrent calls to the refresh token endpoint. */ private refreshingPromise; /** * Event emitter for authentication events (LOGGED_IN, LOGGED_OUT) * Exposed for wallet and passport packages to subscribe to auth state changes */ readonly eventEmitter: TypedEventEmitter; /** * Create a new Auth instance * * @param config - Auth configuration * * @example * ```typescript * import { Auth } from '@imtbl/auth'; * * const auth = new Auth({ * authenticationDomain: 'https://auth.immutable.com', * passportDomain: 'https://passport.immutable.com', * clientId: 'your-client-id', * redirectUri: 'https://your-app.com/callback', * scope: 'openid profile email transact', * }); * ``` */ constructor(config: AuthModuleConfiguration); /** * Login the user with extended options * Supports cached sessions, silent login, redirect flow, and direct login * @param options - Extended login options * @returns Promise that resolves with the user or null */ login(options?: LoginOptions): Promise; /** * Login with redirect * Redirects the page for authentication * @param directLoginOptions - Optional direct login options * @returns Promise that resolves when redirect is initiated */ loginWithRedirect(directLoginOptions?: DirectLoginOptions): Promise; /** * Login callback handler * Call this in your redirect or popup callback page * @returns Promise that resolves with the authenticated user or undefined (for popup flows) */ loginCallback(): Promise; /** * Logout the current user * @returns Promise that resolves when logout is complete */ logout(): Promise; /** * Get the current authenticated user * @returns Promise that resolves with the user or null if not authenticated */ getUser(): Promise; /** * Get the current authenticated user or initiate login if needed * @returns Promise that resolves with an authenticated user */ getUserOrLogin(): Promise; /** * Get the current authenticated zkEVM user * @returns Promise that resolves with a zkEVM-capable user */ getUserZkEvm(): Promise; /** * Get the ID token for the current user * @returns Promise that resolves with the ID token or undefined */ getIdToken(): Promise; /** * Get the access token for the current user * @returns Promise that resolves with the access token or undefined */ getAccessToken(): Promise; /** * Check if user is logged in * @returns Promise that resolves with true if user is logged in */ isLoggedIn(): Promise; /** * Force a silent user refresh (for silent login) * @returns Promise that resolves with the user or null if refresh fails */ forceUserRefresh(): Promise; /** * Trigger a background user refresh without awaiting the result */ forceUserRefreshInBackground(): void; /** * Get the PKCE authorization URL for login flow * @param directLoginOptions - Optional direct login options * @param imPassportTraceId - Optional trace ID for tracking * @returns Promise that resolves with the authorization URL */ loginWithPKCEFlow(directLoginOptions?: DirectLoginOptions, imPassportTraceId?: string): Promise; /** * Handle the PKCE login callback * @param authorizationCode - The authorization code from the OAuth provider * @param state - The state parameter for CSRF protection * @returns Promise that resolves with the authenticated user */ loginWithPKCEFlowCallback(authorizationCode: string, state: string): Promise; /** * Store tokens from device flow and retrieve user * @param tokenResponse - The token response from device flow * @returns Promise that resolves with the authenticated user */ storeTokens(tokenResponse: DeviceTokenResponse): Promise; /** * Get the logout URL * @returns Promise that resolves with the logout URL or undefined if not available */ getLogoutUrl(): Promise; /** * Handle the silent logout callback * @param url - The URL containing logout information * @returns Promise that resolves when callback is handled */ logoutSilentCallback(url: string): Promise; /** * Get auth configuration * @internal * @returns IAuthConfiguration instance */ getConfig(): IAuthConfiguration; /** * Get the configured OIDC client ID * @returns Promise that resolves with the client ID string */ getClientId(): Promise; private handleSuccessfulLogin; private buildExtraQueryParams; private loginWithRedirectInternal; private loginWithPopup; private static mapOidcUserToDomainModel; private static mapDeviceTokenResponseToOidcUser; private loginCallbackInternal; private getPKCEAuthorizationUrl; private loginWithPKCEFlowCallbackInternal; private getPKCEToken; private storeTokensInternal; private logoutInternal; private getLogoutUrlInternal; private forceUserRefreshInBackgroundInternal; private forceUserRefreshInternal; private signinSilentWithRetry; private refreshTokenAndUpdatePromise; private getUserInternal; private getUserZkEvmInternal; }