{"id":15097863,"url":"https://github.com/luckcoding/koa-authority","last_synced_at":"2026-01-07T04:38:57.614Z","repository":{"id":82856474,"uuid":"94765195","full_name":"luckcoding/koa-authority","owner":"luckcoding","description":"Koa middleware for the authority module. Support v1 and v2.","archived":false,"fork":false,"pushed_at":"2019-11-05T13:33:16.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-01T17:44:45.447Z","etag":null,"topics":["koa","koa-authority","koa-middleware"],"latest_commit_sha":null,"homepage":null,"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/luckcoding.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2017-06-19T10:28:57.000Z","updated_at":"2020-09-26T14:45:56.000Z","dependencies_parsed_at":"2024-01-31T23:38:21.117Z","dependency_job_id":null,"html_url":"https://github.com/luckcoding/koa-authority","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":0.2777777777777778,"last_synced_commit":"5d5b7cbbea9084747acb7dd39ca0a7e6f9fbfe6e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckcoding%2Fkoa-authority","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckcoding%2Fkoa-authority/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckcoding%2Fkoa-authority/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckcoding%2Fkoa-authority/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luckcoding","download_url":"https://codeload.github.com/luckcoding/koa-authority/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245854419,"owners_count":20683350,"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":["koa","koa-authority","koa-middleware"],"created_at":"2024-09-25T16:40:57.647Z","updated_at":"2026-01-07T04:38:52.577Z","avatar_url":"https://github.com/luckcoding.png","language":"JavaScript","readme":"# koa-authority\n\n[![npm version](https://img.shields.io/npm/v/koa-authority.svg)](https://www.npmjs.com/package/koa-authority)\n\nThis module provides a minimalistic verification.\n\n## Installation\n\n```\nnpm install koa-authority\n```\n\n## Use\n\n**real example：[==\u003e hotchcms](https://github.com/luckcoding/hotchcms)**\n\n### example 1\n\n\u003e use koa-router\n\n```\nvar koaAuthority = require('koa-authority')\nvar Router = require('koa-router')\n\n// 将要被校验的路由\nvar router = new Router()\nrouter.post('/check', function(){})\n\n// koaAuthority 提供更改权限的中间件 (middle)\nfunction authority(routes) {\n  reutrn koaAuthority({\n    routes: routes,\n    useKoaRouter: true,\n    middleware: function(ctx, { routes }) {\n      return new Promise(function(resolve, reject) {\n        if (err) return reject('500')\n        if (isAdmin) {\n          resolve(routes) // or resolve(true)\n        } else {\n          resolve([])\n        }\n      })\n    }\n  })\n}\n\n// 使用\napp.use(authority(router))\n```\n\n### example 2\n\n\u003e whitout koa-router\n\n```\nvar koaAuthority = require('koa-authority')\n\n// koaAuthority 提供更改权限的中间件 (middle)\nfunction authority(routes) {\n  reutrn koaAuthority({\n    routes: routes,\n    middleware: function(ctx, { routes }) {\n      return new Promise(function(resolve, reject) {\n        if (err) return reject('500')\n        if (isAdmin) {\n          resolve(routes) // or resolve(true)\n        } else {\n          resolve([])\n        }\n      })\n    }\n  })\n}\n\n// 使用\napp.use(authority([\n  {\n    path: 'api/user',\n    methods: ['POST'],\n  },\n  {\n    path: 'api/content/xxx',\n    methods: ['GET','HEAD', ...],\n  },\n  ...\n]))\n```\n\n## options\n\n* **routes**. `koa-router` Object or an Array like `[{path:'',methods:['GET'...]}...]`\n* **useKoaRouter**. Bollean, default false, *use koa-router ?*\n* **middleware**. Function, *return a Promise*.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluckcoding%2Fkoa-authority","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluckcoding%2Fkoa-authority","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluckcoding%2Fkoa-authority/lists"}