import { SSOSession, SSOConfig, ADTokens, ADUser } from './types'; /** * SSO event types for cross-tab communication. */ export type SSOEventType = 'session_created' | 'session_updated' | 'session_expired' | 'session_ended' | 'activity_ping' | 'token_refreshed'; /** * SSO broadcast message structure. */ export interface SSOBroadcastMessage { type: SSOEventType; sessionId: string; timestamp: number; payload?: { tokens?: ADTokens; user?: Partial; source?: string; }; } /** * SSO event handler function type. */ export type SSOEventHandler = (event: SSOBroadcastMessage) => void; /** * SSO Manager options. */ export interface SSOManagerOptions extends SSOConfig { /** Callback when session changes */ onSessionChange?: (session: SSOSession | null) => void; /** Callback when tokens are synced */ onTokenSync?: (tokens: ADTokens) => void; /** Callback when session expires */ onSessionExpired?: () => void; /** Enable debug logging */ debug?: boolean; } /** * SSO Manager for cross-tab session synchronization. * * Manages Single Sign-On sessions across browser tabs and windows, * providing seamless authentication state synchronization. * * @example * ```typescript * const ssoManager = new SSOManager({ * crossTabSync: true, * sessionTimeout: 8 * 60 * 60 * 1000, // 8 hours * onSessionChange: (session) => { * if (session) { * console.log('Session active:', session.upn); * } else { * console.log('No active session'); * } * }, * }); * * // Start a new SSO session * await ssoManager.startSession(user, tokens); * * // Check for existing session on load * const existingSession = await ssoManager.detectSession(); * ``` */ export declare class SSOManager { private options; private broadcastChannel; private activityTimer; private sessionCheckTimer; private eventHandlers; private readonly tabId; private currentSession; /** * Create a new SSO manager. * * @param options - SSO configuration options */ constructor(options?: Partial); /** * Start a new SSO session. * * @param user - Authenticated user * @param tokens - Authentication tokens * @returns The created session */ startSession(user: ADUser, tokens: ADTokens): SSOSession; /** * End the current SSO session. */ endSession(): void; /** * Detect and restore existing SSO session. * * @returns Existing session if found and valid, null otherwise */ detectSession(): SSOSession | null; /** * Get the current active session. */ getCurrentSession(): SSOSession | null; /** * Check if there's an active SSO session. */ hasActiveSession(): boolean; /** * Update session activity timestamp. */ recordActivity(): void; /** * Get stored tokens for the current session. */ getSessionTokens(): ADTokens | null; /** * Update tokens and sync across tabs. * * @param tokens - New tokens */ syncTokens(tokens: ADTokens): void; /** * Subscribe to SSO events. * * @param handler - Event handler function * @returns Unsubscribe function */ onEvent(handler: SSOEventHandler): () => void; /** * Cleanup resources. */ dispose(): void; /** * Initialize BroadcastChannel for cross-tab communication. */ private initializeBroadcastChannel; /** * Broadcast a message to other tabs. */ private broadcast; /** * Handle incoming broadcast messages. */ private handleBroadcastMessage; /** * Handle storage events for fallback sync. */ private handleStorageEvent; /** * Initialize activity tracking. */ private initializeActivityTracking; /** * Start periodic session validity check. */ private startSessionCheck; /** * Persist session to storage. */ private persistSession; /** * Load session from storage. */ private loadSession; /** * Persist tokens to storage. */ private persistTokens; /** * Clear all session data. */ private clearSessionData; /** * Get the storage object. */ private getStorage; /** * Check if a session is still valid. */ private isSessionValid; /** * Generate unique session ID. */ private generateSessionId; /** * Generate unique tab ID. */ private generateTabId; /** * Log debug message. */ private log; } /** * Create a new SSO manager. * * @param options - SSO configuration options * @returns Configured SSOManager */ export declare function createSSOManager(options?: Partial): SSOManager; /** * Cross-domain SSO helper for applications on different subdomains. * * Uses postMessage for secure cross-origin communication. */ export declare class CrossDomainSSO { private allowedOrigins; private messageHandler; constructor(allowedOrigins: string[]); /** * Initialize cross-domain SSO listener. * * @param onSessionReceived - Callback when session is received */ listen(onSessionReceived: (session: SSOSession, tokens: ADTokens) => void): void; /** * Share session with another domain. * * @param targetOrigin - Target origin URL * @param targetWindow * @param session - Session to share * @param tokens - Tokens to share */ shareSession(targetOrigin: string, targetWindow: Window, session: SSOSession, tokens: ADTokens): void; /** * Request session from parent window (for iframes). * * @param parentOrigin - Parent window origin */ requestSession(parentOrigin: string): void; /** * Stop listening for cross-domain messages. */ dispose(): void; } /** * Create a cross-domain SSO helper. * * @param allowedOrigins - List of allowed origins * @returns CrossDomainSSO instance */ export declare function createCrossDomainSSO(allowedOrigins: string[]): CrossDomainSSO;