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')
]);
// Create scope from available roles and/or permissions
var scope = new Scope(roles.find(['api', 'create account']));
// Get scope permissions
var permissions = scope.permissions();
JSON.stringify(permissions);
// => ['read profile', 'read post', 'create account']
Create a new scope from collection of permissions and roles.
Find permissions or roles in the scope by name.
Returns array of roles.
Returns array of permissions.