项目作者: pmctire

项目描述 :
A dead simple expressjs middleware for activity based authorization.
高级语言: JavaScript
项目地址: git://github.com/pmctire/moze.git
创建时间: 2016-11-18T19:52:59Z
项目社区:https://github.com/pmctire/moze

开源协议:Apache License 2.0

下载


Moze

Build Status
npm version
Known Vulnerabilities

A dead simple expressjs middleware for activity based authorization. It lets you
easily define what routes your users are allowed to access.

Moze is an authorization middleware. This is not the same thing as
authentication. If you’re looking for an authentication middleware, we recommend
passport.

Installation

  1. npm install --save moze

Usage

  1. var express = require('express');
  2. var moze = require('moze');
  3. var app = express();
  4. // ...
  5. // Initialize moze. We specify how to get the activities the
  6. // current user is allowed to perform.
  7. app.use(moze.init(function(req) {
  8. // For this example, we assume that our authentication middleware defines the
  9. // req.user object which holds an array of the activities that the user is
  10. // allowed perform.
  11. return req.user.allowedActivities;
  12. }))
  13. // ...
  14. // routes
  15. app.get('/posts',
  16. authenticate, // some authentication middleware
  17. moze.may('browse blog'),
  18. getBlogAllPosts // handler
  19. );
  20. app.post('/posts',
  21. authenticate, // some authentication middleware
  22. moze.may('write blog posts'),
  23. createBlogPost // handler
  24. );
  25. app.get('/posts/:id',
  26. authenticate, // some authentication middleware
  27. moze.may('browse blog', 'write blog posts'),
  28. getBlogPost // handler
  29. );
  30. app.put('/posts/:id',
  31. authenticate, // some authentication middleware
  32. moze.may('write blog posts'),
  33. editBlogPost // handler
  34. );
  35. app.get('/posts/:id/comments',
  36. authenticate, // some authentication middleware
  37. moze.may('browse blog'),
  38. getBlogPostComments // handler
  39. );
  40. app.post('/posts/:id/comments',
  41. authenticate, // some authentication middleware
  42. moze.may('write comments'),
  43. createComment // handler
  44. );

Development

Setup

Install dependencies

  1. npm install

Testing

You can run the tests once with

  1. npm test

You can have the tests run every time you change something with

  1. npm test -- --watch