Himmators
Himmators

Reputation: 15006

Can I use Passport.js and client-side facebook-authentification?

I'm building a REST-api that uses facebook for authentication, I think the best solution to be platform agnostic is to let the client deal with retrieving an auth-token from facebook and then use that to authenticate, to keep the API as clean as possible.

Is this at all possible?

Upvotes: 0

Views: 464

Answers (1)

dygufa
dygufa

Reputation: 186

You can use passport-facebook-token strategy instead of passport-facebook.

In this way you can get the token on the client-side and send it to the application using:

app.post('/auth/facebook/token',
    passport.authenticate('facebook-token'),
    function(req, res) {
        // do something with req.user
        res.send(req.user ? 200 : 401);
    }
);

With the code above you can pass the token using a query parameter like GET /auth/facebook/token?access_token=<TOKEN_HERE>, putting on the HTTP header access_token or in the request body.

Upvotes: 1

Related Questions