auth-scope

Create authorization scope from collection of roles and/or permissions.

auth-scope

Create a scope from collection of roles and/or permissions.

Originally made for use with oauth2orize and the scope parameter, but could be adapted to different scenarios.

npm install auth-scope
component install alexmingoia/auth-scope
var Permission = require('auth-permission')
  , Role = require('auth-role')
  , Scope = require('auth-scope');
 
// Specify any number of roles or permissions 
var roles = new Scope([
  Role('api')
    .allow(Permission('read profile'))
    .allow(Permission('read post')),
  Permission('create account'),
  Permission('update billing')
]);
 
// Get scope permissions 
var permissions = scope.permissions();
 
JSON.stringify(permissions);
// => ['read profile', 'read post', 'create account'] 
 
// Create new scope by narrowing current scope. 
var restricted = scope.narrow(['api', 'create account']));

Create a new scope from collection of permissions and roles.

Find permissions or roles in scope.

Array|String|Scope query array of role or permission names, another scope, or a string of comma separated role or permission names.

Returns array of roles or permissions

Create a new scope by narrowing existing scope.

Array|String|Scope query array of role or permission names, another scope, or a string of comma separated role or permission names.

Returns new scope.

Array|String|Scope query array of role or permission names, another scope, or a string of comma separated role or permission names.

Returns boolean.

Check if scope has given role or permission.

Returns boolean.

Returns array of scope roles.

Returns scope permissions, including those in scope roles.

Returns array of scope role or permission names.

Tests are written with mocha and should.js using BDD-style assertions.

Run them using npm:

npm test