drudge / passport-facebook-token

Passport strategy for authenticating with Facebook access tokens using the OAuth 2.0 API.
MIT License
390 stars 79 forks source link

isAuthenticated() is always returning false #51

Open AkibShahjahan opened 8 years ago

AkibShahjahan commented 8 years ago

How would I use middleware to create a restful api authentication using token? Does anyone have a working example using passport-facebook-token? I just want to see an example where the passport-facebook-token is used to create a restful API with authentication and middlewares. req.isAuthenticated() is always giving me false.

This is the code i have

var passport = require('passport');
var FacebookTokenStrategy = require('passport-facebook-token').Strategy;
var mongoose = require('mongoose');

passport.use(new FacebookTokenStrategy({
        clientID: 'APP_ID_GOES_HERE',
        clientSecret: 'APP_SECRET_GOES_HERE',
    }, function(accessToken, refreshToken, profile, done) {
        console.log(profile);
                    // Do stuff with the profile. You're already getting authenticated data so there's no need to double check anything! For example
                    mongoose.model('User').findOrCreate({...}, function(err, user) {
                          done(err, user);
                    })
    })
);

   app.post('/login/facebook', passport.authenticate('facebook-token', {session: false}), function(req, res) {
    // Congratulations, you're authenticated!
    return res.json({status: 'OK'});
});

Thanks

torch2424 commented 7 years ago

Perhaps, this will help? I am going through the same problem, I dont have time to test it right now though.

https://github.com/drudge/passport-facebook-token/issues/58