Google OAuth provider

OAuth integration for Google. Refer to Google OAuth documentation for getting the required credentials. Provider id is google.

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

const googleAuth = google(auth, configs);

google()#

const google: (
	auth: Auth,
	configs: {
		clientId: string;
		clientSecret: string;
		redirectUri: string;
		scope?: string[];
		accessType?: "online" | "offline";
	}
) => GoogleProvider;
Parameters#
nametypedescriptionoptionaldefault
authAuthLucia instance
config.clientIdstringGoogle OAuth app client id
config.clientSecretstringGoogle OAuth app client secret
config.redirectUristringan authorized redirect URI
config.scopestring[]an array of scopes
config.accessType"online" | "offline"set to "offline" to get refresh tokens"online"
Returns#
typedescription
GoogleProviderGoogle provider

Interfaces#

GoogleAuth#

See OAuth2ProviderAuth.

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

GoogleTokens#

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

GoogleUser#

type GoogleUser = {
	sub: string;
	name: string;
	given_name: string;
	family_name: string;
	picture: string;
	locale: string;
	email?: string;
	email_verified?: boolean;
	hd?: string;
};

GoogleUserAuth#

Extends ProviderUserAuth.

interface GoogleUserAuth<_Auth extends Auth> extends ProviderUserAuth<_Auth> {
	googleUser: GoogleUser;
	googleTokens: GoogleTokens;
}
propertiestypedescription
googleUserGoogleUserGoogle user
googleTokensGoogleTokensAccess tokens etc
Generics#
nameextends
_AuthAuth