{"id":13564171,"url":"https://github.com/koajs/basic-auth","last_synced_at":"2025-04-04T16:14:27.355Z","repository":{"id":10154653,"uuid":"12233791","full_name":"koajs/basic-auth","owner":"koajs","description":"blanket basic auth middleware","archived":false,"fork":false,"pushed_at":"2019-01-07T09:19:09.000Z","size":20,"stargazers_count":138,"open_issues_count":0,"forks_count":16,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-29T15:32:21.153Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koajs.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-20T03:34:09.000Z","updated_at":"2024-10-11T12:11:42.000Z","dependencies_parsed_at":"2022-08-30T00:20:12.850Z","dependency_job_id":null,"html_url":"https://github.com/koajs/basic-auth","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fbasic-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fbasic-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fbasic-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fbasic-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/basic-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246893121,"owners_count":20850903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:01:27.522Z","updated_at":"2025-04-04T16:14:27.334Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","readme":"# koa-basic-auth [![Build Status](https://travis-ci.org/koajs/basic-auth.png)](https://travis-ci.org/koajs/basic-auth)\n\n  Add simple \"blanket\" basic auth with username / password. If you require\n  anything more specific just use the [basic-auth](https://github.com/visionmedia/node-basic-auth) module.\n\n  **v4.x+ Breaking Change:** This package no longer requires both a username and a password.  Either or is supported, see [#39](https://github.com/jshttp/basic-auth/issues/39) for more insight.\n\n## Installation\n\n```js\n$ npm install koa-basic-auth\n```\n\n## Example\n\n  Password protect downstream middleware:\n\n```js\nconst auth = require('koa-basic-auth');\nconst Koa = require('koa');\nconst app = new Koa();\n\n// custom 401 handling\napp.use(async (ctx, next) =\u003e {\n  try {\n    await next();\n  } catch (err) {\n    if (401 == err.status) {\n      ctx.status = 401;\n      ctx.set('WWW-Authenticate', 'Basic');\n      ctx.body = 'cant haz that';\n    } else {\n      throw err;\n    }\n  }\n});\n\n// require auth\napp.use(auth({ name: 'tj', pass: 'tobi' }));\n\n// secret response\napp.use(async (ctx) =\u003e {\n  ctx.body = 'secret';\n});\n\napp.listen(3000, function () {\n  console.log('listening on port 3000');\n});\n```\n\n  Example request:\n\n    $ curl -H \"Authorization: basic dGo6dG9iaQ==\" http://localhost:3000/ -i\n    HTTP/1.1 200 OK\n    X-Powered-By: koa\n    Content-Type: text/plain; charset=utf-8\n    Content-Length: 6\n    Date: Sat, 30 Nov 2013 19:35:17 GMT\n    Connection: keep-alive\n\n    secret\n\n Using the [mount](https://github.com/koajs/mount) middleware you may specify auth for a given prefix:\n\n```js\nconst mount = require('koa-mount');\nconst auth = require('koa-basic-auth');\n\napp.use(mount('/admin', auth({ name: 'tobi', pass: 'ferret' })));\n```\n\n## License\n\n  MIT\n","funding_links":[],"categories":["JavaScript","Middleware","仓库","Koa Middlewares"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fbasic-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fbasic-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fbasic-auth/lists"}