Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passport-facebook-token returns InternalOAuthError: Failed to fetch user profile when verifying the token

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?

like image 470
CorrieSparrow Avatar asked Feb 23 '16 07:02

CorrieSparrow


1 Answers

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
enter image description here

like image 148
chavy Avatar answered Sep 22 '22 14:09

chavy