Basic Auth Header Parser

0.0.2-1 · abandoned · verified Wed Apr 22

The `basic-auth-parser` package provides a minimalist utility for parsing the `Authorization` HTTP header specifically for Basic Authentication schemes. It extracts the authentication scheme (e.g., 'Basic'), username, and password from a base64-encoded header string. The current stable version is 0.0.2-1, which was last published over four years ago, indicating that the package is no longer actively maintained. Due to its age and lack of updates, it does not support modern JavaScript module systems like ESM out-of-the-box, relying solely on CommonJS. Key differentiators from more actively maintained alternatives like `basic-auth` (from `jshttp`) or `http-auth-utils` include its extremely small footprint and singular focus, but this comes at the cost of modern features, security updates, and broader ecosystem support.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse a Basic Auth `Authorization` header string using `basic-auth-parser`, showing both successful parsing and handling of invalid inputs.

const basicAuthParser = require('basic-auth-parser');

// Example: Parsing a valid Basic Auth header
const authHeader = 'Basic YWRtaW46cGFzc3dvcmQ='; // 'admin:password' base64 encoded
const parsedCredentials = basicAuthParser(authHeader);

console.log('Parsed Credentials:', parsedCredentials);
// Expected output: { scheme: 'Basic', username: 'admin', password: 'password' }

// Example: Handling an invalid or malformed header
const invalidAuthHeader = 'Bearer some-token';
const malformedAuthHeader = 'Basic invalid-base64-';

const parsedInvalid = basicAuthParser(invalidAuthHeader);
const parsedMalformed = basicAuthParser(malformedAuthHeader);

console.log('Parsed Invalid Header:', parsedInvalid);
// Expected output for non-Basic scheme: null
console.log('Parsed Malformed Header:', parsedMalformed);
// Expected output for malformed base64: null

view raw JSON →