[英]Passport facebook token Oauth2 throwing Internal Server Errors when the token is good but works fine when token is wrong
What am I missing here?我在这里缺少什么? I've been through all the threads here and googled it for a while:
我已经浏览了这里的所有线程并用谷歌搜索了一段时间:
But when all is good and I send a request with that good token either from Postman or from my frontend I get Internal Server Error telling me User is not defined at that line.但是,当一切顺利并且我从 Postman 或我的前端发送带有该好的令牌的请求时,我收到内部服务器错误,告诉我用户未在该行定义。 What am I missing?
我错过了什么?
Route code:路线代码:
app.get(
'/user',
passport.authenticate('facebook-token', { session: false }),
function(req, res) {
res.send('SUCCESS');
}
);
All other code without imports:没有导入的所有其他代码:
app.use(cors());
app.use(express.json());
app.use(helmet());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(passport.initialize());
passport.use(
new FacebookTokenStrategy(
{
clientID: config.get('facebook.clientID'),
clientSecret: config.get('facebook.clientSecret')
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate({ facebookId: profile.id }, function(error, user) {
return done(error, user);
});
}
)
);
and I'm importing the npm package exactly as in the docs:我正在完全按照文档中的方式导入 npm 包:
const FacebookTokenStrategy = require('passport-facebook-token');
I'm all out of ideas on this one.我对这个完全没有想法。
app.use(cors());
app.use(express.json());
app.use(helmet());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(passport.initialize());
passport.use(
new FacebookTokenStrategy(
{
clientID: config.get('facebook.clientID'),
clientSecret: config.get('facebook.clientSecret')
},
function(accessToken, refreshToken, profile, done) {
return done(null, profile);
}
)
);
Try this尝试这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.