@adonisjs/ally
Version:
Social authentication provider for AdonisJS
86 lines (85 loc) • 4.17 kB
TypeScript
import type { HttpContext } from '@adonisjs/core/http';
import type { ConfigProvider } from '@adonisjs/core/types';
import type { GoogleDriver } from './drivers/google.ts';
import type { GithubDriver } from './drivers/github.ts';
import type { SpotifyDriver } from './drivers/spotify.ts';
import type { TwitterDriver } from './drivers/twitter.ts';
import type { TwitterXDriver } from './drivers/twitter_x.ts';
import type { DiscordDriver } from './drivers/discord.ts';
import type { FacebookDriver } from './drivers/facebook.ts';
import type { LinkedInDriver } from './drivers/linked_in.ts';
import type { LinkedInOpenidConnectDriver } from './drivers/linked_in_openid_connect.ts';
import type { GoogleDriverConfig, GithubDriverConfig, SpotifyDriverConfig, DiscordDriverConfig, TwitterDriverConfig, TwitterXDriverConfig, LinkedInDriverConfig, LinkedInOpenidConnectDriverConfig, FacebookDriverConfig, AllyManagerDriverFactory } from './types.ts';
/**
* Shape of config after it has been resolved from
* the config provider
*
* Maps config providers to their resolved driver factory values.
*/
type ResolvedConfig<KnownSocialProviders extends Record<string, AllyManagerDriverFactory | ConfigProvider<AllyManagerDriverFactory>>> = {
[K in keyof KnownSocialProviders]: KnownSocialProviders[K] extends ConfigProvider<infer A> ? A : KnownSocialProviders[K];
};
/**
* Define configuration for Ally social authentication providers.
* This function accepts a map of provider names to their factory
* functions or config providers.
*
* @param config - An object mapping provider names to driver factories
* @returns A config provider that resolves all registered providers.
*
* @example
* ```ts
* export default defineConfig({
* github: services.github({
* clientId: env.get('GITHUB_CLIENT_ID'),
* clientSecret: env.get('GITHUB_CLIENT_SECRET'),
* callbackUrl: 'http://localhost:3333/github/callback'
* }),
* google: services.google({
* clientId: env.get('GOOGLE_CLIENT_ID'),
* clientSecret: env.get('GOOGLE_CLIENT_SECRET'),
* callbackUrl: 'http://localhost:3333/google/callback'
* })
* })
* ```
*/
export declare function defineConfig<KnownSocialProviders extends Record<string, AllyManagerDriverFactory | ConfigProvider<AllyManagerDriverFactory>>>(config: KnownSocialProviders): ConfigProvider<ResolvedConfig<KnownSocialProviders>>;
/**
* Pre-configured helpers for setting up built-in social authentication
* providers. Each method accepts provider-specific configuration and
* returns a config provider that lazily loads and instantiates the driver.
*
* @example
* ```ts
* const github = services.github({
* clientId: env.get('GITHUB_CLIENT_ID'),
* clientSecret: env.get('GITHUB_CLIENT_SECRET'),
* callbackUrl: 'http://localhost:3333/github/callback',
* disallowLocalSignup: true,
* })
* ```
*
* @example
* ```ts
* export default defineConfig({
* github: services.github({
* clientId: env.get('GITHUB_CLIENT_ID'),
* clientSecret: env.get('GITHUB_CLIENT_SECRET'),
* callbackUrl: 'http://localhost:3333/github/callback',
* scopes: ['user', 'user:email']
* })
* })
* ```
*/
export declare const services: {
discord: (config: DiscordDriverConfig) => ConfigProvider<(ctx: HttpContext) => DiscordDriver>;
facebook: (config: FacebookDriverConfig) => ConfigProvider<(ctx: HttpContext) => FacebookDriver>;
github: (config: GithubDriverConfig) => ConfigProvider<(ctx: HttpContext) => GithubDriver>;
google: (config: GoogleDriverConfig) => ConfigProvider<(ctx: HttpContext) => GoogleDriver>;
linkedin: (config: LinkedInDriverConfig) => ConfigProvider<(ctx: HttpContext) => LinkedInDriver>;
linkedinOpenidConnect: (config: LinkedInOpenidConnectDriverConfig) => ConfigProvider<(ctx: HttpContext) => LinkedInOpenidConnectDriver>;
spotify: (config: SpotifyDriverConfig) => ConfigProvider<(ctx: HttpContext) => SpotifyDriver>;
twitter: (config: TwitterDriverConfig) => ConfigProvider<(ctx: HttpContext) => TwitterDriver>;
twitterX: (config: TwitterXDriverConfig) => ConfigProvider<(ctx: HttpContext) => TwitterXDriver>;
};
export {};