Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

chrisns/passportjs-header

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

passportjs-header

Greenkeeper badge

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

About

No description, website, or topics provided.

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

No packages published