/** * OAuth2 Authorization Code flow for the WHOOP API. * * Orchestrates: build auth URL → open browser → wait for callback code * → exchange code for tokens → save to token store. Also handles token refresh. */ import type { OAuthTokens } from "./token-store.js"; /** Configuration for the OAuth flow */ export interface OAuthConfig { clientId: string; clientSecret: string; /** Override the default redirect URI. Default: WHOOP_REDIRECT_URI */ redirectUri?: string; /** Token storage directory. Default: ~/.whoop-mcp/ */ tokenDir?: string; /** Callback server port, if provided, must match the redirect URI. */ port?: number; } /** Raw token response from the WHOOP token endpoint */ export interface TokenResponse { access_token: string; refresh_token: string; expires_in: number; token_type: string; scope: string; } /** * Build the WHOOP authorization URL with all required parameters. * * Constructs a properly-encoded URL that the user will be redirected to * in order to authorize the application. */ export declare function buildAuthorizationUrl(config: OAuthConfig, state: string, codeChallenge?: string): string; /** * Exchange an authorization code for tokens. * * POSTs to the WHOOP token endpoint with `application/x-www-form-urlencoded` * body per OAuth2 spec. */ export declare function exchangeCodeForTokens(code: string, config: OAuthConfig, codeVerifier?: string): Promise; /** * Use the refresh token to obtain a new access token. * * POSTs to the WHOOP token endpoint with `grant_type=refresh_token`. */ export declare function refreshAccessToken(refreshToken: string, config: OAuthConfig): Promise; /** * Convert the raw TokenResponse into our OAuthTokens shape for storage. * * Computes `expires_at` (absolute epoch ms) from `expires_in` (relative seconds). * * Per RFC 6749 §6, the authorization server MAY issue a new refresh token on * refresh — but is not required to. If the response omits `refresh_token`, * pass `existingRefreshToken` to preserve the current one so the token file * stays valid on the next load. */ export declare function toOAuthTokens(response: TokenResponse, existingRefreshToken?: string): OAuthTokens; /** * Open a URL in the user's default browser. * * Uses `spawn` with argument arrays to avoid shell injection. * Throws if the URL is malformed or not http(s) — callers must pass a * trusted scheme. Otherwise best-effort: spawn errors are logged, not thrown. */ export declare function openBrowser(url: string): void; /** * Main entry point. Returns a valid access token. * * - If valid (non-expired) tokens exist on disk → returns `access_token` * - If tokens exist but are expired → refreshes and returns new `access_token` * - If no tokens or refresh fails → starts full OAuth flow */ export declare function authenticate(config: OAuthConfig): Promise; //# sourceMappingURL=oauth.d.ts.map