Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RBAC Planning #24

Open
gurpreetatwal opened this issue Mar 10, 2017 · 0 comments
Open

RBAC Planning #24

gurpreetatwal opened this issue Mar 10, 2017 · 0 comments
Assignees

Comments

@gurpreetatwal
Copy link
Member

gurpreetatwal commented Mar 10, 2017

roles have permissions, permissions map to validator functions

example:

function validate(req) {
   if (!req.valid) {
       return false;  // should this throw an error?
   }
  return true;
}

validator functions are defined in 3 places and take the following precedence (lowest to highest)

  1. default validator just does a string match of the permission name
'user.get': function validate(req) {
  return permissions[req.role].indcludes('user.get');
}
  1. custom validators can be defined in the permission file
'user.get9to5': function validate(req) {
  return permissions[req.role].indcludes('user.get') && timeofday > 9 && timeofday < 5;
}
  1. custom validators can be passed in by the user of the middleware
router.get('/:id', 
  permission.middleware(['user.get', 'user.self'], {
      'user.self': function(req) {
           return req.params.id === req.userId;
       }
  }),
  function(req, res, next) {
    // route
  }
)
@gurpreetatwal gurpreetatwal self-assigned this Mar 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant