🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

nest-google-oauth2

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nest-google-oauth2

A google-oauth2 client for nestjs

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

Description

Google-OAuth2 Module for Nest.

Installation

$ npm install nest-google-oauth2

Usage

Injecting the GoogleOAuth2Module

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AuthenticationService } from './authentication.service';
import { AuthenticationController } from './authentication.controller';
import { GoogleOAuth2Module } from 'nest-google-oauth2';

@Module({
  imports: [
    ConfigModule,
    GoogleOAuth2Module.registerAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        return {
          clientId: configService.get('GOOGLE_CLIENT_ID'),
          clientSecret: configService.get('GOOGLE_SECRET'),
        };
      },
    }),
  ],
  controllers: [AuthenticationController],
  providers: [AuthenticationService],
})
export class AuthenticationModule {}

Using the GoogleOAuth2Service

import { Injectable } from '@nestjs/common';
import { GoogleOAuth2Service } from 'nest-google-oauth2';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class AuthenticationService {
  constructor(
    private readonly configService: ConfigService,
    private readonly googleOAuth2Service: GoogleOAuth2Service,
  ) {}
  public async googleOauth(data: { accessToken: string }) {
    const tokenInfo = await this.googleOAuth2Service.getTokenInfo(
      data.accessToken,
    );
    console.log(tokenInfo);
    const ticket = await this.googleOAuth2Service.verifyIdToken({
      idToken: data.accessToken,
      audience: this.configService.get('GOOGLE_CLIENT_ID'),
    });
    return ticket.getPayload();
  }
}


Stay in touch

License

nest-google-oauth2 is MIT licensed.

Keywords

google-oauth2

FAQs

Package last updated on 05 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts