Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zcong1993/egg-casbin
casbin plugin for egg
https://github.com/zcong1993/egg-casbin
Last synced: about 23 hours ago
JSON representation
casbin plugin for egg
- Host: GitHub
- URL: https://github.com/zcong1993/egg-casbin
- Owner: zcong1993
- License: mit
- Created: 2019-08-12T11:06:44.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-09-27T04:49:33.000Z (about 2 years ago)
- Last Synced: 2024-09-22T09:13:36.893Z (about 2 months ago)
- Language: JavaScript
- Size: 546 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# egg-casbin
[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]
[npm-image]:https://img.shields.io/npm/v/@zcong/egg-casbin.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@zcong/egg-casbin
[travis-image]: https://img.shields.io/travis/eggjs/egg-casbin.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-casbin
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-casbin.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/egg-casbin?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-casbin.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-casbin
[snyk-image]: https://snyk.io/test/npm/egg-casbin/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-casbin
[download-image]: https://img.shields.io/npm/dm/@zcong/egg-casbin.svg?style=flat-square
[download-url]: https://npmjs.org/package/@zcong/egg-casbin## Install
```bash
$ npm i @zcong/egg-casbin --save
```## Usage
### Use a customized authorizer
```ts
// app/middleware/casbin.ts
import { authz } from '@zcong/egg-casbin'export default authz
``````ts
// {app_root}/config/config.default.ts
// ...
class MyAuthorizer extends DefaultAuthorizer {
// override function
getUserName(ctx: Context): string {
return ctx.user.username
}
}config.casbin = {
enable: true,
newEnforcer: async() => {
const enforcer = await newEnforcer(`${__dirname}/authz_model.conf`, `${__dirname}/authz_policy.csv`)
return enforcer
},
authorizer: MyAuthorizer,
}
```## License
[MIT](LICENSE)