An open API service indexing awesome lists of open source software.

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

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)
```