【发布时间】:2016-09-10 00:28:56
【问题描述】:
我正在使用 passport-facebook 登录我的用户,当 facebook 调用 myt 回调时,我进入了未定义的循环。我已经阅读了很多网站和问题,甚至在这里,但实际上,我找不到任何解决方案。
这是代码,我将把它全部放在这里,就像放在一个文件中一样:
var restify = require('restify');
var passport = require('passport-restify');
var FacebookStrategy = require('passport-facebook').Strategy;
var server = restify.createServer();
server.use(restify.bodyParser());
passport.use(new FacebookStrategy({
clientID: 'APP_ID',
clientSecret: 'APP_SECRET',
callbackURL: 'http://192.168.0.13:8080/login/facebook/callback'
}, function (token, refreshToken, profile, done) {
//this code never is executed, why?
return done(null, profile);
}));
server.use(passport.initialize());
server.get('/login/facebook', function(req, res, next) {
passport.authenticate('facebook', { display: null, scope: ['email']})(req, res, next);
});
server.get('/login/facebook/callback', (req, res, next) => {
//here is where the loop happends, i´m getting into this and never can go out from here
passport.authenticate('facebook', function(profile) {
//I could not execute this
if (!profile || !profile.id) {
return res.json(500, 'We had trouble signing you up with Facebook. Please try again or sign-up via email.');
} else {
res.json(200, profile);
}
})(req, res, next);
});
server.listen(config.port, function () {
console.log('%s listening at %s', server.name, server.url);
});
真的,我很沮丧,我现在,我现在,有成千上万的帖子在谈论这个......我尝试了所有这些,无论如何我都在这里......
谢谢。
【问题讨论】:
-
你能展示你的序列化/反序列化函数吗?
-
passport.serializeUser(function (profile, done) { done(null, profile); }); passport.deserializeUser(function (profile, done) { done(null, profile); });
-
在 serializeUser 中尝试用这个
done(null, profile.id)替换这个done(null, profile) -
我得到了相同的结果...同一行中的无限循环。非常感谢
-
你的服务器在 nginx 上运行?
标签: javascript node.js passport.js passport-facebook