/** * OAuth Types * * OAuth authentication types and interfaces for provider authentication. */ export type OAuthCredentials = { refresh: string; access: string; expires: number; [key: string]: unknown; }; export type OAuthProviderId = string; export type OAuthLoginMethod = 'browser' | 'device_code'; export type OAuthPrompt = { message: string; placeholder?: string; allowEmpty?: boolean; }; export type OAuthAuthInfo = { url: string; instructions?: string; }; export type OAuthDeviceCodeInfo = { userCode: string; verificationUri: string; intervalSeconds?: number; expiresInSeconds?: number; }; export type OAuthSelectOption = { id: string; label: string; }; export type OAuthSelectPrompt = { message: string; options: OAuthSelectOption[]; }; export interface OAuthLoginCallbacks { onAuth: (info: OAuthAuthInfo) => void; onDeviceCode: (info: OAuthDeviceCodeInfo) => void; onPrompt: (prompt: OAuthPrompt) => Promise; onProgress?: (message: string) => void; onManualCodeInput?: () => Promise; onSelect: (prompt: OAuthSelectPrompt) => Promise; signal?: AbortSignal; } export interface OAuthProviderInterface { readonly id: OAuthProviderId; readonly name: string; /** Run the login flow, return credentials to persist */ login(callbacks: OAuthLoginCallbacks): Promise; /** Whether login uses a local callback server and supports manual code input. */ usesCallbackServer?: boolean; /** Login methods exposed by providers that support more than one OAuth flow. */ loginMethods?: readonly OAuthLoginMethod[]; /** Refresh expired credentials, return updated credentials to persist */ refreshToken(credentials: OAuthCredentials, signal?: AbortSignal): Promise; /** Convert credentials to API key string for the provider */ getApiKey(credentials: OAuthCredentials): string; } export type AuthCredential = { type: 'api_key'; key: string; } | { type: 'oauth'; } & OAuthCredentials;