node-casbin / express-authz

express-authz is an authorization middleware for Express.js based on Casbin
https://casbin.org
Apache License 2.0
62 stars 9 forks source link

allow authz to receive a constructor of Authorizer #12

Closed onichandame closed 4 years ago

onichandame commented 4 years ago

Problem

As stated in the README, the authorizer works by mapping the url to obj, the method to act and the user to sub. All these 3 fields come from the Express.Request object. I understand how it works when using the default BasicAuthorizer, but could not see how the request object is passed to the customized authorizer instance. Correct me if I am wrong.

Fix

This patch allows the user to pass the constructor of the Authorizer class to authz instead of an instance. By doing so the authz function can pass the request object to the constructor to create an instance so that the instance has access to the correct request object.

Notes

  1. README has been updated to reflect the change
  2. the husky commit hook is deleted because the prettier keeps failing in my dev environment and I couldn't commit with this hook. Please can a maintainer revert this?
coveralls commented 4 years ago

Pull Request Test Coverage Report for Build 522


Totals Coverage Status
Change from base Build 480: -2.7%
Covered Lines: 49
Relevant Lines: 53

💛 - Coveralls
hsluoyz commented 4 years ago

@nodece @zhmushan

nodece commented 4 years ago

LGTM