{"id":15018076,"url":"https://github.com/casbin-rs/rocket-authz","last_synced_at":"2025-10-18T04:44:01.213Z","repository":{"id":51313097,"uuid":"265289392","full_name":"casbin-rs/rocket-authz","owner":"casbin-rs","description":"Casbin Rocket access control middleware ","archived":false,"fork":false,"pushed_at":"2023-08-08T05:44:46.000Z","size":23,"stargazers_count":4,"open_issues_count":0,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-30T19:07:39.975Z","etag":null,"topics":["abac","acl","auth","authentication","authorization","casbin","casbin-rs","middleware","permissions","rbac","rocket","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/casbin-rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2020-05-19T15:40:31.000Z","updated_at":"2024-04-03T07:46:01.000Z","dependencies_parsed_at":"2024-09-16T12:33:19.661Z","dependency_job_id":"1869607c-7a60-442c-94b3-cfc5b11a87d6","html_url":"https://github.com/casbin-rs/rocket-authz","commit_stats":{"total_commits":15,"total_committers":4,"mean_commits":3.75,"dds":"0.33333333333333337","last_synced_commit":"165175a8d6e87822d888fd722bb937204b84203c"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin-rs%2Frocket-authz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin-rs%2Frocket-authz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin-rs%2Frocket-authz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin-rs%2Frocket-authz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/casbin-rs","download_url":"https://codeload.github.com/casbin-rs/rocket-authz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237843750,"owners_count":19375196,"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":["abac","acl","auth","authentication","authorization","casbin","casbin-rs","middleware","permissions","rbac","rocket","rust"],"created_at":"2024-09-24T19:51:24.324Z","updated_at":"2025-10-18T04:43:56.162Z","avatar_url":"https://github.com/casbin-rs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rocket Casbin Middleware\n\n[![Crates.io](https://img.shields.io/crates/d/rocket-authz)](https://crates.io/crates/rocket-authz)\n[![Docs](https://docs.rs/rocket-authz/badge.svg)](https://docs.rs/rocket-authz)\n[![CI](https://github.com/casbin-rs/rocket-authz/workflows/CI/badge.svg)](https://github.com/casbin-rs/rocket-authz/actions)\n[![codecov](https://codecov.io/gh/casbin-rs/rocket-authz/branch/master/graph/badge.svg)](https://codecov.io/gh/casbin-rs/rocket-authz)\n\n[Casbin](https://github.com/casbin/casbin-rs) access control middleware for [Rocket](https://github.com/SergioBenitez/Rocket) framework\n\n## Install\nAdd it to `Cargo.toml`\n\n```rust\nrocket-authz = \"0.1.0\"\n```\n## Requirement\n**Casbin only takes charge of permission control**, so you need to implement an `Authentication Middleware` to identify user.\nYou need to put `rocket_authz::CasbinVals` which contains `subject` and `domain`(optional) into `reqeust.local_cache()` through an `Authentication Middleware`. You could see an example of using rocket-authz in [Example](#example).\n## Example\n```rust\n#![feature(proc_macro_hygiene, decl_macro)]\nuse casbin::{DefaultModel, FileAdapter};\nuse rocket::{\n    fairing::{Fairing, Info, Kind},\n    get,\n    request::Request,\n    routes, Data,\n};\nuse rocket_authz;\n\nstruct FakeAuthFairing;\n\nimpl Fairing for FakeAuthFairing {\n    fn info(\u0026self) -\u003e Info {\n        Info {\n            name: \"Fake Auth Fairing\",\n            kind: Kind::Request | Kind::Response,\n        }\n    }\n\n    fn on_request(\u0026self, request: \u0026mut Request, _data: \u0026Data) {\n        request.local_cache(|| rocket_authz::CasbinVals::new(Some(\"alice\".to_string()), None));\n    }\n}\n\n#[get(\"/data1\")]\nfn data1(_g: rocket_authz::CasbinGuard) -\u003e \u0026'static str {\n    \"data1\"\n}\n\n#[get(\"/data2\")]\nfn data2(_g: rocket_authz::CasbinGuard) -\u003e \u0026'static str {\n    \"data2\"\n}\n\nfn rocket() -\u003e rocket::Rocket {\n    let rt = tokio::runtime::Runtime::new().unwrap();\n    let m = match rt.block_on(DefaultModel::from_file(\n        \"examples/rbac_with_pattern_model.conf\",\n    )) {\n        Ok(m) =\u003e m,\n        Err(_) =\u003e panic!(\"\"),\n    };\n    let a = FileAdapter::new(\"examples/rbac_with_pattern_policy.csv\");\n\n    let casbin_fairing = match rt.block_on(rocket_authz::CasbinFairing::new(m, a)) {\n        Ok(f) =\u003e f,\n        Err(_) =\u003e panic!(\"\"),\n    };\n    let fake_auth_fairing = FakeAuthFairing;\n    rocket::ignite()\n        .attach(fake_auth_fairing)\n        .attach(casbin_fairing)\n        .mount(\"/\", routes![data1, data2])\n}\n```\n## License\nThis project is licensed under\n\n* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasbin-rs%2Frocket-authz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcasbin-rs%2Frocket-authz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasbin-rs%2Frocket-authz/lists"}