[英]passport-facebook not doing a redirect
Here's my silly nodejs module. 这是我愚蠢的nodejs模块。 When
passport.authenticate('facebook')
is called it just freezes. 调用
passport.authenticate('facebook')
,它会冻结。
I'm using Express 4.2.0. 我正在使用Express 4.2.0。 Any ideas?
有任何想法吗?
The authenticate call doesn't block. 身份验证调用不会阻止。 How am I suppose to return from the function?
我应该如何从函数返回?
All the examples I've seen call authenticate
in app.js. 我看过的所有示例都在app.js中调用了
authenticate
。 I don't want to configure authentication strategies in app.js. 我不想在app.js中配置身份验证策略。
var express = require('express');
var router = express.Router();
var passport = require('passport')
var facebookStrategy = require('passport-facebook').Strategy;
passport.use(new facebookStrategy({
clientID: "xxx",
clientSecret: "xxx",
callbackURL: "http://localhost:3000/auth/facebook/callback"
},
function(accessToken, refreshToken, profile, done) {
}
));
router.get('/', function(req, res) {
passport.authenticate('facebook');
});
module.exports = router;
You must call done()
in your facebookStrategy
callback function. 您必须在
facebookStrategy
回调函数中调用done()
。 Without that, things hang because the calling of done()
is how the system knows to proceed. 否则,事情就会死机,因为对
done()
的调用是系统知道如何进行的。 Even if you just have stub code in there for now, you need at least done()
to keep the control flow proceeding properly. 即使现在只在其中存根代码,也至少需要
done()
才能使控制流正确进行。
Secondly, passport.authenticate
returns a middleware function, so you don't directly call it, you pass it on to express: 其次,
passport.authenticate
返回一个中间件函数,因此您不直接调用它,而是将其传递来表示:
router.get('/', passport.authenticate('facebook')); //don't wrap here
The second part incorrect about your above router.get
callback is it never responds, which is also a way to make express hang. 关于您上面的
router.get
回调的第二部分不正确,因为它永远不会响应,这也是使快速挂起的一种方法。
Once those are fixed, you'll need one more route to handle the facebook callback: 解决这些问题后,您将需要另一条路径来处理facebook回调:
var options = {
successRedirect: '/home',
failureRedirect: '/bummer-dude'
};
router.get('/auth/facebook/callback', passport.authenticate('facebook', options));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.