Skip to main content

Google Provider

Package: @nauth-toolkit/social-google Type: Social Auth Provider

npm install @nauth-toolkit/social-google

Exports

ExportTypeEntry
GoogleSocialAuthServiceClassDefault
GoogleOAuthClientClassDefault
TokenVerifierServiceClassDefault
VerifiedGoogleTokenProfileInterfaceDefault
GoogleSocialAuthModuleNestJS Module/nestjs

Configuration

Configure Google under config.social.google (in @nauth-toolkit/core config).

KeyTypeRequiredDescription
enabledbooleanNoEnable Google OAuth
clientIdstring | string[]Yes (if enabled)OAuth client ID (supports multi-platform IDs)
clientSecretstringYes (if enabled)OAuth client secret
callbackUrlstringYes (if enabled)Backend callback URL (/auth/social/google/callback)
scopesstring[]NoDefault: ['openid', 'email', 'profile']
autoLinkbooleanNoAuto-link to existing users by verified email
allowSignupbooleanNoAllow creating new users on first login
oauthParamsRecord<string, string>NoAdditional OAuth parameters to include in authorization URL. These act as defaults and can be overridden on a per-request basis.

OAuth Parameters

The oauthParams option allows you to customize the OAuth authorization flow. These parameters are appended to Google's authorization URL and can be overridden on a per-request basis from the frontend.

Common Parameters:

  • prompt: Control consent screen behavior
    • 'select_account' - Always show account chooser
    • 'consent' - Always show consent screen
    • 'none' - Silent authentication (fails if user interaction needed)
    • Combined: 'select_account consent'
  • hd: Restrict to Google Workspace domain (e.g., 'company.com')
  • login_hint: Pre-fill email address (e.g., 'user@company.com')
  • include_granted_scopes: 'true' for incremental authorization

Example:

social: {
google: {
enabled: true,
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackUrl: 'https://api.myapp.com/auth/social/google/callback',
scopes: ['openid', 'email', 'profile'],
oauthParams: {
prompt: 'select_account', // Always show account chooser
hd: 'company.com', // Restrict to company domain
},
},
}

See Social Login Guide for usage examples.

Usage

import { GoogleSocialAuthModule } from '@nauth-toolkit/social-google/nestjs';

@Module({
imports: [AuthModule.forRoot(config), GoogleSocialAuthModule],
})
export class AppModule {}

Profile Data

FieldTypeDescription
idstringGoogle user ID
emailstringEmail address
emailVerifiedbooleanEmail verified by Google
namestringDisplay name
picturestringProfile picture URL