passportjs-header
v1.0.2
Published
header authentication strategy for Passport.
Downloads
224
Readme
passportjs-header
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