Discord OAuth provider

OAuth integration for Discord. Refer to Discord API documentation for getting the required credentials. Provider id is discord.

import { discord } from "@lucia-auth/oauth/providers";
import { auth } from "./lucia.js";

const discordAuth = discord(auth, config);

The identify scope is always included regardless of provided scope config.

discord()#

const discord: (
	auth: Auth,
	config: {
		clientId: string;
		clientSecret: string;
		redirectUri: string;
		scope?: string[];
	}
) => DiscordProvider;
Parameters#
nametypedescriptionoptional
authAuthLucia instance
config.clientIdstringDiscord OAuth app client id
config.clientSecretstringDiscord OAuth app client secret
config.redirectUristringan authorized redirect URI
config.scopestring[]an array of scopes - identify is always included
Returns#
typedescription
DiscordProviderDiscord provider

Interfaces#

DiscordAuth#

See OAuth2ProviderAuth.

// implements OAuth2ProviderAuth<DiscordAuth<_Auth>>
interface DiscordAuth<_Auth extends Auth> {
	getAuthorizationUrl: () => Promise<readonly [url: URL, state: string]>;
	validateCallback: (code: string) => Promise<DiscordUserAuth<_Auth>>;
}
Generics#
nameextendsdefault
_AuthAuthAuth

DiscordTokens#

type DiscordTokens = {
	accessToken: string;
	refreshToken: string;
	accessTokenExpiresIn: number;
};

DiscordUser#

type DiscordUser = {
	id: string;
	username: string;
	discriminator: string;
	global_name: string | null;
	avatar: string | null;
	bot?: boolean;
	system?: boolean;
	mfa_enabled?: boolean;
	verified?: boolean;
	email?: string | null;
	flags?: number;
	banner?: string | null;
	accent_color?: number | null;
	premium_type?: number;
	public_flags?: number;
	locale?: string;
	avatar_decoration?: string | null;
};

DiscordUserAuth#

Extends ProviderUserAuth.

interface DiscordUserAuth<_Auth extends Auth> extends ProviderUserAuth<_Auth> {
	discordUser: DiscordUser;
	discordTokens: DiscordTokens;
}
propertiestypedescription
discordUserDiscordUserDiscord user
discordTokensDiscordTokensAccess tokens etc
Generics#
nameextends
_AuthAuth