passportjs-header

1.0.2 • Public • Published

passportjs-header

Build Coverage Quality Dependencies

Passport strategy for authenticating within a header.

This is effectively a stripped down version of passport-local.

This module lets you authenticate using a header username in your Node.js applications. By plugging into Passport, authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Install

$ npm install passportjs-header

Usage

Configure Strategy

The header authentication strategy authenticates users based on the user id sent in the HTTP headers by header worstations. The strategy requires a verify callback, which accepts these credentials and calls done providing a user.

passport.use(new HeaderStrategy(
  function(userid, done) {
    User.findOne({ userid: userid }, function (err, user) {
      if (err) { return done(err); }
      if (!user) { return done(null, false); }
      return done(null, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate(), specifying the 'header' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.post('/login', 
  passport.authenticate('Header', { failureRedirect: '/unauthenticated' }),
  function(req, res) {
    res.redirect('/');
  });

Tests

$ npm install
$ npm test

Package Sidebar

Install

npm i passportjs-header

Weekly Downloads

218

Version

1.0.2

License

GPL-2.0

Last publish

Collaborators

  • chrisns