Lightweight connect based authorization middleware with express-style routing.
Lightweight connect based authorization middleware.
This library was extracted from an internal project where our authorization requirements where extremely simple. Large and more feature-rich libraries seemed like overkill. We also wanted something that is expressive and consistent with express.js' routes.
npm install authorizer --save
This example makes use of passport.js for authentication
var express = require'express'var passport = require'passport';var authorizer = require'authorizer';var routes =method : 'delete' path : '/api*' return requserisAdmin;method : 'post' path : '/api/resource' return requserisAdmin;method : 'post' path : '/api/auth*' check : authorizerassertAlwaysOpenmethod : 'get,post' path : '/api*' return reqisAuthenticated;method : '*' path : '*' check : authorizerassertAlwaysClosed;appconfigureapppassport = passport;appuseexpressbodyParser;appuseexpressmethodOverride;appuseexpresscookieParser;appuseexpresssession secret: 'Some secet' ;appusepassportinitialize;appusepassportsession;appuseauthorizerroutes;appuseapprouter;;