rest-access
install
npm i -S rest-access
rest-access
can be used to restrict access to resources. it can be used as a standalone solution or as a express/connect middleware.
usage
const express = const app = const jwt = const access = app // authenticate with jwtapp app // restrict access according to definition above // endpointslet hello = 'world'appappapp
api
access(rules)
This function lets you define the access rules all at once:
access(methods, path, role[, block])
Use This method if you want to define a single access rules a specific place. examples:
The fourth argument is optional. If the fourth argument is "truthy" (boolean:true or string), it means that this role is blocked (instead of allowed) for the given methods and path.
Therefore in the following example, the Role read:glint
is blocked to POST
the given path.
members
access.isBlocked
this function can be used to check if the access to the required endpoint is blocked.
isBlocked(method, path, permission)
Given this definition:
The following result is expected:
access // -> returns `false`access // -> returns `false`access // -> returns `'access not permitted'`
access.midleware middleware function
example usage: looks for user permission under req.permission
app
access.restrict restrict single route
example usage: looks for user permission under req.permission
app
access.getRules use this function to return a copy of the existing rules.
example:
restAccess;
extends
access.middleware()
adds req.userCan
function to the express/connect Request Object.
Example call: req.userCan('admin:*')
test
run unittests
npm test
run integrationtests
npm test:integration
license
MIT
credits
extracted from: https://github.com/glintcms/glintcms-starter-glintcms/blob/master/local_modules/page-auth-access/access.js