`basic-auth-connect` is a Connect/Express middleware that implements HTTP Basic Authentication, providing a straightforward way to secure web routes. It allows for user verification using either static username/password pairs or through synchronous or asynchronous callback functions for more dynamic authentication logic. The package is currently on version 1.1.0, with its most recent updates focusing primarily on security patches, notably addressing CVE-2024-47178. While functional and easy to use for common Basic Auth scenarios, the package's own documentation suggests that for more complex or highly custom authentication requirements, developers should consider using the underlying `basic-auth` package directly to build their own middleware. Its release cadence appears to be driven by critical security fixes rather than feature development, indicating it is in a maintenance status. Its key differentiator is its simplicity for direct integration into the Connect middleware stack.
npm install basic-auth-connectVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic HTTP authentication for a Connect application using both static credentials and an asynchronous callback function with a timing-safe comparison.
Upgrade to `basic-auth-connect@1.1.0` or higher.
Implement `crypto.timingSafeEqual(Buffer.from(providedPass), Buffer.from(storedPass))` when comparing user-provided passwords with stored ones in your verification callback.
For complex or highly customized basic authentication logic, consider directly using `basic-auth` to build your middleware, providing more control and flexibility.
Ensure your project is configured for CommonJS, or use a tool like `createRequire` from the `module` package if you must import CommonJS modules within an ESM file (`import { createRequire } from 'module'; const require = createRequire(import.meta.url); const basicAuth = require('basic-auth-connect');`).Use the CommonJS `require()` syntax: `const basicAuth = require('basic-auth-connect');`. This package does not provide ES module exports.