{"id":16306,"library":"basic-auth-parser","title":"Basic Auth Header Parser","description":"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.","status":"abandoned","version":"0.0.2-1","language":"javascript","source_language":"en","source_url":"https://github.com/mmalecki/basic-auth-parser","tags":["javascript"],"install":[{"cmd":"npm install basic-auth-parser","lang":"bash","label":"npm"},{"cmd":"yarn add basic-auth-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add basic-auth-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and does not officially support ESM `import` statements. Attempting to import it directly in an ESM context will likely result in a runtime error.","wrong":"import basicAuthParser from 'basic-auth-parser';","symbol":"basicAuthParser","correct":"const basicAuthParser = require('basic-auth-parser');"}],"quickstart":{"code":"const basicAuthParser = require('basic-auth-parser');\n\n// Example: Parsing a valid Basic Auth header\nconst authHeader = 'Basic YWRtaW46cGFzc3dvcmQ='; // 'admin:password' base64 encoded\nconst parsedCredentials = basicAuthParser(authHeader);\n\nconsole.log('Parsed Credentials:', parsedCredentials);\n// Expected output: { scheme: 'Basic', username: 'admin', password: 'password' }\n\n// Example: Handling an invalid or malformed header\nconst invalidAuthHeader = 'Bearer some-token';\nconst malformedAuthHeader = 'Basic invalid-base64-';\n\nconst parsedInvalid = basicAuthParser(invalidAuthHeader);\nconst parsedMalformed = basicAuthParser(malformedAuthHeader);\n\nconsole.log('Parsed Invalid Header:', parsedInvalid);\n// Expected output for non-Basic scheme: null\nconsole.log('Parsed Malformed Header:', parsedMalformed);\n// Expected output for malformed base64: null","lang":"javascript","description":"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."},"warnings":[{"fix":"Migrate to a maintained library like `basic-auth` (`npm install basic-auth`) or `http-auth-utils` (`npm install http-auth-utils`).","message":"The package has not been updated in over four years (last published 0.0.2-1). It is highly unlikely to receive security patches, bug fixes, or new features. Consider using actively maintained alternatives like `basic-auth` (from `jshttp`) or `http-auth-utils` for production environments.","severity":"breaking","affected_versions":"0.0.1 - 0.0.2-1"},{"fix":"For ESM projects, consider using a dynamic `import()` statement or a CommonJS-compatible module loader, or switch to an ESM-native alternative. Example for ESM: `const basicAuthParser = await import('basic-auth-parser').then(m => m.default || m);`","message":"This package is exclusively CommonJS (`require`) and lacks official ESM (`import`) support. Integrating it into modern TypeScript or ESM-native projects may require specific build configurations or a CommonJS wrapper.","severity":"gotcha","affected_versions":"0.0.1 - 0.0.2-1"},{"fix":"Always check for `null` return values and implement robust error handling or use a more comprehensive HTTP auth parsing library if supporting multiple schemes is required.","message":"The package only handles 'Basic' scheme parsing. It will return `null` for other `Authorization` schemes (e.g., 'Bearer', 'Digest') or malformed Basic Auth strings (e.g., invalid base64 encoding or missing colon).","severity":"gotcha","affected_versions":"0.0.1 - 0.0.2-1"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure the module is correctly imported using `const basicAuthParser = require('basic-auth-parser');` for CommonJS. If in ESM, consider `const basicAuthParser = require('basic-auth-parser');` or a dynamic import with proper default export handling: `const { default: basicAuthParser } = await import('basic-auth-parser');`","cause":"Attempting to use `basicAuthParser` as a function when it might be `undefined` or a malformed import due to incorrect module handling (e.g., in ESM context attempting to `import default as basicAuthParser`).","error":"TypeError: basicAuthParser is not a function"},{"fix":"Revert to CommonJS `require()` syntax: `const basicAuthParser = require('basic-auth-parser');`.","cause":"This error typically occurs when a CommonJS module is attempting to be imported using an ESM `import` statement in an environment that strictly enforces module types without transpilation or interoperability layers. This library does not export via `export`.","error":"SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm"}