passport-jwt-cookie-extractor
v1.0.0
Published
Passport JWT helper to excract tokens from cookies
Downloads
3
Maintainers
Readme
Install
$ npm install passport-jwt-cookie-extractor
Usage
Configure Strategy
passport-jwt-cookie-extractor
is a lightweight addition to the existing passport-jwt
package that you are missing to be able to confidently work with retrieving a token from a cookie in a request.
You should pass it as jwtFromRequest param in JwtStrategy options.
var JwtStrategy = require('passport-jwt').Strategy,
Extractor = require('passport-jwt-cookie-extractor');
var opts = {}
opts.jwtFromRequest = Extractor.fromCookie('accessToken');
opts.secretOrKey = 'secret';
opts.issuer = 'accounts.examplesoft.com';
opts.audience = 'yoursite.net';
passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
User.findOne({id: jwt_payload.sub}, function(err, user) {
if (err) {
return done(err, false);
}
if (user) {
return done(null, user);
} else {
return done(null, false);
// or you could create a new account
}
});
}));
Thanks
Thanks to Jared Hanson for his great Passport