import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js'; import { OAuthClientInformationFull, OAuthClientMetadata, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js'; /** * First leg payload data for OAuth flow initialization. */ export type FirstLegPayload = { authorizationUrl: string; clientInformation: OAuthClientInformationFull; codeVerifier: string; state: string; }; /** * Callback function type for first leg OAuth flow. */ type OnFirstLeg = (payload: FirstLegPayload) => Promise; /** * Configuration for ZapierOAuthClientProvider in different OAuth flow phases. */ type ZapierOAuthClientProviderConfig = { /** First leg: initiate OAuth flow */ phase: 'firstLeg'; onFirstLeg: OnFirstLeg; redirectUrl: string; state: string; scope?: string | null; } | { /** Second leg: exchange code for tokens */ phase: 'secondLeg'; clientInformation: OAuthClientInformationFull; codeVerifier: string; redirectUrl: string; state: string; } | { /** Connected: use existing tokens */ phase: 'connected'; tokens: OAuthTokens; } | { /** Refresh: refresh expired tokens */ phase: 'refresh'; clientInformation: OAuthClientInformationFull; redirectUrl: string; tokens: OAuthTokens; }; /** * OAuth client provider implementation for Zapier-specific OAuth flows. * * This provider handles the complete OAuth 2.0 PKCE flow including: * - First leg: Authorization URL generation * - Second leg: Token exchange * - Connected: Using existing tokens * - Refresh: Token refresh * * @example * ```ts * // First leg - get authorization URL * const provider = new ZapierOAuthClientProvider({ * phase: 'firstLeg', * redirectUrl: 'https://zapier.com/oauth/callback', * state: 'random-state-value', * onFirstLeg: async (payload) => { * console.log('Authorization URL:', payload.authorizationUrl); * } * }); * ``` * * @example * ```ts * // Second leg - exchange code for tokens * const provider = new ZapierOAuthClientProvider({ * phase: 'secondLeg', * clientInformation: firstLegData.clientInformation, * codeVerifier: firstLegData.codeVerifier, * redirectUrl: 'https://zapier.com/oauth/callback', * state: 'random-state-value' * }); * ``` */ export declare class ZapierOAuthClientProvider implements OAuthClientProvider { readonly config: ZapierOAuthClientProviderConfig; private updatedClientInformation; private updatedCodeVerifier; private updatedTokens; /** * Creates a new Zapier OAuth client provider. * * @param config - Configuration for the specific OAuth flow phase */ constructor(config: ZapierOAuthClientProviderConfig); /** * Gets the redirect URL for OAuth flow. * * @returns The redirect URL * @throws {RefreshAuthError} When called during connected phase (indicates auth refresh needed) */ get redirectUrl(): string; /** * Gets the OAuth client metadata with Zapier-specific configuration. * * @returns OAuth client metadata including redirect URIs, grant types, etc. */ get clientMetadata(): OAuthClientMetadata; /** * Gets the state parameter for OAuth flow. * * @returns The OAuth state parameter * @throws {Error} When state is not available in the current phase */ state(): string; /** * Gets the OAuth client information. * * @returns Client information if available, undefined otherwise */ clientInformation(): OAuthClientInformationFull | undefined; /** * Saves the OAuth client information. * * @param clientInformation - The client information to save */ saveClientInformation(clientInformation: OAuthClientInformationFull): void; /** * Gets the PKCE code verifier. * * @returns The code verifier string * @throws {Error} When code verifier is not available in the current phase */ codeVerifier(): string; /** * Saves the PKCE code verifier. * * @param codeVerifier - The code verifier to save */ saveCodeVerifier(codeVerifier: string): void; /** * Redirects to the OAuth authorization URL (first leg). * * @param authorizationUrl - The authorization URL to redirect to * @throws {Error} When client information is not set or onFirstLeg callback is not available */ redirectToAuthorization(authorizationUrl: URL): Promise; /** * Gets the OAuth tokens for the current phase. * * @returns OAuth tokens if available, undefined for firstLeg phase * @throws {Error} When tokens are not available in phases that require them */ tokens(): OAuthTokens | undefined; /** * Saves the OAuth tokens. * * @param tokens - The OAuth tokens to save */ saveTokens(tokens: OAuthTokens): void; } export {}; //# sourceMappingURL=OAuthClientProvider.d.ts.map