https://github.com/awatercolorpen/caskin
A multi-domain RBAC authorization library in Golang. Focus on management of authorization business.
https://github.com/awatercolorpen/caskin
authorization casbin domain rbac rbac-management tenant tenant-management
Last synced: 8 months ago
JSON representation
A multi-domain RBAC authorization library in Golang. Focus on management of authorization business.
- Host: GitHub
- URL: https://github.com/awatercolorpen/caskin
- Owner: AWaterColorPen
- License: mit
- Created: 2021-02-20T06:12:22.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-03-14T21:54:36.000Z (over 1 year ago)
- Last Synced: 2024-06-19T05:54:32.065Z (over 1 year ago)
- Topics: authorization, casbin, domain, rbac, rbac-management, tenant, tenant-management
- Language: Go
- Homepage:
- Size: 605 KB
- Stars: 15
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Caskin
[](https://github.com/AWaterColorPen/caskin/actions/workflows/go.yml)
Caskin is a multi-domain rbac library for Golang projects. It develops base on [caskin](https://github.com/casbin/casbin)
## Introduction
### Example
## Documentation
1. [Configuration](./docs/configuration.md) to configure caskin instance and dictionary.
2. [Design](./docs/design.md) for the details of design.
3. [API](./docs/api.md) for the details of caskin service method.
## Getting Started
### Define the dictionary configuration file
Create a new file for example named `caskin.toml` to define
[feature](./docs/configuration.md#feature),
[backend](./docs/configuration.md#backend),
[frontend](./docs/configuration.md#frontend),
[package](./docs/configuration.md#package),
[creator_object](./docs/configuration.md#creator-object),
[creator_role](./docs/configuration.md#creator-role),
[creator_policy](./docs/configuration.md#creator-policy).
```toml
feature = [
{name = "feature"},
]
backend = [
{path = "api/feature", method = "GET"},
{path = "api/feature", method = "POST"},
]
frontend = [
{name = "feature", type = "menu"},
]
package = [
{key = "feature", backend = [["api/feature", "GET"], ["api/feature", "POST"]], frontend = [["feature", "menu"]]},
]
creator_object = [
{name = "role_root", type = "role"},
]
creator_role = [
{name = "admin"},
{name = "member"},
]
creator_policy = [
{role = "admin", object = "role_root", action = ["read", "write", "manage"]},
{role = "admin", object = "github.com/awatercolorpen/caskin::feature", action = ["read"]},
{role = "member", object = "role_root", action = ["read"]},
]
```
### To make use of caskin in golang
Register [user-role-object-domain]() instance.
It should implement the interface of `caskin.User`, `caskin.Role`, `caskin.Object`, `caskin.Domain` generally.
Or use the example implementation in `github.com/awatercolorpen/caskin/example` for the prototype.
```golang
import "github.com/awatercolorpen/caskin"
import "github.com/awatercolorpen/caskin/example"
// register instance type
caskin.Register[*example.User, *example.Role, *example.Object, *example.Domain]()
```
Create a new [caskin service instance](./docs/configuration.md#service-configuration).
```golang
import "github.com/awatercolorpen/caskin"
// set db option
dbOption := &caskin.DBOption{
DSN: "./sqlite.db",
Type: "sqlite",
}
// set dictionary option
dictionaryOption := &caskin.DictionaryOption{
Dsn: "caskin.toml",
}
// build service option
option := &caskin.Options{
Dictionary: dictionaryOption,
DB: dbOption,
}
// create a new service instance
service, err := caskin.New(option)
```
Initialize first [domain](), and add first superadmin.
```golang
domain := &example.Domain{Name: "school-1"}
superadmin := &example.User{Email: "superadmin@qq.com"}
// create domain
err := service.CreateDomain(domain)
// reset domain by the creator setting from caskin.toml
err := service.ResetDomain(domain)
// reset domain by the feature setting from caskin.toml
err := service.ResetFeature(domain)
// add a user to caskin
err := service.CreateUser(superadmin)
// set a user as superadmin
err := service.AddSuperadmin(p.Superadmin)
```
### To manage the authorization business
Use the `caskin.Service`'s [API](./docs/api.md) to control on authorization management.
```golang
// authorization business: delete one role
err := service.DeleteRole(operatorUser, workingOnDomain, toDeleteRole))
```
Use the `caskin.CurrentService` interface.
```golang
currentService := service.SetCurrent(operatorUser, workingOnDomain)
```
## License
See the [License File](./LICENSE).