gpt4 book ai didi

javascript - Passport-facebook 策略回调函数永远不会被调用

转载 作者:太空宇宙 更新时间:2023-11-04 01:45:34 25 4
gpt4 key购买 nike

我是 Passport 新手,在这里我尝试使用 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
});

谢谢

最佳答案

正如文档所示:

更新回调函数为:

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

See more here.

关于javascript - Passport-facebook 策略回调函数永远不会被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51634672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com