节点护照js +重定向不起作用

时间:2017-02-05 18:35:22

标签: javascript node.js passport.js google-authentication passport-google-oauth

我正在使用带有express的节点js。 我正在尝试实施护照google auth。

当我点击谷歌登录链接时,询问gmail用户名和密码,然后允许拒绝按钮,

点击“允许”按钮后,继续加载。

var passport             = require('passport');
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
var configAuth = require('./config');


passport.use(new GoogleStrategy({
    clientID : configAuth.googleAuth.clientID,
    clientSecret : configAuth.googleAuth.clientSecret,
    callbackURL : configAuth.googleAuth.callbackURL,
  },
  function(accessToken, refreshToken, profile, done) {
       /*
       User.findOrCreate({ googleId: profile.id }, function (err, user) {
                return done(err, user);
              });*/
       console.log("rrrrrr");
       return done(err, accessToken);

  }
));

router.get('/auth/google',
  passport.authenticate('google', { scope: ['https://www.googleapis.com/auth/plus.login'] }));

router.get('/auth/google/callback', 
  passport.authenticate('google', { failureRedirect: '/login' }),
  function(req, res) {
           console.log("rddddddddddrrrrr");

    res.redirect('/');
  });

0 个答案:

没有答案