Giter VIP home page Giter VIP logo

egg-passport-google's Introduction

egg-passport-google

NPM version build status Test coverage David deps Known Vulnerabilities npm download

google passport plugin for egg. only support OAuth 2.0.

Install

$ npm i egg-passport-google --save

Usage

// config/plugin.js
exports.passportGoogle = {
  enable: true,
  package: 'egg-passport-google',
};

Configuration

// config/config.default.js
exports.passportGoogle = {
  key: 'your oauth key',
  secret: 'your oauth secret',
};

see config/config.default.js for more detail.

Questions & Suggestions

Please open an issue here.

License

MIT

egg-passport-google's People

Contributors

sinchang avatar

Watchers

 avatar  avatar  avatar

egg-passport-google's Issues

passport-google-oauth2 改更新到 2.0.0,Google Plus 老的 API 已废弃

jaredhanson/passport-google-oauth2#53

目前的版本已经无法使用了。

修改参考:

  1. passport-google-oauth2 2.0.0
  2. 实现修改(返回结构字段有变化,需要调整一下):
'use strict';

const debug = require('debug')('egg-passport-google');
const assert = require('assert');
const Strategy = require('passport-google-oauth20').Strategy;

module.exports = app => {
  const config = app.config.passportGoogle;
  config.passReqToCallback = true;
  assert(config.key, '[egg-passport-google] config.passportGoogle.key required');
  assert(config.secret, '[egg-passport-google] config.passportGoogle.secret required');
  config.clientID = config.key;
  config.clientSecret = config.secret;

  // must require `req` params
  app.passport.use('google', new Strategy(config, (req, accessToken, refreshToken, params, profile, done) => {
    const email = profile.emails && profile.emails[0] && profile.emails[0].value;
    const photo = profile.photos && profile.photos[0] && profile.photos[0].value;
    const name = email.split('@')[0];
    // format user
    const user = {
      provider: 'google',
      id: profile.id,
      email,
      givenName: name,
      familyName: '',
      displayName: profile.displayName || name,
      photo,
      accessToken,
      refreshToken,
      params,
      profile,
    };
    debug('%s %s get user: %j', req.method, req.url, user);

    // let passport do verify and call verify hook
    app.passport.doVerify(req, user, done);
  }));
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.