我有一个 iOS 应用程序,我在其中使用 Facebook API 进行登录,我得到一个访问 token 作为响应。现在我想使用此 token 在我的后端服务器上对用户进行身份验证。
我正在为 Passport.js 使用 passport-facebook-token 策略。
var FacebookTokenStrategy = require('passport-facebook-token');
module.exports = function(app) {
app.use(passport.initialize());
app.use(passport.session());
passport.use(new FacebookTokenStrategy({
clientID: '32424222424024',
clientSecret: '3292e42148264c2817523232446187',
callbackURL: "http://localhost:3000/auth/facebook/callback"
},
function(accessToken, refreshToken, profile, done) {
User.findOne({ facebookId: profile.id }, function (err, user) {
console.log("facebook");
return done(err, user);
});
}
));
app.get('/auth/facebook',
passport.authenticate('facebook-token'),
function (req, res) {
res.send(req.user? 200 : 401);
}
);
};
但是当我调用 http://localhost:3000/auth/facebook?access_token=my_token_here我收到以下错误:
InternalOAuthError: Failed to fetch user profile at C:\app\www\app\node_modules\passport-facebook-token\lib\index.js:152:32 at passBackControl (C:\app\www\app\node_modules\oauth\lib\oauth2.js:123:9) at IncomingMessage. (C:\app\www\app\node_modules\oauth\lib\oauth2.js:143:7) at emitNone (events.js:72:20) at IncomingMessage.emit (events.js:166:7) at endReadableNT (_stream_readable.js:905:12) at nextTickCallbackWith2Args (node.js:474:9) at process._tickCallback (node.js:388:17)
我缺少应用配置和/或身份验证实现中的哪些步骤?
最佳答案
首先,检查您的ClientId和Client Secret,然后检查您是否选择了正确的应用程序test您通过 Postman(或类似工具)与 Facebook 的连接。
就我而言,问题在于为另一个应用程序生成 token
关于javascript - 护照-facebook-token 返回 InternalOAuthError : Failed to fetch user profile when verifying the token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35571072/