Google Provider
Package: @nauth-toolkit/social-google
Type: Social Auth Provider
- npm
- Yarn
- pnpm
- Bun
npm install @nauth-toolkit/social-google
yarn add @nauth-toolkit/social-google
pnpm add @nauth-toolkit/social-google
bun add @nauth-toolkit/social-google
Exports
| Export | Type | Entry |
|---|---|---|
GoogleSocialAuthService | Class | Default |
GoogleOAuthClient | Class | Default |
TokenVerifierService | Class | Default |
VerifiedGoogleTokenProfile | Interface | Default |
GoogleSocialAuthModule | NestJS Module | /nestjs |
Configuration
Configure Google under config.social.google (in @nauth-toolkit/core config).
| Key | Type | Required | Description |
|---|---|---|---|
enabled | boolean | No | Enable Google OAuth |
clientId | string | string[] | Yes (if enabled) | OAuth client ID (supports multi-platform IDs) |
clientSecret | string | Yes (if enabled) | OAuth client secret |
callbackUrl | string | Yes (if enabled) | Backend callback URL (/auth/social/google/callback) |
scopes | string[] | No | Default: ['openid', 'email', 'profile'] |
autoLink | boolean | No | Auto-link to existing users by verified email |
allowSignup | boolean | No | Allow creating new users on first login |
oauthParams | Record<string, string> | No | Additional 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
- NestJS
- Express
- Fastify
import { GoogleSocialAuthModule } from '@nauth-toolkit/social-google/nestjs';
@Module({
imports: [AuthModule.forRoot(config), GoogleSocialAuthModule],
})
export class AppModule {}
const nauth = await NAuth.create({
config,
dataSource,
adapter: new ExpressAdapter(),
});
const nauth = await NAuth.create({
config,
dataSource,
adapter: new FastifyAdapter(),
});
Profile Data
| Field | Type | Description |
|---|---|---|
id | string | Google user ID |
email | string | Email address |
emailVerified | boolean | Email verified by Google |
name | string | Display name |
picture | string | Profile picture URL |