Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vonage/acl-express

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vonage/acl-express

An access control middleware for Express

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

ACL-Express

A stateless access control middleware for Express servers

Installation

Install using npm:

$ npm install @vonage/acl-express

then in your project require the package:

const acl = require('@vonage/acl-express');

lastly, you must configure the module for it to work:

acl.config({...});

Configuration

You must supply a configuration object to the module for it to work.
You can use the following configurations:

PropertyRequiredTypeDescription
pathtruestringThis is the path for your rules file
roleObjectKeyfalsestringThe name of the user object on the express request object which holds the role field
Default Value: user
defaultRolefalsestringThis is the role that will be given to users which do not have a role set for them.

Example:

acl.config({
  path: 'path/to/rule/list',
  roleObjectKey: 'myUser',
  defaultRole: 'guest'
});

Rule File

You have to supply a rule file to the module which is built in the following way:

  1. The file needs to be a JSON file
  2. The JSON keys will be the roles you want in your system
  3. Every role will hold an array of routes you want to allow or deny access to

Basic Example:

{
  "guest": [
      {
        "route": "/public",
        "methods": [
          "GET"
        ],
        "action": "allow"
      },
      {
        "route": "/private",
        "methods": "*",
        "action": "deny"
      }
    ],
    "admin": [
      {
        "route": "*",
        "methods": "*",
        "action": "allow"
      }
    ]
}

As seen in the example above, every rule will hold the following fields:

FieldTypeDescription
routestringThe path for the rule to be applied on
methodsstring or arrayAn array of HTTP methods to apply this rule on, or * for all methods
actionstringThe action to apply for all requests this rule applies for. Values must be allow or deny

Advanced Features

URL Parameters

You can use the Express styled url parameters in your path, i.e.: /path/with/:param

Sub-routes

Every rule can have another field which is called subroutes. this is another array of rules which will allow you a more granular control over which routes to allow and deny access to according to your logic.
Example:

{
  "guest": [
    {
      "path": "/api",
      "method": "*",
      "action": "allow",
      "subroutes": [
        {
          "path": "/public", // Translates to /api/public
          "method": ["GET"],
          "action": "allow"
        },
        {
          "path": "/private", // Translates to /api/private
          "method": "*",
          "action": "deny"
        }
      ]
    }
  ]
}

License

See the LICENSE file for license rights and limitations (Apache License, Version 2.0)

Keywords

FAQs

Package last updated on 28 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc