简体   繁体   English

password.js Facebook身份验证接下来无法正常工作

[英]passport.js facebook authentication next not working

The passport.js strategy that I am trying to implement is the one for the facebook provider. 我尝试实施的passport.js策略是针对facebook提供者的策略。 I have tested with the text book example (from https://github.com/passport/express-4.x-facebook-example ) and it seems the redirect is never called. 我已经测试了教科书示例(来自https://github.com/passport/express-4.x-facebook-example ),似乎从未调用过重定向。

The redirect sequence works fine except when the user is logged in, it redirects to the homepage, even when explicitly putting a different URL in the callback. 重定向序列可以正常工作,除非用户登录后可以重定向到主页,即使在回调中显式放置其他URL也不例外。

So everything works except the last redirect, which should end up at https://xx.com/testing which never happens. 因此,除最后一次重定向外,其他所有操作均正常进行,该重定向最终应在https://xx.com/testing处结束,但永远不会发生。

nodejs 6, express 4+, passport 3.2 nodejs 6,Express 4+,护照3.2

What is going wrong? 怎么了?

Strategy 战略

passport.use(new FacebookStrategy({
  clientID: xx,
  clientSecret: 'xx',
  callbackURL: 'https://xx.com/auth/facebook/callback/',
  profileFields: ['id', 'email', 'name', 'displayName']
},
  function (accessToken, refreshToken, profile, done) {
      return done(null, profile)
  }
))

Route 路线

router.get('/auth/facebook', passport.authenticate('facebook', {scope: ['public_profile', 'email']}))
router.get('/auth/facebook/callback',
  passport.authenticate('facebook', { failureRedirect: '/login' }),
  function(req, res) {
    // never gets called
    console.log('I don't get called!!!')
    res.redirect('/testing')
  })

/testing goes to successRedirect /testing进入成功successRedirect

passport.authenticate('facebook', { 
    successRedirect: '/testing',
    failureRedirect: '/login'
}));

UPDATE: Use passport.authorize 更新:使用passport.authorize

router.get('/auth/facebook/callback',
    passport.authorize('facebook', { failureRedirect: '/login' }),
    function(req, res) {
       res.redirect('/testing')
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM