Gathering detailed insights and metrics for passport-google-oauth20
Gathering detailed insights and metrics for passport-google-oauth20
Gathering detailed insights and metrics for passport-google-oauth20
Gathering detailed insights and metrics for passport-google-oauth20
@types/passport-google-oauth20
TypeScript definitions for passport-google-oauth20
passport-google-oauth
Google (OAuth) authentication strategies for Passport.
passport-google-oauth1
Google (OAuth 1.0) authentication strategy for Passport.
passport-google-oauth2-sock5agent
fork from passport-google-oauth20, support sock5 agent
Google authentication strategy for Passport and Node.js.
npm install passport-google-oauth20
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
825 Stars
86 Commits
153 Forks
31 Watching
1 Branches
2 Contributors
Updated on 26 Nov 2024
JavaScript (99.65%)
Makefile (0.35%)
Cumulative downloads
Total Downloads
Last day
-3.8%
71,053
Compared to previous day
Last week
2.1%
382,666
Compared to previous week
Last month
14.7%
1,566,683
Compared to previous month
Last year
12.3%
15,112,109
Compared to previous year
1
4
Passport strategy for authenticating with Google using OAuth 2.0.
This module lets you authenticate using Google in your Node.js applications. By plugging into Passport, Sign In with Google can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
:brain: Understanding OAuth 2.0 • :heart: Sponsors
1$ npm install passport-google-oauth20
1$ npm install @types/passport-google-oauth20
The Google strategy authenticates users using their Google account. Before your application can make use of Google's authentication system, you must first register your app to use OAuth 2.0 with Google APIs. Once registered, a client ID and secret will be issued which are used by Google to identify your app.
Once you've registered your application, the strategy needs to be configured with your application's client ID and secret, along with its OAuth 2.0 redirect endpoint.
The strategy takes a verify
function as an argument, which accepts
accessToken
, refreshToken
, and profile
as arguments. accessToken
and
refreshToken
are used for API access, and are not needed for authentication.
profile
contains the user's profile information
stored in their Google account. When authenticating a user, this strategy uses
the OAuth 2.0 protocol to obtain this information via a sequence of redirects
and API requests to Google.
The verify
function is responsible for determining the user to which the
Google account belongs. In cases where the account is logging in for the
first time, a new user record is typically created automatically. On subsequent
logins, the existing user record will be found via its relation to the Google
account.
Because the verify
function is supplied by the application, the app is free to
use any database of its choosing. The example below illustrates usage of a SQL
database.
1var GoogleStrategy = require('passport-google-oauth20'); 2 3passport.use(new GoogleStrategy({ 4 clientID: process.env['GOOGLE_CLIENT_ID'], 5 clientSecret: process.env['GOOGLE_CLIENT_SECRET'], 6 callbackURL: 'https://www.example.com/oauth2/redirect/google', 7 scope: [ 'profile' ], 8 state: true 9 }, 10 function verify(accessToken, refreshToken, profile, cb) { 11 db.get('SELECT * FROM federated_credentials WHERE provider = ? AND subject = ?', [ 12 'https://accounts.google.com', 13 profile.id 14 ], function(err, cred) { 15 if (err) { return cb(err); } 16 17 if (!cred) { 18 // The account at Google has not logged in to this app before. Create a 19 // new user record and associate it with the Google account. 20 db.run('INSERT INTO users (name) VALUES (?)', [ 21 profile.displayName 22 ], function(err) { 23 if (err) { return cb(err); } 24 25 var id = this.lastID; 26 db.run('INSERT INTO federated_credentials (user_id, provider, subject) VALUES (?, ?, ?)', [ 27 id, 28 'https://accounts.google.com', 29 profile.id 30 ], function(err) { 31 if (err) { return cb(err); } 32 33 var user = { 34 id: id, 35 name: profile.displayName 36 }; 37 return cb(null, user); 38 }); 39 }); 40 } else { 41 // The account at Google has previously logged in to the app. Get the 42 // user record associated with the Google account and log the user in. 43 db.get('SELECT * FROM users WHERE id = ?', [ cred.user_id ], function(err, user) { 44 if (err) { return cb(err); } 45 if (!user) { return cb(null, false); } 46 return cb(null, user); 47 }); 48 } 49 }); 50 } 51));
Two routes are needed in order to allow users to log in with their Google account. The first route redirects the user to the Google, where they will authenticate:
1app.get('/login/google', passport.authenticate('google'));
The second route processes the authentication response and logs the user in, after Google redirects the user back to the app:
1app.get('/oauth2/redirect/google', 2 passport.authenticate('google', { failureRedirect: '/login', failureMessage: true }), 3 function(req, res) { 4 res.redirect('/'); 5 });
Using OAuth 2.0 to Access Google APIs
Official Google documentation on how to use OAuth 2.0 to access Google APIs.
Illustrates how to use the Google strategy within an Express application.
Passport strategy for authenticating with Google using OpenID Connect.
Copyright (c) 2012-2023 Jared Hanson
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More