npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

null-authorization

v0.0.21

Published

An authorization system non-intrusive inspired by express-authorization, Apache's Shiro project and XACML acl rules.

Downloads

12

Readme

express-authorization

An express/connect middleware module for enforcing an Apache Shiro inspired authorization system.

var express = require('express');
var authorization = require('express-authorization');
var app = express();

// Consider an authenticated user in the express session:
// req.session.user.permissions = ["restricted:*"]

app.get('/restricted',
  authorization.ensureRequest.isPermitted("restricted:view"),
  function(req, res) {
    ...
  });

Installation

$ npm install express-authorization

Features

  • Easy integration into your express or connect based code
  • Permission claim evaluation in the browser
  • Expressive permissions inspired by Apache Shiro
  • Customizable to fit your application needs
  • High test coverage

Philosophy

In express-authorization, a permission is a statement that defines access to an explicit activity, behavior or action. Subjects, usually website users, are assigned permissions to enable access to sets of activities, behaviors, or actions. To practically assign sets of permissions to subjects, express-authorization supports a wildcard enabled permission statement syntax that closely follows the syntax used by Apache Shiro. A collection of permissions assigned to a subject are compiled by the system into a regular expression referred to as a claim. Claims are then queried regarding whether or not they permit permissions that gate activities, behaviors, or actions.

Documentation

Permission Wildcard Expressions

express-authorization uses the Apache Shiro wildcard permission syntax directly.

  • Permission statements are composed of from parts delimited by colons (:).
  • Permission parts can contain lists delimited by commas (,).
  • Wildcard ? and * can be used to match one or more chataters within an expression part.
  • Examples: system:* | activity:create,update,delete

Permission Query

Permissions statements are strings that can be specified in parameter lists that may include arrays of composited permissions. A subject, usually a user, is expected to be represented by an object with a permissions property refering to either a single permission or an array of permissions.

In the permission query API, a permission source is placed under consideration and compiled into a claim that is queries to confirm permitted permissions.

authorization
  .considerSubject(user)
  .isPermitted("express:coding")
authorization
  .considerPermissions("source:edit", "express:*")
  .isPermitted("express:coding")

From subject or permission list -> claim -> isPermitted

authorization.considerSubject | authorization.considerPermissions -> claim

The considerSubject and considerPermissions methods are used to generate a claim object. A claim object is litterly a regular expression that matches any permissions that are permitted by the subject, user, or permission list under consideration. In addition, an isPermitted method is exposed on the claim for checking if one or more permissions are supported. See the consider test cases in the code for more examples.

Express Middleware

express-authorization uses a fluent API to generate express middleware for enforcing permissions.

authorization.ensureRequest.isPermitted("restricted:view")

To generate an express middleware, you write a call chain starting with a reference to authenticate.ensureRequest and ending in a call to isPermitted. The call to isPermitted returns a connect/express compliant middleware function.

By default, ensureRequest sources permissions from the session through references to session.user.permissions or session.permissions. To consider alternative permission sources, withSubject or withPermissions callbacks (asynchronous or immediate) are used.

authorization.ensureRequest
  .withPermissions(function (req, res, done) { done(["identity:*"]); })
  .isPermitted("identity:edit");

ensureRequest redirects to /login by default when a request is denied. redirectTo can be used to specify an alternate redirect url. onDenied can be used to prived a custom response function.

All of these options (withSubject, withPermissions, redirectTo, and onDenied) can be set either through chained API calls, or on the ensureRequest.options object. When set on the global authorization.ensureRequest.options, these establish new defaults.

A custom new authorization.EnsureRequest() object can be constructed for use if required.

Browser

The dist directory includes a version of the permission query API that can be used in your web pages. See dist/authorization.js.

License

MIT License

Copyright (c) 2013 Support.com, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.