/** * OAuth 2.0 client for Yahoo Fantasy Sports API * @module */ /** * OAuth 2.0 endpoints for Yahoo */ export declare const OAUTH2_ENDPOINTS: { /** * Authorization URL (user must visit this) */ readonly AUTHORIZE: "https://api.login.yahoo.com/oauth2/request_auth"; /** * Token endpoint (for getting and refreshing tokens) */ readonly TOKEN: "https://api.login.yahoo.com/oauth2/get_token"; }; /** * OAuth 2.0 tokens */ export interface OAuth2Tokens { /** * OAuth 2.0 access token (Bearer token) */ accessToken: string; /** * Token type (always "bearer") */ tokenType: string; /** * Access token lifetime in seconds (usually 3600 = 1 hour) */ expiresIn: number; /** * Refresh token for getting new access tokens */ refreshToken: string; /** * Calculated timestamp when the token expires */ expiresAt: number; /** * Yahoo user GUID (optional, deprecated) */ yahooGuid?: string; } /** * OAuth 2.0 client for Yahoo authentication * * Implements the Authorization Code Grant flow: * 1. Get authorization URL * 2. User authorizes and gets redirected with code * 3. Exchange code for access token and refresh token * 4. Refresh access token when it expires * * @example * ```typescript * const oauth2 = new OAuth2Client( * clientId, * clientSecret, * 'https://example.com/callback' * ); * * // Step 1: Get auth URL * const authUrl = oauth2.getAuthorizationUrl(); * * // Step 2: User visits URL and gets redirected * // Extract code from redirect: ?code=AUTHORIZATION_CODE * * // Step 3: Exchange code for tokens * const tokens = await oauth2.exchangeCodeForToken(code); * * // Step 4: Refresh when needed * const newTokens = await oauth2.refreshAccessToken(tokens.refreshToken); * ``` */ export declare class OAuth2Client { private clientId; private clientSecret; private redirectUri?; /** * Creates a new OAuth 2.0 client * * @param clientId - OAuth client ID (Consumer Key) from Yahoo Developer * @param clientSecret - OAuth client secret (Consumer Secret) from Yahoo Developer * @param redirectUri - Optional redirect URI (required for user auth methods) */ constructor(clientId: string, clientSecret: string, redirectUri?: string); /** * Generates the authorization URL for the user to visit * * @param state - Optional state parameter for CSRF protection * @param language - Optional language code (default: 'en-us') * @returns Authorization URL to redirect user to * @throws {ConfigError} If redirectUri was not provided in constructor * * @example * ```typescript * const authUrl = oauth2.getAuthorizationUrl('random-state-string'); * console.log('Visit:', authUrl); * ``` */ getAuthorizationUrl(state?: string, language?: string): string; /** * Exchanges an authorization code for access and refresh tokens * * @param code - Authorization code from the redirect callback * @returns OAuth 2.0 tokens * @throws {AuthenticationError} If the token exchange fails * @throws {ConfigError} If redirectUri was not provided in constructor * * @example * ```typescript * // After user authorizes and is redirected to: * // https://your-redirect-uri?code=AUTHORIZATION_CODE * const tokens = await oauth2.exchangeCodeForToken(code); * ``` */ exchangeCodeForToken(code: string): Promise; /** * Refreshes the access token using a refresh token * * @param refreshToken - The refresh token from previous authentication * @returns New OAuth 2.0 tokens (includes new refresh token) * @throws {AuthenticationError} If the token refresh fails * @throws {ConfigError} If redirectUri was not provided in constructor * * @example * ```typescript * const newTokens = await oauth2.refreshAccessToken(oldTokens.refreshToken); * ``` */ refreshAccessToken(refreshToken: string): Promise; /** * Makes a token request to Yahoo OAuth 2.0 API * * @param body - URL-encoded request body * @returns OAuth 2.0 tokens * @throws {AuthenticationError} If the request fails * @private */ private requestToken; /** * Checks if an access token is expired or will expire soon * * @param tokens - The OAuth 2.0 tokens to check * @param bufferSeconds - Time buffer in seconds before actual expiration (default: 60) * @returns True if the token is expired or will expire within the buffer time * * @example * ```typescript * if (oauth2.isTokenExpired(tokens)) { * tokens = await oauth2.refreshAccessToken(tokens.refreshToken); * } * ``` */ isTokenExpired(tokens: OAuth2Tokens, bufferSeconds?: number): boolean; /** * Gets the time until the token expires * * @param tokens - The OAuth 2.0 tokens to check * @returns Time in seconds until expiration (negative if already expired) * * @example * ```typescript * const secondsRemaining = oauth2.getTimeUntilExpiration(tokens); * console.log(`Token expires in ${secondsRemaining} seconds`); * ``` */ getTimeUntilExpiration(tokens: OAuth2Tokens): number; } //# sourceMappingURL=OAuth2Client.d.ts.map