I have an iOS app in which I use Facebook API for logging in, and I get an access token in response. Now I want to use this token to authenticate user on my backend server.
I'm using passport-facebook-token strategy for Passport.js.
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);
}
);
};
But when I call http://localhost:3000/auth/facebook?access_token=my_token_here I get following error:
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)
What steps in app configuration and/or authentication implementation am I'm missing?
First of all, check your ClientId and Client Secret, then check if you choose a correct app to test your connection to Facebook by Postman (or similar).
In my case, the problem was with generating token to another app
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With