Passport-HTTP-2 provides HTTP Basic and Digest authentication strategies for Passport.js, enabling stateless authentication for Node.js applications that support Connect-style middleware like Express. Currently at version 1.1.1, the library's release cadence appears to be on-demand, with the last notable update in 2019 and last commit in 2022, suggesting a maintenance rather than actively developed status. It serves as a fork of the original `jaredhanson/passport-http` module, which itself is less actively maintained. This fork aims to offer continued support for these fundamental HTTP authentication schemes, often used for protecting API endpoints where sessions are not desired. Developers leverage this module to integrate standard basic (username/password over plaintext, requires HTTPS) and digest (challenge-response, avoids cleartext password) authentication into their Passport-based applications.
npm install passport-http-2Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up both HTTP Basic and Digest authentication using Passport-HTTP-2 with an Express application, showing strategy configuration and route protection.
Review the GitHub repository's issues and PRs for active development and specific changes from the original `passport-http`.
Always deploy applications using HTTP Basic authentication behind a TLS/SSL (HTTPS) layer to encrypt communications.
Always include `{ session: false }` as an option in `passport.authenticate('strategy', { session: false })` for stateless HTTP authentication.Ensure the `done` callback is invoked with `done(null, user)` for success, `done(null, false)` for authentication failure, or `done(error)` for server errors during credential verification.
For `DigestStrategy`, ensure your `secret` callback correctly returns `done(null, user, user.password)` (or equivalent) for successful user lookup, supplying the secret for digest calculation.
For ESM, use `import { BasicStrategy } from 'passport-http-2';`. For CommonJS, ensure `const { BasicStrategy } = require('passport-http-2');` or `const BasicStrategy = require('passport-http-2').BasicStrategy;` if it's not a direct named export.Ensure `passport.use(new BasicStrategy(...))` (or `DigestStrategy`) is called to configure and register the strategy before any routes attempt to use `passport.authenticate('basic', ...)`.Debug your `verify`/`secret` callback logic to ensure it correctly identifies valid users and passwords. Also, check browser/client cache, especially in development, as browsers might cache HTTP auth credentials.
Ensure the `qop` option in `new DigestStrategy({ qop: 'auth' }, ...)` is correctly set to a valid string like 'auth' or 'auth-int' as per RFC 2617.