@zcong/egg-casbin
v0.3.0
Published
[![NPM version][npm-image]][npm-url] <!-- [![build status][travis-image]][travis-url] --> <!-- [![Test coverage][codecov-image]][codecov-url] --> <!-- [![David deps][david-image]][david-url] --> <!-- [![Known Vulnerabilities][snyk-image]][snyk-url] --> [!
Downloads
47
Readme
egg-casbin
Install
$ npm i @zcong/egg-casbin --save
Usage
Use a customized authorizer
// app/middleware/casbin.ts
import { authz } from '@zcong/egg-casbin'
export default authz
// {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,
}