Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zcong1993/koa-casbin
casbin middleware for koa
https://github.com/zcong1993/koa-casbin
Last synced: about 23 hours ago
JSON representation
casbin middleware for koa
- Host: GitHub
- URL: https://github.com/zcong1993/koa-casbin
- Owner: zcong1993
- License: mit
- Created: 2019-08-29T11:10:11.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-10T20:46:00.000Z (about 3 years ago)
- Last Synced: 2023-02-28T14:37:11.229Z (over 1 year ago)
- Language: TypeScript
- Size: 286 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-casbin
[![NPM version](https://img.shields.io/npm/v/@zcong/koa-casbin.svg?style=flat)](https://npmjs.com/package/@zcong/koa-casbin) [![NPM downloads](https://img.shields.io/npm/dm/@zcong/koa-casbin.svg?style=flat)](https://npmjs.com/package/@zcong/koa-casbin) [![CircleCI](https://circleci.com/gh/zcong1993/koa-casbin/tree/master.svg?style=shield)](https://circleci.com/gh/zcong1993/koa-casbin/tree/master) [![codecov](https://codecov.io/gh/zcong1993/koa-casbin/branch/master/graph/badge.svg)](https://codecov.io/gh/zcong1993/koa-casbin)
> casbin middleware for koa
## Install
```bash
$ npm i @zcong/koa-casbin --save
```## Usage
### Use a customized authorizer
see [examples](./examples)
```ts
// app.ts
// ...
class MyAuthorizer extends Authorizer {
getUserName(ctx: Koa.Context) {
return ctx.user
}
}app.use(authMiddleware())
app.use(
authz({
newEnforcer: async () => {
const enforcer = await newEnforcer(
`${__dirname}/authz_model.conf`,
`${__dirname}/authz_policy.csv`
)
return enforcer
},
authorizer: MyAuthorizer
})
)
```## License
MIT © zcong1993