🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

passport-http

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-http

HTTP Basic and Digest authentication strategies for Passport.

0.3.0
latest
Version published
Weekly downloads
193K
13.95%
Maintainers
1
Weekly downloads
 
Created

What is passport-http?

The passport-http npm package provides HTTP Basic and Digest authentication strategies for Passport, a popular authentication middleware for Node.js. It allows you to authenticate requests using the HTTP Basic and Digest authentication schemes, which are often used for simple username and password authentication.

What are passport-http's main functionalities?

HTTP Basic Authentication

This feature allows you to authenticate users using HTTP Basic Authentication. The code sample demonstrates how to set up a BasicStrategy with Passport and protect an Express route.

const passport = require('passport');
const BasicStrategy = require('passport-http').BasicStrategy;

passport.use(new BasicStrategy(
  function(username, password, done) {
    User.findOne({ username: username }, function (err, user) {
      if (err) { return done(err); }
      if (!user) { return done(null, false); }
      if (!user.verifyPassword(password)) { return done(null, false); }
      return done(null, user);
    });
  }
));

// Express route
app.get('/protected', 
  passport.authenticate('basic', { session: false }),
  function(req, res) {
    res.json({ message: 'Access granted' });
  }
);

HTTP Digest Authentication

This feature allows you to authenticate users using HTTP Digest Authentication. The code sample demonstrates how to set up a DigestStrategy with Passport and protect an Express route.

const passport = require('passport');
const DigestStrategy = require('passport-http').DigestStrategy;

passport.use(new DigestStrategy({ qop: 'auth' },
  function(username, done) {
    User.findOne({ username: username }, function (err, user) {
      if (err) { return done(err); }
      if (!user) { return done(null, false); }
      return done(null, user, user.password);
    });
  },
  function(params, done) {
    // Validate nonces as necessary
    done(null, true);
  }
));

// Express route
app.get('/protected', 
  passport.authenticate('digest', { session: false }),
  function(req, res) {
    res.json({ message: 'Access granted' });
  }
);

Other packages similar to passport-http

FAQs

Package last updated on 15 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts