Google Login OAuth 2.0 flow
Google oAuth flow to retrieve access & refresh token
Feature
This package can be used to get Google access token and refresh token for an user access token.
Implements a server-Side flow for login with Google, similar to one provided by Facebook or Twitter.
This can be used to get User Access Token to make API calls to Google, like getting access to Google My Business
Installation
-
Clone as a Git repository
git clone https://github.com/knitesh/google-login.git -
Install as a node_module
npm i google-oauth-login --saveORnpm install google-oauth-login --save
Usage
To initialize Google oAuth function
config
where config will be
const config = clientId clientSecret scope redirectUri
To get oAuth URl for user consent and login
await google
To extract code received from Google
await google
To get access token and refresh token(if accessType = offline)
await google
Sample Express app
const express = const GoogleLogin = const app = const port = 9000 const google = clientId:<<your Google oAuth Client Id> clientSecret: <<your Google oAuth Client Secret> redirectUri: 'http://localhost:9000/google/oauth/callback' scope: 'https://www.googleapis.com/auth/userinfo.profile' accessType: 'offline' // to get refresh token pass access type: offline prompt: 'consent' // to prompt user everytime app // This is the Authrized redirect URl that needs to be added to oAuth Client Id generation screen// Google will send the code and related scope as query string to this Urlapp app app