{"_id":"basic-auth@3.0.0","bugs":{"url":"https://github.com/jshttp/basic-auth/issues"},"dist":{"shasum":"18665a504dc0cdf22e9f83d51b14dc1d226d4e21","tarball":"http://registry-npm.ywwl.com/basic-auth/download/basic-auth-3.0.0.tgz","integrity":"sha512-B63UKsSJ2atgiSuCJvzAjpfAdFY6mYT3C0vZFlLV/81Rw2/VCs6Tp29UzkpKETB3qA2cHwuU1LjBnhUQ0WkPKw==","fileCount":9,"unpackedSize":14533,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/basic-auth@3.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHXvfOq345/IiuEmEgn9SXEEsznv9rAgc2ex3W93NwkQAiEAgGf9PlvlzS9cf8q3cgg71BnXpaYo0PlDlLrxsh5p3aM="}],"size":4960,"noattachment":false,"key":"/basic-auth/-/basic-auth-3.0.0.tgz"},"name":"basic-auth","type":"module","engines":{"node":">=22"},"exports":"./dist/index.js","gitHead":"0ea09f3a01df2e87dabf9975d4ad27f1e7dd4e25","license":"MIT","scripts":{"lint":"ts-scripts lint","size":"size-limit","test":"ts-scripts test && npm run size","bench":"vitest bench","build":"ts-scripts build","specs":"ts-scripts specs","format":"ts-scripts format","prepare":"ts-scripts install && npm run build"},"version":"3.0.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:887ffc00-b876-4f93-8807-04f14639ad68"},"approver":{"name":"blakeembrey","email":"hello@blakeembrey.com"}},"homepage":"https://github.com/jshttp/basic-auth#readme","keywords":["basic","auth","authorization","basicauth"],"repository":{"url":"git+https://github.com/jshttp/basic-auth.git","type":"git"},"size-limit":[{"path":"dist/index.js","limit":"1 kB"}],"ts-scripts":{"dist":["dist"],"project":["tsconfig.build.json"]},"_npmVersion":"11.18.0","description":"Basic auth parser","directories":{},"maintainers":[{"name":"ulisesgascon","email":"ulisesgascondev@gmail.com"},{"name":"blakeembrey","email":"hello@blakeembrey.com"},{"name":"tjholowaychuk","email":"tj@vision-media.ca"},{"name":"dougwilson","email":"doug@somethingdoug.com"},{"name":"jonathanong","email":"jonathanrichardong@gmail.com"},{"name":"jongleberry","email":"jonathanrichardong@gmail.com"}],"_nodeVersion":"26.6.0","devDependencies":{"vitest":"^4.1.6","size-limit":"^13.0.3","typescript":"^7.0.2","@types/node":"^26.1.0","@vitest/coverage-v8":"^4.1.6","@borderless/ts-scripts":"^0.15.0","@size-limit/preset-small-lib":"^13.0.3"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/basic-auth_3.0.0_1785773905445_0.8878251833412545"},"_hasShrinkwrap":false,"readme":"# basic-auth\n\n[![NPM Version][npm-version-image]][npm-url]\n[![NPM Downloads][npm-downloads-image]][npm-url]\n[![Node.js Version][node-image]][node-url]\n[![Build Status][ci-image]][ci-url]\n[![Coverage Status][coveralls-image]][coveralls-url]\n\nGeneric basic auth Authorization header field parser for whatever.\n\n## Installation\n\nThis is a [Node.js](https://nodejs.org/en/) module available through the\n[npm registry](https://www.npmjs.com/). Installation is done using the\n[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```\n$ npm install basic-auth\n```\n\n## API\n\n```js\nconst { parse } = require('basic-auth');\n```\n\n### parse(string)\n\nParse a basic auth authorization header string. This will return an object\nwith `name` and `pass` properties, or `undefined` if the string is invalid.\n\n### format(credentials)\n\nFormat a credentials object with `name` and `pass` properties as a basic\nauth authorization header string.\n\n## Example\n\nPass a Basic auth header to the `parse()` method. If parsing fails\n`undefined` is returned, otherwise an object with `.name` and `.pass`.\n\n```js\nconst { parse } = require('basic-auth');\nconst user = parse(req.headers.authorization);\n// => { name: 'something', pass: 'whatever' }\n```\n\nA header string from any other location can also be parsed for example a `Proxy-Authorization` header:\n\n```js\nconst { parse } = require('basic-auth');\nconst user = parse(req.getHeader('Proxy-Authorization'));\n```\n\nA credentials object can be formatted with `auth.format` as\nbasic auth header string.\n\n```js\nconst { format } = require('basic-auth');\nconst credentials = { name: 'foo', pass: 'bar' };\nconst authHeader = format(credentials);\n// => \"Basic Zm9vOmJhcg==\"\n```\n\n### With vanilla node.js http server\n\n```js\nconst http = require('node:http');\nconst { parse } = require('basic-auth');\nconst compare = require('tsscmp');\n\n// Create server\nconst server = http.createServer(function (req, res) {\n  const credentials = parse(req.headers.authorization);\n\n  // Check credentials\n  // The \"check\" function will typically be against your user store\n  if (!credentials || !check(credentials.name, credentials.pass)) {\n    res.statusCode = 401;\n    res.setHeader('WWW-Authenticate', 'Basic realm=\"example\"');\n    res.end('Access denied');\n  } else {\n    res.end('Access granted');\n  }\n});\n\n// Basic function to validate credentials for example\nfunction check(name, pass) {\n  let valid = true;\n\n  // Simple method to prevent short-circuit and use timing-safe compare\n  valid = compare(name, 'john') && valid;\n  valid = compare(pass, 'secret') && valid;\n\n  return valid;\n}\n\n// Listen\nserver.listen(3000);\n```\n\n# License\n\n[MIT](LICENSE)\n\n[ci-image]: https://badgen.net/github/checks/jshttp/basic-auth/master?label=ci\n[ci-url]: https://github.com/jshttp/basic-auth/actions/workflows/ci.yml\n[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/basic-auth/master\n[coveralls-url]: https://coveralls.io/r/jshttp/basic-auth?branch=master\n[node-image]: https://badgen.net/npm/node/basic-auth\n[node-url]: https://nodejs.org/en/download\n[npm-downloads-image]: https://badgen.net/npm/dm/basic-auth\n[npm-url]: https://npmjs.org/package/basic-auth\n[npm-version-image]: https://badgen.net/npm/v/basic-auth\n","publish_time":1785773905527,"_cnpm_publish_time":1785773905527,"dist-tags":{"latest":"3.1.0"}}