passport-jwtr

3.1.0 • Public • Published

passport-jwtr

A Passport strategy for authenticating with a JSON Web Token.

This module lets you authenticate endpoints using a JSON web token. It is intended to be used to secure RESTful endpoints without sessions.

Installation

Npm

npm install passport-jwtr

Yarn

yarn add passport-jwtr

Support

This library is quite fresh, and maybe has bugs. Write me an email to natashkinsash@gmail.com and I will fix the bug in a few working days.

Quick start

 
var JwtrStrategy = require('passport-jwtr').Strategy,
    ExtractJwt = require('passport-jwtr').ExtractJwt;
var Redis = require('ioredis');
var opts = {}
opts.jwtFromRequest = ExtractJwt.fromAuthHeader();
opts.secretOrKey = 'secret';
opts.redis = new Redis();
passport.use(new JwtrStrategy(opts, function(jwt_payload, done) {
    User.findOne({id: jwt_payload.sub}, function(err, user) {
        if (err) {
            return done(err, false);
        }
        if (user) {
            done(null, user);
        } else {
            done(null, false, 'User not found');
        }
    });
}));
 

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 3.1.0
    5
    • latest

Version History

Package Sidebar

Install

npm i passport-jwtr

Weekly Downloads

1

Version

3.1.0

License

ISC

Last publish

Collaborators

  • natashkinsasha