import * as better_call from 'better-call'; import { z } from 'zod'; import { U as User, l as AuthContext } from '../../shared/better-auth.DijUyhfq.cjs'; import { O as OAuth2Tokens, a as OAuthProvider } from '../../shared/better-auth.WtOxsS45.cjs'; import '../../shared/better-auth.Bi8FQwDD.cjs'; import 'kysely'; import 'better-sqlite3'; import 'jose'; /** * Configuration interface for generic OAuth providers. */ interface GenericOAuthConfig { /** Unique identifier for the OAuth provider */ providerId: string; /** * URL to fetch OAuth 2.0 configuration. * If provided, the authorization and token endpoints will be fetched from this URL. */ discoveryUrl?: string; /** * URL for the authorization endpoint. * Optional if using discoveryUrl. */ authorizationUrl?: string; /** * URL for the token endpoint. * Optional if using discoveryUrl. */ tokenUrl?: string; /** * URL for the user info endpoint. * Optional if using discoveryUrl. */ userInfoUrl?: string; /** OAuth client ID */ clientId: string; /** OAuth client secret */ clientSecret: string; /** * Array of OAuth scopes to request. * @default [] */ scopes?: string[]; /** * Custom redirect URI. * If not provided, a default URI will be constructed. */ redirectURI?: string; /** * OAuth response type. * @default "code" */ responseType?: string; /** * The response mode to use for the authorization code request. */ responseMode?: "query" | "form_post"; /** * Prompt parameter for the authorization request. * Controls the authentication experience for the user. */ prompt?: "none" | "login" | "consent" | "select_account"; /** * Whether to use PKCE (Proof Key for Code Exchange) * @default false */ pkce?: boolean; /** * Access type for the authorization request. * Use "offline" to request a refresh token. */ accessType?: string; /** * Custom function to fetch user info. * If provided, this function will be used instead of the default user info fetching logic. * @param tokens - The OAuth tokens received after successful authentication * @returns A promise that resolves to a User object or null */ getUserInfo?: (tokens: OAuth2Tokens) => Promise; /** * Custom function to map the user profile to a User object. */ mapProfileToUser?: (profile: Record) => { id?: string; name?: string; email?: string; image?: string; emailVerified?: boolean; [key: string]: any; } | Promise<{ id?: string; name?: string; email?: string; image?: string; emailVerified?: boolean; [key: string]: any; }>; /** * Additional search-params to add to the authorizationUrl. * Warning: Search-params added here overwrite any default params. */ authorizationUrlParams?: Record; /** * Disable implicit sign up for new users. When set to true for the provider, * sign-in need to be called with with requestSignUp as true to create new users. */ disableImplicitSignUp?: boolean; /** * Disable sign up for new users. */ disableSignUp?: boolean; /** * Authentication method for token requests. * @default "post" */ authentication?: "basic" | "post"; } interface GenericOAuthOptions { /** * Array of OAuth provider configurations. */ config: GenericOAuthConfig[]; } /** * A generic OAuth plugin that can be used to add OAuth support to any provider */ declare const genericOAuth: (options: GenericOAuthOptions) => { id: "generic-oauth"; init: (ctx: AuthContext) => { context: { socialProviders: OAuthProvider>[]; }; }; endpoints: { signInWithOAuth2: { ; errorCallbackURL: z.ZodOptional; newUserCallbackURL: z.ZodOptional; disableRedirect: z.ZodOptional; scopes: z.ZodOptional>; requestSignUp: z.ZodOptional; }, "strip", z.ZodTypeAny, { providerId: string; scopes?: string[] | undefined; callbackURL?: string | undefined; requestSignUp?: boolean | undefined; errorCallbackURL?: string | undefined; newUserCallbackURL?: string | undefined; disableRedirect?: boolean | undefined; }, { providerId: string; scopes?: string[] | undefined; callbackURL?: string | undefined; requestSignUp?: boolean | undefined; errorCallbackURL?: string | undefined; newUserCallbackURL?: string | undefined; disableRedirect?: boolean | undefined; }>; metadata: { openapi: { description: string; responses: { 200: { description: string; content: { "application/json": { schema: { type: "object"; properties: { url: { type: string; }; redirect: { type: string; }; }; }; }; }; }; }; }; }; } & { use: any[]; }>]>(...inputCtx: C): Promise; options: { method: "POST"; body: z.ZodObject<{ providerId: z.ZodString; callbackURL: z.ZodOptional; errorCallbackURL: z.ZodOptional; newUserCallbackURL: z.ZodOptional; disableRedirect: z.ZodOptional; scopes: z.ZodOptional>; requestSignUp: z.ZodOptional; }, "strip", z.ZodTypeAny, { providerId: string; scopes?: string[] | undefined; callbackURL?: string | undefined; requestSignUp?: boolean | undefined; errorCallbackURL?: string | undefined; newUserCallbackURL?: string | undefined; disableRedirect?: boolean | undefined; }, { providerId: string; scopes?: string[] | undefined; callbackURL?: string | undefined; requestSignUp?: boolean | undefined; errorCallbackURL?: string | undefined; newUserCallbackURL?: string | undefined; disableRedirect?: boolean | undefined; }>; metadata: { openapi: { description: string; responses: { 200: { description: string; content: { "application/json": { schema: { type: "object"; properties: { url: { type: string; }; redirect: { type: string; }; }; }; }; }; }; }; }; }; } & { use: any[]; }; path: "/sign-in/oauth2"; }; oAuth2Callback: { ; error: z.ZodOptional; error_description: z.ZodOptional; state: z.ZodOptional; }, "strip", z.ZodTypeAny, { state?: string | undefined; code?: string | undefined; error?: string | undefined; error_description?: string | undefined; }, { state?: string | undefined; code?: string | undefined; error?: string | undefined; error_description?: string | undefined; }>; metadata: { openapi: { description: string; responses: { 200: { description: string; content: { "application/json": { schema: { type: "object"; properties: { url: { type: string; }; }; }; }; }; }; }; }; }; } & { use: any[]; }>]>(...inputCtx: C): Promise; options: { method: "GET"; query: z.ZodObject<{ code: z.ZodOptional; error: z.ZodOptional; error_description: z.ZodOptional; state: z.ZodOptional; }, "strip", z.ZodTypeAny, { state?: string | undefined; code?: string | undefined; error?: string | undefined; error_description?: string | undefined; }, { state?: string | undefined; code?: string | undefined; error?: string | undefined; error_description?: string | undefined; }>; metadata: { openapi: { description: string; responses: { 200: { description: string; content: { "application/json": { schema: { type: "object"; properties: { url: { type: string; }; }; }; }; }; }; }; }; }; } & { use: any[]; }; path: "/oauth2/callback/:providerId"; }; oAuth2LinkAccount: { ; use: ((inputContext: better_call.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; name: string; email: string; emailVerified: boolean; createdAt: Date; updatedAt: Date; image?: string | null | undefined; }; }; }>)[]; } & { use: any[]; }>]>(...inputCtx: C): Promise; options: { method: "POST"; body: z.ZodObject<{ providerId: z.ZodString; callbackURL: z.ZodString; }, "strip", z.ZodTypeAny, { providerId: string; callbackURL: string; }, { providerId: string; callbackURL: string; }>; use: ((inputContext: better_call.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; name: string; email: string; emailVerified: boolean; createdAt: Date; updatedAt: Date; image?: string | null | undefined; }; }; }>)[]; } & { use: any[]; }; path: "/oauth2/link"; }; }; $ERROR_CODES: { readonly INVALID_OAUTH_CONFIGURATION: "Invalid OAuth configuration"; }; }; export { genericOAuth };