passport-http-bearer icon indicating copy to clipboard operation
passport-http-bearer copied to clipboard

MEAN.JS integration

Open vko-online opened this issue 9 years ago • 6 comments

Please can you provide example of integration.

strategies/bearer.js (new file)

 exports.signin = function(req, res, next){
    passport.authenticate('bearer', {session: false}, function(err, user, info){
        if(err || !user) {
            res.status(400).send(info);
        } else {
            // Remove sensitive data before login
            user.password = undefined;
            user.salt = undefined;
            req.login(user, function(err){
                if(err) {
                    res.status(400).send(err);
                } else {
                    res.json(user);
                }
            });
        }
    })(req, res, next);
};

Added token field to user model

Added middleware in router

app.route('/games').get(passport.authenticate('bearer', { session: false }), games.list)

Dunno what else i must do, any ideas?

vko-online avatar May 28 '15 08:05 vko-online

there is an example included in the repo

kumavis avatar May 30 '15 18:05 kumavis

https://github.com/jaredhanson/passport-http-bearer/blob/master/examples/bearer/app.js

kumavis avatar May 30 '15 18:05 kumavis

Yes, thanks, but somehow i cannot use it in MEAN.JS stack, when user registers, it's ok, then it can sign-in, but when he signs-out and sign-ins again, the password hashes do not match

vko-online avatar Jun 01 '15 03:06 vko-online

sounds unrelated to this module - it doesnt use a password or hash, just an api token

kumavis avatar Jun 01 '15 17:06 kumavis

Maybe the bearer token was confused with a password hash. You probably get a new bearer token each time you authenticate. It's similar to a session ID.

mk-pmb avatar Jun 01 '15 20:06 mk-pmb

There is a good sample, https://github.com/castlewhitehall/meanjs-with-token-auth Did anyone tried to patch existing project with that token-auth?

vko-online avatar Jun 02 '15 03:06 vko-online