GitHub OAuth provider

OAuth integration for GitHub. Refer to Create a GitHub OAuth app for getting the required credentials. Provider id is github.

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

const githubAuth = github(auth, config);

github()#

const github: (
	auth: Auth,
	config: {
		clientId: string;
		clientSecret: string;
		scope?: string[];
		redirectUri?: string;
	}
) => GithubProvider;
Parameters#
nametypedescriptionoptional
authAuthLucia instance
config.clientIdstringGitHub OAuth app client id
config.clientSecretstringGitHub OAuth app client secret
config.scopestring[]an array of scopes
config.redirectUristringan authorized redirect URI
Returns#
typedescription
GithubProviderGitHub provider

Interfaces#

GithubAuth#

See OAuth2ProviderAuth.

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

GithubTokens#

type GithubTokens =
	| {
			accessToken: string;
			accessTokenExpiresIn: null;
	  }
	| {
			accessToken: string;
			accessTokenExpiresIn: number;
			refreshToken: string;
			refreshTokenExpiresIn: number;
	  };

GithubUser#

type GithubUser = PublicGithubUser | PrivateGithubUser;

type PublicGithubUser = {
	avatar_url: string;
	bio: string | null;
	blog: string | null;
	company: string | null;
	created_at: string;
	email: string | null;
	events_url: string;
	followers: number;
	followers_url: string;
	following: number;
	following_url: string;
	gists_url: string;
	gravatar_id: string | null;
	hireable: boolean | null;
	html_url: string;
	id: number;
	location: string | null;
	login: string;
	name: string | null;
	node_id: string;
	organizations_url: string;
	public_gists: number;
	public_repos: number;
	received_events_url: string;
	repos_url: string;
	site_admin: boolean;
	starred_url: string;
	subscriptions_url: string;
	type: string;
	updated_at: string;
	url: string;

	twitter_username?: string | null;
	plan?: {
		name: string;
		space: number;
		private_repos: number;
		collaborators: number;
	};
	suspended_at?: string | null;
};

type PrivateGithubUser = PublicGithubUser & {
	collaborators: number;
	disk_usage: number;
	owned_private_repos: number;
	private_gists: number;
	total_private_repos: number;
	two_factor_authentication: boolean;

	business_plus?: boolean;
	ldap_dn?: string;
};

GithubUserAuth#

Extends ProviderUserAuth.

interface GithubUserAuth<_Auth extends Auth> extends ProviderUserAuth<_Auth> {
	githubUser: GithubUser;
	githubTokens: GithubTokens;
}
propertiestypedescription
githubUserGithubUserGitHub user
githubTokensGithubTokensAccess tokens etc
Generics#
nameextends
_AuthAuth