{"id":28396080,"url":"https://github.com/fastapi-practices/casbin_rbac","last_synced_at":"2026-03-04T03:02:53.097Z","repository":{"id":290136109,"uuid":"973460332","full_name":"fastapi-practices/casbin_rbac","owner":"fastapi-practices","description":"FastAPI Best Architecture casbin RBAC 插件","archived":false,"fork":false,"pushed_at":"2025-05-16T03:31:11.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-27T09:39:47.093Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","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/fastapi-practices.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,"zenodo":null}},"created_at":"2025-04-27T03:18:24.000Z","updated_at":"2025-06-24T14:27:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"3d249952-7156-4c97-8107-dd502efa19c1","html_url":"https://github.com/fastapi-practices/casbin_rbac","commit_stats":null,"previous_names":["wu-clan/fba_casbin"],"tags_count":0,"template":false,"template_full_name":"fastapi-practices/fba_plugin_template","purl":"pkg:github/fastapi-practices/casbin_rbac","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastapi-practices%2Fcasbin_rbac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastapi-practices%2Fcasbin_rbac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastapi-practices%2Fcasbin_rbac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastapi-practices%2Fcasbin_rbac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastapi-practices","download_url":"https://codeload.github.com/fastapi-practices/casbin_rbac/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastapi-practices%2Fcasbin_rbac/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30070479,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T01:03:42.280Z","status":"online","status_checked_at":"2026-03-04T02:00:07.464Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-05-31T21:36:45.069Z","updated_at":"2026-03-04T03:02:53.092Z","avatar_url":"https://github.com/fastapi-practices.png","language":"Python","readme":"# Casbin RBAC\n\n基于 Casbin 实现的 RBAC 访问控制\n\n我们在最初架构设计时，参考了 go-admin，gin-vue-admin... 等优秀的开源项目，同时引入了 Casbin，它在众多 python web\n开源项目中可能是极为罕见的，并且，它的学习成本非常高\n\n使用此插件前，请查看以下内容\n\n## Casbin 基础学习\n\n建议通过以下资源系统学习 Casbin\n\n- **官方文档**：[Casbin官网](https://casbin.org/docs/get-started)\n- **视频教程**：\n    - [半小时彻底弄懂Casbin基础模型](https://www.bilibili.com/video/BV1qz4y167XP)\n    - [Casbin代码使用与API调用](https://www.bilibili.com/video/BV13r4y1M7AC)\n\n## 全局配置\n\n在 `backend/core/conf.py` 中添加以下内容：\n\n```python\n##################################################\n# [ Plugin ] casbin_rbac\n##################################################\n# 基础配置（in plugin.toml）\nRBAC_CASBIN_EXCLUDE: set[tuple[str, str]]\n```\n\n## 规则配置\n\n内置模型：\n\n```text\n[request_definition]\nr = sub, obj, act\n\n[policy_definition]\np = sub, obj, act\n\n[role_definition]\ng = _, _\n\n[policy_effect]\ne = some(where (p.eft == allow))\n\n[matchers]\nm = g(r.sub, p.sub) \u0026\u0026 (keyMatch(r.obj, p.obj) || keyMatch3(r.obj, p.obj)) \u0026\u0026 (r.act == p.act || p.act == \"*\")\n```\n\n建议使用 [在线编辑器](https://casbin.org/zh/docs/online-editor) 验证规则\n\n## 策略管理\n\n| 类型            | 适用场景   | 格式                                  | 依赖关系   |\n|---------------|--------|-------------------------------------|--------|\n| **P策略**（角色基准） | 批量用户配置 | `角色 role + 访问路径 path + 访问方法 method` | 需配合G策略 |\n| **P策略**（用户基准） | 指定用户配置 | `用户 uuid + 访问路径 path + 访问方法 method` | 独立生效   |\n| **G策略**       | 角色分配   | `用户 uuid + 角色 role`                 | 需P策略配合 |\n\n## 接口集成\n\n在路由声明中添加鉴权依赖：\n\n```python\n@router.post(\n    '/hello',\n    summary='示例接口',\n    dependencies=[DependsRBAC]  # 关键鉴权标识\n)\nasync def hello():\n    ...\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastapi-practices%2Fcasbin_rbac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastapi-practices%2Fcasbin_rbac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastapi-practices%2Fcasbin_rbac/lists"}