Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
B

basic-auth

> 安全
Open source

Generic basic auth Authorization header field parser

714 stars0 likes1 views
WebsiteGitHub

About

Generic basic auth Authorization header field parser

basic-auth

NPM Version NPM Downloads Node.js Version Build Status Coverage Status

Generic basic auth Authorization header field parser for whatever.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install basic-auth

API

javascript
const { parse } = require('basic-auth');

parse(string)

Parse a basic auth authorization header string. This will return an object with name and pass properties, or undefined if the string is invalid.

format(credentials)

Format a credentials object with name and pass properties as a basic auth authorization header string.

Example

Pass a Basic auth header to the parse() method. If parsing fails undefined is returned, otherwise an object with .name and .pass.

javascript
const { parse } = require('basic-auth');
const user = parse(req.headers.authorization);
// => { name: 'something', pass: 'whatever' }

A header string from any other location can also be parsed for example a Proxy-Authorization header:

javascript
const { parse } = require('basic-auth');
const user = parse(req.getHeader('Proxy-Authorization'));

A credentials object can be formatted with auth.format as basic auth header string.

javascript
const { format } = require('basic-auth');
const credentials = { name: 'foo', pass: 'bar' };
const authHeader = format(credentials);
// => "Basic Zm9vOmJhcg=="

With vanilla node.js http server

…

License

MIT

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptbasic-authhttpjavascriptnodejs

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category安全
PricingOpen source

> Related tools

O
OWASP ZAP
开源 Web 应用安全扫描器
O
owasp-wstg-tracker
Simple web app to track OWASP WSTG security testing progress
H
homebridge-mi-gateway-security
XiaoMi Gateway Security plugin for HomeBridge.