/** * Standalone login functions for stateless authentication flows. * These functions handle OAuth login without managing session state, * making them ideal for use with external session managers like NextAuth. */ import type { DirectLoginOptions, ZkEvmInfo } from '../types'; /** * Configuration for standalone login functions */ export interface LoginConfig { /** Your Immutable application client ID */ clientId: string; /** The OAuth redirect URI for your application */ redirectUri: string; /** Optional separate redirect URI for popup flows */ popupRedirectUri?: string; /** OAuth audience (default: "platform_api") */ audience?: string; /** OAuth scopes (default: "openid profile email offline_access transact") */ scope?: string; /** Authentication domain (default: "https://auth.immutable.com") */ authenticationDomain?: string; } /** * Token response from successful authentication */ export interface TokenResponse { /** OAuth access token for API calls */ accessToken: string; /** OAuth refresh token for token renewal */ refreshToken?: string; /** OpenID Connect ID token */ idToken?: string; /** Unix timestamp (ms) when the access token expires */ accessTokenExpires: number; /** User profile information */ profile: { sub: string; email?: string; nickname?: string; }; /** zkEVM wallet information if available */ zkEvm?: ZkEvmInfo; } /** * Extended login options for popup/redirect flows */ export interface StandaloneLoginOptions { /** Direct login options (social provider, email, etc.) */ directLoginOptions?: DirectLoginOptions; } /** * Login with a popup window. * Opens a popup for OAuth authentication and returns tokens when complete. * * @param config - Login configuration * @param options - Optional login options (direct login, etc.) * @returns Promise resolving to token response * @throws Error if popup is blocked or login fails * * @example * ```typescript * import { loginWithPopup } from '@imtbl/auth'; * * const tokens = await loginWithPopup({ * clientId: 'your-client-id', * redirectUri: 'https://your-app.com/callback', * }); * console.log(tokens.accessToken); * ``` */ export declare function loginWithPopup(config: LoginConfig, options?: StandaloneLoginOptions): Promise; /** * Login with an embedded iframe modal. * First displays a modal for the user to select their login method (email, Google, etc.), * then opens a popup for OAuth authentication and returns tokens when complete. * * This provides a smoother user experience compared to loginWithPopup as the user * can choose their login method before the OAuth popup opens. * * @param config - Login configuration * @returns Promise resolving to token response * @throws Error if modal is closed or login fails * * @example * ```typescript * import { loginWithEmbedded } from '@imtbl/auth'; * * const tokens = await loginWithEmbedded({ * clientId: 'your-client-id', * redirectUri: 'https://your-app.com/callback', * }); * console.log(tokens.accessToken); * ``` */ export declare function loginWithEmbedded(config: LoginConfig): Promise; /** * Login with redirect. * Redirects the current page to OAuth authentication. * After authentication, the user will be redirected back to your redirectUri. * Use `handleLoginCallback` to complete the flow. * * @param config - Login configuration * @param options - Optional login options (direct login, etc.) * * @example * ```typescript * import { loginWithRedirect } from '@imtbl/auth'; * * // In your login button handler * loginWithRedirect({ * clientId: 'your-client-id', * redirectUri: 'https://your-app.com/callback', * }); * ``` */ export declare function loginWithRedirect(config: LoginConfig, options?: StandaloneLoginOptions): Promise; /** * Handle the OAuth callback after redirect-based login. * Extracts the authorization code from the URL and exchanges it for tokens. * * @param config - Login configuration (must match what was used in loginWithRedirect) * @returns Promise resolving to token response, or undefined if not a valid callback * * @example * ```typescript * // In your callback page * import { handleLoginCallback } from '@imtbl/auth'; * * const tokens = await handleLoginCallback({ * clientId: 'your-client-id', * redirectUri: 'https://your-app.com/callback', * }); * * if (tokens) { * // Login successful, tokens contains accessToken, refreshToken, etc. * await signIn('immutable', { tokens: JSON.stringify(tokens) }); * } * ``` */ export declare function handleLoginCallback(config: LoginConfig): Promise; /** * Configuration for standalone logout functions */ export interface LogoutConfig { /** Your Immutable application client ID */ clientId: string; /** URL to redirect to after logout completes (must be registered in your app settings) */ logoutRedirectUri?: string; /** Authentication domain (default: "https://auth.immutable.com") */ authenticationDomain?: string; } /** * Build the logout URL for federated logout. * This URL can be used to redirect to the auth domain's logout endpoint, * which clears the session on the auth server (including social provider sessions). * * @param config - Logout configuration * @returns The full logout URL * * @example * ```typescript * import { buildLogoutUrl } from '@imtbl/auth'; * * const logoutUrl = buildLogoutUrl({ * clientId: 'your-client-id', * logoutRedirectUri: 'https://your-app.com', * }); * // => "https://auth.immutable.com/v2/logout?client_id=your-client-id&returnTo=https://your-app.com" * ``` */ export declare function buildLogoutUrl(config: LogoutConfig): string; /** * Logout with redirect. * Redirects the current page to the auth domain's logout endpoint, * which clears the session on the auth server (including social provider sessions like Google). * * This is the recommended logout method for most applications as it ensures * complete session cleanup. After logout, the user will be redirected to * the `logoutRedirectUri` if provided. * * @param config - Logout configuration * * @example * ```typescript * import { logoutWithRedirect } from '@imtbl/auth'; * * // In your logout button handler * logoutWithRedirect({ * clientId: 'your-client-id', * logoutRedirectUri: 'https://your-app.com', * }); * // Page will redirect to auth domain, then back to your app * ``` */ export declare function logoutWithRedirect(config: LogoutConfig): void; /** * Logout silently using a hidden iframe. * Clears the session on the auth server without redirecting the current page. * * Note: Silent logout may not work in all browsers due to third-party cookie * restrictions. For more reliable session cleanup, use `logoutWithRedirect`. * * @param config - Logout configuration * @param timeout - Timeout in milliseconds (default: 5000) * @returns Promise that resolves when logout is complete or times out * * @example * ```typescript * import { logoutSilent } from '@imtbl/auth'; * * try { * await logoutSilent({ * clientId: 'your-client-id', * }); * console.log('Logged out silently'); * } catch (error) { * console.error('Silent logout failed:', error); * // Fall back to redirect logout * } * ``` */ export declare function logoutSilent(config: LogoutConfig, timeout?: number): Promise;