我是通行证的新手,在这里我正尝试使用passport-facebook策略进行身份验证。 但是,永远不会调用在“ FacebookStrategy”内部定义的回调函数,这意味着永远不会在控制台上打印“被调用的Facebook回调”。 尽管成功案例每次都在运行。
这是我的代码
// Initialising passport
router.use(passport.initialize());
//router.use(passport.session()); /*I don't want to use passport session*/
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function (obj, done) {
done(null, obj);
});
/**
* Configuring FacebookStrategy
*/
passport.use(new FacebookStrategy({
clientID: 'facebook_client_id', // Facebook Client ID
clientSecret: 'facebook_client_secret', // Facebook Client Secret
callbackURL: 'https://sheltered-earth-74671.herokuapp.com/signin/facebook/callback' // Callback URL after user allow information access
}, function (accessToken, refreshToken, profile, done) { // Callback Function
console.log('Facebook callback called'); /*THIS ISN'T PRINTING*/
done(null, profile);
}));
router.get('/facebook', passport.authenticate('facebook', {
scope: ['email']
}));
router.get('/facebook/callback', (req, res, next) => {
res.send(req.query.code); // This is working
});
谢谢
答案 0 :(得分:0)
文档提示:
将回调函数更新为:
router.get('/facebook/callback',
passport.authenticate('facebook',
{ successRedirect: '/', failureRedirect: '/login' }
));