/** * OAuth Session Validation and Token Refresh * * Handles automatic validation and refresh of OAuth tokens in sessions */ import type { Request, IOAuthProvider, Logger } from '../types.ts'; import type { HookManager } from './hookManager.ts'; export interface SessionValidationResult { /** Whether the session has valid OAuth data */ valid: boolean; /** Whether tokens were refreshed during validation */ refreshed?: boolean; /** Error message if validation failed */ error?: string; } /** * Validate OAuth session and refresh tokens if needed * * This function checks if OAuth tokens in the session are expired or approaching * expiration, and automatically refreshes them if possible. * * Token refresh strategy: * - If token is expired (past expiresAt), refresh immediately * - If token is approaching expiration (past refreshThreshold = 80% of lifetime), refresh proactively * - If no refresh token available and token is expired, clear OAuth session data * * @param request - Harper request object with session * @param provider - OAuth provider instance for token refresh * @param logger - Optional logger for debugging * @param hookManager - Optional hook manager for calling onTokenRefresh hook * @returns Validation result indicating if session is valid and if refresh occurred */ export declare function validateAndRefreshSession(request: Request, provider: IOAuthProvider, logger?: Logger, hookManager?: HookManager): Promise; /** * Check if a session has valid OAuth authentication * Does not refresh tokens, only checks validity */ export declare function hasValidOAuthSession(request: Request): boolean;