通用基本身份验证授权头部解析器
[![NPM 版本][npm-version-image]][npm-url] [![NPM 下载量][npm-downloads-image]][npm-url] [![Node.js 版本][node-image]][node-url] [![构建状态][ci-image]][ci-url] [![覆盖情况][coveralls-image]][coveralls-url] 用于任何情况的通用基本身份验证授权头字段解析器。
这是通过 Node.js 可用的模块
npm 注册表。安装过程使用
npm install 命令:
$ npm install basic-authconst { parse } = require('basic-auth');解析基本授权头部字符串。此方法将返回一个对象
具有 name 和 pass 属性,或者如果字符串无效则为 undefined。
使用 name 和 pass 属性格式化一个凭据对象,作为基本凭据
auth 授权头部字符串。
向 parse() 方法传递基本身份验证头。如果解析失败
如果返回 undefined,则返回一个具有 .name 和 .pass 的对象。
const { parse } = require('basic-auth');
const user = parse(req.headers.authorization);
// => { name: 'something', pass: 'whatever' }也可以解析来自其他位置的头部字符串,例如 Proxy-Authorization 头部:
const { parse } = require('basic-auth');
const user = parse(req.getHeader('Proxy-Authorization'));可以使用 auth.format 格式化凭证对象
基本身份验证报头字符串。
const { format } = require('basic-auth');
const credentials = { name: 'foo', pass: 'bar' };
const authHeader = format(credentials);
// => "Basic Zm9vOmJhcg=="…MIT [ci-image]: https://badgen.net/github/checks/jshttp/basic-auth/master?label=ci [ci-url]: https://github.com/jshttp/basic-auth/actions/workflows/ci.yml [coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/basic-auth/master [coveralls-url]: https://coveralls.io/r/jshttp/basic-auth?branch=master [node-image]: https://badgen.net/npm/node/basic-auth [node-url]: https://nodejs.org/en
暂无开放 Issues,或尚未同步最近议题。