0.2.0 • Published 4 years ago

@zcong/koa-casbin v0.2.0

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

koa-casbin

NPM version NPM downloads CircleCI codecov

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