passport-google-strategy

1.0.3 • Public • Published

passport-google-strategy

passport strategy that uses google-auth library to verify id token before logging in user

This strategy is an authentication strategy based on google's recommended signin practice google-signin

A custom strategy that utilizes google's recommended google-auth-library and is based on passport-strategy

Usage

Install

npm install passport-google-strategy --save

Configure Strategy

var passport = require("passport");
var CustomGoogleStrategy = require("passport-google-strategy");
module.exports = function (passport, User) {
  passport.use(
    new CustomGoogleStrategy(
      { clientId: process.env.GOOGLE_CLIENT_ID },
      function (req, payload, cb) {
        User.findOrCreate({
          where: {
            oAuthID: payload.sub,
          },
          defaults: {
            username: payload.name,
            email: payload.email,
            active: true,
          },
        })
          .then(function (user) {
            return cb(null, user[0]);
          })
          .catch(function (err) {
            return cb(err, null);
          });
      }
    )
  );
};

Authenticate Requests

var passport = require("passport");
module.exports = function (app, User) {
  app.get("/verifygoogle", passport.authenticate("custom-google"), function (
    req,
    res
  ) {
    // do something with req.user
    res.status(200).send({ username: req.session.passport.user.username });
  });
};

License

Apache 2.0

Dependencies (2)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i passport-google-strategy

    Weekly Downloads

    6

    Version

    1.0.3

    License

    Apache-2.0

    Unpacked Size

    17.1 kB

    Total Files

    7

    Last publish

    Collaborators

    • humaidk2