Socket
Socket
Sign inDemoInstall

passport-google-oauth-token

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-google-oauth-token

Google access token authentication strategy for Passport


Version published
Weekly downloads
878
increased by22.11%
Maintainers
1
Install size
218 kB
Created
Weekly downloads
 

Readme

Source

passport-google-oauth-token

Passport strategy for authenticating with Google access tokens using the OAuth 2.0 API.

This module is created based on passport-facebook-token and passport-google-oauth2.

This module lets you authenticate using Google in your Node.js applications. By plugging into Passport, Google authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Installation

$ npm install passport-google-oauth-token

Usage

Configure Strategy

The Google authentication strategy authenticates users using a Google account and OAuth 2.0 tokens. The strategy requires a verify callback, which accepts these credentials and calls cb providing a user, as well as options specifying an app ID and app secret.

const GoogleOauthTokenStrategy = require('passport-google-oauth-token');

passport.use(new GoogleOauthTokenStrategy({
  clientID: GOOGLE_CLIENT_ID,
  clientSecret: GOOGLE_CLIENT_SECRET,
}, (accessToken, refreshToken, profile, cb) => {
  User.findOrCreate({ googleId: profile.id }, (error, user) => {
    return done(error, user);
  });
}));

Authenticate Requests

Use passport.authenticate(), specifying the 'google-oauth-token' strategy, to authenticate requests.

app.post('/auth/google/token',
  passport.authenticate('google-oauth-token'),
  (req, res) => {
    // do something with req.user
    res.send(req.user ? 200 : 401);
  },
);

Client Requests

Clients can send requests to routes that use passport-google-oauth-token authentication using query parms, body, or HTTP headers. Clients will need to transmit the access_token and optionally the refresh_token that are received from google after login.

Options

FieldDescriptionDefault Value
clientIDGoogle's client id
clientSecretGoogle's client secret
tokenURLGoogle's oauth2 token urlhttps://www.googleapis.com/oauth2/v4/token
profileURLGoogle's scope profile urlhttps://www.googleapis.com/oauth2/v3/userinfo
authorizationURLGoogle's oauth2 authorization urlhttps://accounts.google.com/o/oauth2/v2/auth
tokenURLVersionVersion of token urlv4
userinfoURLVersionVersion of profile urlv3
authURLVersionVersion of authorization urlv2

Profile Example

{
  provider: 'google',
  id: '1234',
  displayName: 'Alpha',
  name: {
    familyName: 'Lucifer',
    givenName: 'Alpha',
  },
  emails: [
    {
      value: 'alphanolucifer@gmail.com',
      verified: true,
    },
  ],
  photos: [
    {
      value: 'https://google.com',
    },
  ],
  _json: {},
  _raw: {},
}

License

The MIT License (MIT)

Copyright (c) 2015 Nicholas Penree

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Last updated on 21 May 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc