@zcong/koa-casbin
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @zcong/koa-casbin

Weekly Downloads

2

Version

0.2.0

License

MIT

Unpacked Size

15.8 kB

Total Files

24

Last publish

Collaborators

  • zcong