simple-auth-basic is a lightweight Node.js module designed for parsing HTTP Basic Authorization headers. It extracts the username and password from the 'Authorization' header in an incoming request or a raw header string, returning an object with `name` and `pass` properties. If the header is invalid or missing, it returns `undefined`. The current stable version is 2.0.8. As a focused utility for a well-established standard, its release cadence is generally slow, primarily for maintenance and compatibility updates rather than new features. Its key differentiator is its simplicity and singular focus on parsing the header, leaving credential validation to the application logic, often paired with a timing-safe string comparison library like `tsscmp` for security.
npm install simple-auth-basicVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up a basic Node.js HTTP server that uses simple-auth-basic to parse Authorization headers and perform credential validation. It includes an example of using `tsscmp` for secure password comparison.
Always use a timing-safe string comparison library (e.g., `tsscmp`) when validating user-provided passwords against stored credentials to mitigate timing attacks.
For raw strings, use `auth.parse(headerString)`. For Node.js `IncomingMessage` objects, use `auth(req)`.
Ensure `auth` is imported correctly as a default export (`import auth from 'simple-auth-basic'`) and that `auth` is called with a request object (`auth(req)`). For string parsing, use `auth.parse(headerString)`.
Replace `const auth = require('simple-auth-basic')` with `import auth from 'simple-auth-basic'`.No dependency data recorded yet.