https://github.com/casbin/chi-authz
Chi Authorization Middleware based on Casbin
https://github.com/casbin/chi-authz
abac acl auth authorization casbin chi http middleware rbac
Last synced: 5 months ago
JSON representation
Chi Authorization Middleware based on Casbin
- Host: GitHub
- URL: https://github.com/casbin/chi-authz
- Owner: casbin
- License: mit
- Created: 2023-09-17T18:35:21.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-29T15:58:59.000Z (about 2 years ago)
- Last Synced: 2025-04-19T16:41:08.106Z (10 months ago)
- Topics: abac, acl, auth, authorization, casbin, chi, http, middleware, rbac
- Language: Go
- Homepage: https://github.com/casbin/casbin
- Size: 9.77 KB
- Stars: 3
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Chi-authz [](https://coveralls.io/github/casbin/chi-authz?branch=master) [](https://godoc.org/github.com/casbin/chi-authz)
======
Chi-authz is an authorization middleware for [Chi](https://github.com/go-chi/chi), it's based on [https://github.com/casbin/casbin](https://github.com/casbin/casbin).
## Installation
go get github.com/casbin/chi-authz
## Simple Example
```Go
package main
import (
"net/http"
"github.com/casbin/chi-authz"
"github.com/casbin/casbin"
"github.com/go-chi/chi"
)
func main() {
router := chi.NewRouter()
// load the casbin model and policy from files, database is also supported.
e := casbin.NewEnforcer("authz_model.conf", "authz_policy.csv")
router.Use(authz.Authorizer(e))
// define your handler, this is just an example to return HTTP 200 for any requests.
// the access that is denied by authz will return HTTP 403 error.
router.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
})
}
```
## Getting Help
- [casbin](https://github.com/casbin/casbin)
## License
This project is under MIT License. See the [LICENSE](LICENSE) file for the full license text.