0.2.0 • Published 4 years ago
@zcong/koa-casbin v0.2.0
koa-casbin
casbin middleware for koa
Install
$ npm i @zcong/koa-casbin --save
Usage
Use a customized authorizer
see examples
// 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