GithubHelp home page GithubHelp logo

node-casbin / koa-authz Goto Github PK

View Code? Open in Web Editor NEW
40.0 4.0 14.0 627 KB

koa-authz is an authorization middleware for Koa2 based on Casbin

Home Page: https://casbin.org/

License: Apache License 2.0

JavaScript 100.00%
casbin koa2 node-casbin authorization middleware koajs

koa-authz's Issues

Question: how can I use customized authorizer ?

maybe a stupid question here...
I got error when I tried to extends BasicAuthorizer as below:

const BasicAuthorizer = require("koa-authz").BasicAuthorizer;
.........
// use CustomizeAuthorizer
class CustomizeAuthorizer extends BasicAuthorizer {
........
}

Error like below:

class CustomizeAuthorizer extends BasicAuthorizer {
                                  ^
TypeError: Class extends value undefined is not a constructor or null
........

how can I import BasicAuthorizer into my app.js??

Package is problematic on npm

Package is problematic on npm.

  • On the master branch if (!await authzorizer.checkPermission()) { ctx.status = 403 return }
  • On the v2.0 if (!await authzorizer.checkPermission()) { ctx.status = 403 }
  • I install [email protected] and it like v2.0

No permission need return

koa-authz/authz.js

Lines 18 to 39 in 9ca6c22

// authz returns the authorizer, uses a Casbin enforcer as input
module.exports = function authz (options) {
return async (ctx, next) => {
try {
const {newEnforcer, authorizer} = options
const enforcer = await newEnforcer()
if (!(enforcer instanceof Enforcer)) {
throw new Error('Invalid enforcer')
}
const authzorizer = authorizer ? authorizer(ctx, enforcer) : new BasicAuthorizer(ctx, enforcer)
if (!(authzorizer instanceof BasicAuthorizer)) {
throw new Error('Please extends BasicAuthorizer class')
}
if (!await authzorizer.checkPermission()) {
ctx.status = 403
}
await next()
} catch (e) {
throw e
}
}
}

      if (!authzorizer.checkPermission()) {
        ctx.status = 403 // change to return ctx.status=403 ???
      }
      await next()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.