The `auth-header` library provides a robust solution for parsing and formatting HTTP `Authorization` and `WWW-Authenticate` headers. It supports various authentication schemes, including Basic, Digest, AWS, and Bearer/OAuth, adhering primarily to RFC7235 while also accommodating certain legacy formats by being less strict in its parsing. Currently at version 1.0.0, the library offers a stable API, though it appears to be in a maintenance state with no new feature development or active bug fixes since 2017. Its core differentiator lies in abstracting the complexities of these historically inconsistent HTTP headers, offering a standardized programmatic interface for their manipulation, which is a significant improvement over manual string parsing.
npm install auth-headerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `auth-header` within an Express application to parse an incoming `Authorization` header and format a `WWW-Authenticate` header for basic authentication. It checks for a 'Basic' scheme, decodes the credentials, and performs a simple password verification.
Ensure that your server responds with separate `WWW-Authenticate` headers for each challenge if this scenario is applicable.
Be aware that parsed output might come from non-standard or slightly malformed input. Implement additional validation on the parsed `scheme` and `token` if strict adherence to standards is critical for your application.
Evaluate the stability requirements for your project. If ongoing support or new standards compliance is crucial, consider alternatives or be prepared to maintain a fork.
For browser environments, use `atob()` for base64 decoding, or include a `Buffer` polyfill if targeting broader compatibility.
Always check if the result of `authorization.parse()` is a valid object before attempting to access its properties. For example: `const auth = authorization.parse(headerValue); if (!auth) { /* handle unparseable header */ }`Ensure you are using the correct import pattern: `import * as authorization from 'auth-header';` and then access `authorization.parse()` and `authorization.format()`.
If running in a browser, use `atob(auth.token)` for base64 decoding. If targeting universal environments, consider a polyfill or a library like `js-base64` for encoding/decoding operations.
No dependency data recorded yet.