passport-http-bearer
passport-http-bearer copied to clipboard
MEAN.JS integration
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?
there is an example included in the repo
https://github.com/jaredhanson/passport-http-bearer/blob/master/examples/bearer/app.js
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
sounds unrelated to this module - it doesnt use a password or hash, just an api token
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.
There is a good sample, https://github.com/castlewhitehall/meanjs-with-token-auth Did anyone tried to patch existing project with that token-auth?