{"id":13799847,"url":"https://github.com/gerhut/koa-http-auth","last_synced_at":"2025-05-13T08:32:10.706Z","repository":{"id":143882755,"uuid":"53251626","full_name":"Gerhut/koa-http-auth","owner":"Gerhut","description":"HTTP authorization middleware of koa.","archived":true,"fork":false,"pushed_at":"2019-12-25T08:22:02.000Z","size":12,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T17:19:31.699Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gerhut.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-06T11:35:26.000Z","updated_at":"2023-01-28T16:17:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"e6d67521-1a17-4ecd-bbb9-0ff96693fa35","html_url":"https://github.com/Gerhut/koa-http-auth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gerhut%2Fkoa-http-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gerhut%2Fkoa-http-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gerhut%2Fkoa-http-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gerhut%2Fkoa-http-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gerhut","download_url":"https://codeload.github.com/Gerhut/koa-http-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253903881,"owners_count":21981764,"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-04T00:01:06.604Z","updated_at":"2025-05-13T08:32:10.421Z","avatar_url":"https://github.com/Gerhut.png","language":"JavaScript","readme":"# koa-http-auth\n\n[![Build Status](https://travis-ci.org/Gerhut/koa-http-auth.svg?branch=master)](https://travis-ci.org/Gerhut/koa-http-auth)\n[![codecov.io](https://codecov.io/github/Gerhut/koa-http-auth/coverage.svg?branch=master)](https://codecov.io/github/Gerhut/koa-http-auth?branch=master)\n[![Dependency Status](https://david-dm.org/gerhut/koa-http-auth.svg)](https://david-dm.org/gerhut/koa-http-auth)\n[![devDependency Status](https://david-dm.org/gerhut/koa-http-auth/dev-status.svg)](https://david-dm.org/gerhut/koa-http-auth#info=devDependencies)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)\n\nSimple [HTTP Authentication](https://tools.ietf.org/html/rfc2617) middleware\nof koa\n\n## Install\n\n    $ npm install koa-http-auth\n\n## Usage\n\n### Basic Authentication\n\n```javascript\nconst koa = require('koa')\nconst BasicAuth = require('koa-http-auth').Basic\n\nconst app = koa()\napp.use(BasicAuth('Simple Application'))\n\napp.use(function * (next) {\n  if (this.request.auth == null) { // No authorization provided\n    this.body = 'Please log in.'\n    return // Middleware will auto give 401 response\n  }\n\n  if (this.request.auth.user !== 'user' ||\n    this.request.auth.password('password')) {\n    this.body = 'Invalid user.'\n    delete this.request.auth // Delete request.auth ...\n    return // ... will make middleware give 401 response too.\n  }\n\n  if (this.url === '/logout') {\n    this.body = 'You are successfully logged out.'\n    delete this.request.auth // Delete request.auth unconditionally ...\n    return // ... will make user logged out.\n  }\n\n  this.body = 'Welcome back!'\n  yield next\n})\n```\n\n### Digest Authentication\n\n```javascript\nconst koa = require('koa')\nconst DigestAuth = require('koa-http-auth').Digest\n\nconst app = koa()\napp.use(DigestAuth('Simple Application'))\n\napp.use(function * (next) {\n  if (this.request.auth == null) { // No authorization provided\n    this.body = 'Please log in.'\n    return // Middleware will auto give 401 response\n  }\n\n  if (this.request.auth.user !== 'user' ||\n    this.request.auth.password('password')) {\n    this.body = 'Invalid user.'\n    delete this.request.auth // Delete request.auth ...\n    return // ... will make middleware give 401 response too.\n  }\n\n  if (this.url === '/logout') {\n    this.body = 'You are successfully logged out.'\n    delete this.request.auth // Delete request.auth unconditionally ...\n    return // ... will make user logged out.\n  }\n\n  this.body = 'Welcome back!'\n  yield next\n})\n```\n","funding_links":[],"categories":["仓库"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgerhut%2Fkoa-http-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgerhut%2Fkoa-http-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgerhut%2Fkoa-http-auth/lists"}