@redredgroup/nestjs-google-auth
v1.0.0
Published
Google Authentication integration to a NestJS application
Downloads
4
Maintainers
Readme
Nestjs Google Auth

Introduction
This package is a module that integrates Google Authentication to NestJS application.
Installation
using npm
npm install @redredgroup/nestjs-google-authusing yarn
yarn add @redredgroup/nestjs-google-authusing pnpm
pnpm add @redredgroup/nestjs-google-authImport module
import { Module } from '@nestjs/common';
import { GoogleAuthModule } from '@redredgroup/nestjs-google-auth';
@Module({
imports: [
GoogleAuthModule.forRoot({
clientId: 'YOUR_GOOGLE_CLIENT_ID',
clientSecret: 'YOUR_GOOGLE_CLIENT_SECRET',
redirectUri: 'YOUR_REDIRECT_URI',
}),
],
})
export class AppModule {}
//Or the forRootAsync module using @nestjs/Config
import { Module } from '@nestjs/common';
import { GoogleAuthModule } from '@redredgroup/nestjs-google-auth';
import { ConfigModule, ConfigService } from '@nestjs/config';
@Module({
imports: [
GoogleAuthModule.forRootAsync({
useFactory: (configService: ConfigService) => ({
clientId: configService.get('GOOGLE_CLIENT_ID'),
clientSecret: configService.get('GOOGLE_CLIENT_SECRET'),
redirectUri: configService.get('GOOGLE_REDIRECT_URI'),
}),
inject: [ConfigService],
}),
],
})
export class AppModule {}Example
OAuth2 Client
import { Injectable } from '@nestjs/common';
import { GoogleAuthService } from '@redredgroup/nestjs-google-auth';
@Injectable()
export class AppService {
constructor(private readonly googleAuthService: GoogleAuthService) {}
async getAuthUrl(): string {
const authUrl = this.googleAuthService.generateAuthUrl({
scope: ['https://www.googleapis.com/auth/userinfo.email'],
});
return authUrl;
}
async getUserInfo(code: string) {
const { tokens } = await this.googleAuthService.getToken(code);
const userInfo = await this.googleAuthService.getUserInfo(tokens.access_token);
return userInfo;
}
}Copyright
© 2025 REDREDGROUP Software. All Right Reserved.
License
Apache-2.0
