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#
name | type | description | optional | default |
---|
auth | Auth | Lucia instance | | |
config.clientId | string | Google OAuth app client id | | |
config.clientSecret | string | Google OAuth app client secret | | |
config.redirectUri | string | an authorized redirect URI | | |
config.scope | string[] | an array of scopes | ✓ | |
config.accessType | "online" | "offline" | set to "offline" to get refresh tokens | ✓ | "online" |
Returns#
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#
name | extends | default |
---|
_Auth | Auth | Auth |
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;
}
Generics#