{"id":13487588,"url":"https://github.com/eggjs/egg-userrole","last_synced_at":"2026-01-23T18:16:24.462Z","repository":{"id":57220814,"uuid":"63522637","full_name":"eggjs/egg-userrole","owner":"eggjs","description":"user role plugin for egg","archived":false,"fork":false,"pushed_at":"2019-10-24T02:47:47.000Z","size":23,"stargazers_count":77,"open_issues_count":0,"forks_count":5,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-10-07T18:44:11.253Z","etag":null,"topics":["egg","egg-plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"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/eggjs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-17T08:45:13.000Z","updated_at":"2022-11-03T05:17:39.000Z","dependencies_parsed_at":"2022-08-29T02:12:19.532Z","dependency_job_id":null,"html_url":"https://github.com/eggjs/egg-userrole","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/eggjs/egg-userrole","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-userrole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-userrole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-userrole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-userrole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eggjs","download_url":"https://codeload.github.com/eggjs/egg-userrole/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-userrole/sbom","scorecard":{"id":368783,"data":{"date":"2025-08-11","repo":{"name":"github.com/eggjs/egg-userrole","commit":"85a0acba9333bb96a854862eba3ebd44080107d1"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.1,"checks":[{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":4,"reason":"Found 8/20 approved changesets -- score normalized to 4","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 10 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T12:29:51.600Z","repository_id":57220814,"created_at":"2025-08-18T12:29:51.600Z","updated_at":"2025-08-18T12:29:51.600Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28697428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T17:25:48.045Z","status":"ssl_error","status_checked_at":"2026-01-23T17:25:47.153Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["egg","egg-plugin"],"created_at":"2024-07-31T18:01:00.911Z","updated_at":"2026-01-23T18:16:24.447Z","avatar_url":"https://github.com/eggjs.png","language":"JavaScript","readme":"# egg-userrole\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-userrole.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-userrole\n[travis-image]: https://img.shields.io/travis/eggjs/egg-userrole.svg?style=flat-square\n[travis-url]: https://travis-ci.org/eggjs/egg-userrole\n[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-userrole.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/eggjs/egg-userrole?branch=master\n[david-image]: https://img.shields.io/david/eggjs/egg-userrole.svg?style=flat-square\n[david-url]: https://david-dm.org/eggjs/egg-userrole\n[snyk-image]: https://snyk.io/test/npm/egg-userrole/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-userrole\n[download-image]: https://img.shields.io/npm/dm/egg-userrole.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-userrole\n\nProvide dynamic roles based authorisation. Use [koa-roles](https://github.com/koajs/koa-roles).\n\n## Install\n\n```bash\n$ npm i egg-userrole --save\n```\n\n## Usage\n```javascript\n// {app_root}/config/plugin.js\nexports.userrole = {\n  package: 'egg-userrole',\n};\n```\n\n\u003e Recommend to use along with custom `userservice` plugin (which provide `ctx.user`).\n\u003e\n\u003e see [`egg-userservice`](https://github.com/eggjs/egg-userservice) for more info.\n\n### Build-in\n\n`Roles` build-in `failureHandler`:\n\n```javascript\nfunction failureHandler(ctx, action) {\n  const message = 'Forbidden, required role: ' + action;\n  if (ctx.acceptJSON) {\n    ctx.body = {\n      message: message,\n      stat: 'deny',\n    };\n  } else {\n    ctx.status = 403;\n    ctx.body = message;\n  }\n};\n```\n\nBuild-in `user` role define:\n\n```javascript\napp.role.use('user', ctx =\u003e !!ctx.user);\n```\n\n### How to custom `failureHandler`\n\nDefine `app.role.failureHandler(action)` method in `config/role.js`\n\n- `app/extend/context.js`\n\n```javascript\n// {app_root}/config/role.js or {framework_root}/config/role.js\nmodule.exports = app =\u003e {\n  app.role.failureHandler = function(ctx, action) {\n    if (ctx.acceptJSON) {\n      ctx.body = { target: loginURL, stat: 'deny' };\n    } else {\n      ctx.realStatus = 200;\n      ctx.redirect(loginURL);\n    }\n  };\n}\n```\n\n### How to custom role\n\n```javascript\n// {app_root}/config/role.js or {framework_root}/config/role.js\nmodule.exports = function(app) {\n  app.role.use('admin', ctx =\u003e {\n    return ctx.user \u0026\u0026 ctx.user.isAdmin;\n  });\n\n  app.role.use('can write', async ctx =\u003e {\n    const post = await ctx.service.post.fetch(ctx.request.body.id);\n    return ctx.user.name === post.author;\n  });\n};\n```\n\n## Questions \u0026 Suggestions\n\nPlease open an issue [here](https://github.com/eggjs/egg/issues).\n\n## License\n\n[MIT](https://github.com/eggjs/egg-userrole/blob/master/LICENSE)\n","funding_links":[],"categories":["Plugins","仓库"],"sub_categories":["插件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-userrole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feggjs%2Fegg-userrole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-userrole/lists"}