https://github.com/tesladodger/authngn
Simple authorization engine for Go
https://github.com/tesladodger/authngn
api-rest authorization go golang
Last synced: 12 months ago
JSON representation
Simple authorization engine for Go
- Host: GitHub
- URL: https://github.com/tesladodger/authngn
- Owner: tesladodger
- License: mit
- Created: 2023-03-04T20:29:46.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-07T16:03:52.000Z (over 3 years ago)
- Last Synced: 2025-03-03T00:16:54.697Z (over 1 year ago)
- Topics: api-rest, authorization, go, golang
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Authngn
Stupidly simple authorization engine.
```
go get -u github.com/tesladodger/authngn
```
## Usage
Register the rules:
```
ngn := authngn.New()
ngn.Register(User{}, "read,write,delete", Resource{}, func(ent, res any) bool {
user := ent.(User)
res := res.(Resource)
return user.id == resource.owner
})
```
Assert authorization:
```
ok := ngn.Authorize(user, "read", resource)
```