Socket
Socket
Sign inDemoInstall

passport-http

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

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.


Version published
Maintainers
1
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

Keywords

FAQs

Package last updated on 12 May 2013

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc