UNPKG

@ioloco/oauth

Version:

OAuth 2.0 utility library that provides helper functions for integrating third-party login providers. Designed to simplify the token exchange and user-fetch flows, while leaving API route implementation to the developer.

42 lines (41 loc) 1.34 kB
import { z } from 'zod'; import { AuthUrlOptions, Cookies, OauthProvider, OAuthTokenResponse, OAuthUserResult } from '../@Types'; export declare class OAuthClient<T> { readonly provider: OauthProvider; private readonly urls; private readonly clientId; private readonly clientSecret; private readonly scopes; private readonly userInfo; private readonly tokenSchema; constructor({ provider, urls, clientId, clientSecret, scopes, userInfo }: { provider: OauthProvider; urls: { auth: string; token: string; user: string; redirect_base: string; }; clientId: string; clientSecret: string; scopes: string[]; userInfo: { schema: z.ZodSchema<T>; parser: (data: T) => { id: string; email: string; name: string; }; }; }); createAuthUrl(cookies: Pick<Cookies, 'set'>, options?: AuthUrlOptions): Promise<string>; fetchToken({ code, codeVerifier }: { code: string; codeVerifier: string; }): Promise<OAuthTokenResponse>; fetchUser({ code, state, cookies }: { code: string; state: string; cookies: Pick<Cookies, 'get' | 'delete'>; }): Promise<OAuthUserResult>; }