Socket
Book a DemoInstallSign in
Socket

@webgap/authorization-utils

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webgap/authorization-utils

WebGAP authorization module for express routes using Role-based Access Control - RBAC.

Source
npmnpm
Version
0.1.3
Version published
Weekly downloads
7
133.33%
Maintainers
1
Weekly downloads
 
Created
Source

WebGAP Authorization Utils

Build Status Test Coverage Code Climate Dependency Status

NPM version NPM downloads

README

WebGAP Authorization module for Express.js

This is the Authorization utilities module for express routes using Role-based Access Control - RBAC.

Dependencies

Handles notifications using @webgap/notifier.

Requirements

Requires passport.
Requires express.

API

Installation

npm install @webgap/authorization-utils --save

Usage

It can be used as expressjs middleware:

var Authorizator = require('@webgap/authorization-utils');
var authorizator = new Autorizator();
var Role = Authorizator.Role;
...
// set authorization required to all routes starting with
app.use('/admin', authorizator.isAuthorized([Role.ADMIN]));
app.use('/user', authorizator.isAuthorized([Role.USER]));
app.use('/provider', authorizator.isAuthorized([Role.PROVIDER]));
...
// or apply to individual troutes
  app.router.get('/account/settings', authorizator.isAuthorized([Role.USER]), function (req, res) {
    res.render('backend/account/settings.html');
  });
...

Or in the browser with a templating engine as a filter:

<% if (authorizator.hasAccess(user, [authorizator.Role.ADMIN])) { %>
<span>Welcome Administrator!</span>
<% } %>
...

Check the tests for more info.

Options

var Authorizator = require('@webgap/authorization-utils');
var options = {
  notifier: { // default to @webgap/notifier module
    notify: function notify(options, callback) {
      console.log(options.notification); //render message as you want
      return callback();
    }
  },
  unauthorizedURL: '/unauthorized',
  loginURL: '/auth/login',
  unauthenticatedMessageKey: 'messages.warning.authentication-required',
  unauthorizedMessageKey: 'messages.error.authorization-required'
};
...
var authorizator = new Authorizator(options);
...

License

Apache License, Version 2.0

Keywords

webgap

FAQs

Package last updated on 19 Nov 2015

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