import { SSOProvider, AuthenticationResponse } from './types'; /** * Set the auth context for SSO operations * This is called automatically when using useAuth() */ export declare function setAuthContext(authApi: any): void; /** * SSO Provider Configuration */ export interface SSOProviderConfig { /** Provider identifier */ id: SSOProvider; /** Display name */ name: string; /** Brand color (hex) */ color: string; /** Icon identifier (for UI libraries) */ icon: string; /** Default OAuth scopes */ defaultScopes: string[]; /** Provider-specific metadata */ metadata?: { authDomain?: string; buttonText?: string; [key: string]: any; }; } /** * OAuth Flow Options */ export interface OAuthFlowOptions { /** Custom redirect URI (defaults to current origin + /auth/callback) */ redirectUri?: string; /** State parameter for CSRF protection (auto-generated if not provided) */ state?: string; /** Custom scopes (overrides provider defaults) */ scopes?: string[]; /** Additional OAuth parameters (prompt, login_hint, hd, domain, etc.) */ params?: Record; /** Popup window dimensions */ popupDimensions?: { width?: number; height?: number; }; /** Timeout for popup flow in milliseconds (default: 90000) */ popupTimeout?: number; } /** * Popup Result */ export interface PopupResult { code: string; state?: string; error?: string; } /** * SSO Error Types */ export declare class SSOError extends Error { code: string; constructor(message: string, code: string); } export declare class PopupBlockedError extends SSOError { constructor(); } export declare class PopupClosedError extends SSOError { constructor(); } export declare class PopupTimeoutError extends SSOError { constructor(); } export declare class StateMismatchError extends SSOError { constructor(); } /** * SSO Provider Instance with functional methods */ export interface SSOProviderInstance extends SSOProviderConfig { /** * Initiate OAuth flow with redirect (most common) * User is redirected to provider's authorization page */ redirect: (options?: OAuthFlowOptions) => Promise; /** * Initiate OAuth flow in a popup window * Returns the authorization code without leaving the page */ popup: (options?: OAuthFlowOptions) => Promise; /** * Complete OAuth flow after callback * Call this on your callback page */ callback: (code: string, state: string) => Promise; /** * Link this provider to the current logged-in user * Call this after OAuth redirect completes on link callback page */ link: (code: string, state: string) => Promise; /** * Unlink this provider from the current user */ unlink: () => Promise; /** * Get authorization URL without redirecting */ getAuthUrl: (options?: OAuthFlowOptions) => Promise; /** * Whether this provider supports popup flow * Some providers (like Apple) work better with redirect */ supportsPopup?: boolean; } /** * SSO object type with providers and helper methods */ export interface SSOObject { google: SSOProviderInstance; microsoft: SSOProviderInstance; github: SSOProviderInstance; okta: SSOProviderInstance; apple: SSOProviderInstance; facebook: SSOProviderInstance; handleCallback: () => Promise; handleLinkCallback: () => Promise; } /** * SSO object with providers and global helper methods */ export declare const sso: SSOObject; /** * Array of all SSO provider instances */ export declare const ssoProvidersList: readonly SSOProviderInstance[]; /** * Get SSO provider instance by ID */ export declare function getSSOProvider(provider: SSOProvider): SSOProviderInstance | undefined; /** * Get all available SSO providers */ export declare function getAllSSOProviders(): readonly SSOProviderInstance[]; /** * Check if a provider is supported */ export declare function isSupportedProvider(provider: string): provider is SSOProvider; /** * Popup-mode OAuth landing handler. * * Call this **once at app startup, before the router mounts**. When the current * page was opened as an OAuth popup (it has `?code`/`?state` — or `?error` — and * a `window.opener`), it posts an `auth:complete` message back to the opener * (which `sso..popup()` is waiting for) and closes the popup. * * This lets a host app support popup SSO **without** a dedicated `/auth/callback` * route or component — the whole flow stays on the original page. * * @returns `true` if it handled a popup callback (caller should stop bootstrapping * the app — the window is closing), otherwise `false`. * * @example * ```ts * import { handleSsoPopup } from '@bagelink/auth' * if (handleSsoPopup()) { // we're the popup; do nothing else * } else { * app.mount('#app') * } * ``` */ export declare function handleSsoPopup(): boolean;