Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scull7/empower-permission
Given a permission set and a request return a permission token.
https://github.com/scull7/empower-permission
Last synced: about 1 month ago
JSON representation
Given a permission set and a request return a permission token.
- Host: GitHub
- URL: https://github.com/scull7/empower-permission
- Owner: scull7
- License: mit
- Created: 2015-10-30T16:36:27.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-04T23:28:55.000Z (about 9 years ago)
- Last Synced: 2024-09-14T12:53:59.267Z (2 months ago)
- Language: CoffeeScript
- Size: 160 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/scull7/empower-permission.svg?branch=master)](https://travis-ci.org/scull7/empower-permission)
[![Coverage Status](https://coveralls.io/repos/scull7/empower-permission/badge.svg?branch=master&service=github)](https://coveralls.io/github/scull7/empower-permission?branch=master)# empower-permission
Given a permission set and a request return a permission token.it will look in the `PermissionMap` for for a url that matches the given URL.
If found, then it will return the token string associated with that path.
Otherwise, it will return the `GeneralAccessToken` or _'*'_.Paths will be parsed using the `pathToRegexp` module.
g
## PermissionTokenExample Token Strings:
```javascript
'token:entity:create'
'token:entity:update'
'token:entity:sub-entity:read'
```## PermissionMap
This is a map of path strings to `PermissionTokens`
Example Map:
```json
{
"/url/token/entity/:entityId": "url:token:entity",
"/url/token/:tokenId": "url:token",
"/url/token": "url:token:list",
"/url/token/:tokenId/action": "url:token:action"
}
```## Usage
### Building the Map from JSON
```javascriptvar PermissionMap = require('empower-permission');
var map = PermissionMap.fromJson({
"/url/token/entity/:entityId": "url:token:entity",
"/url/token/:tokenId": "url:token",
"/url/token": "url:token:list",
"/url/token/:tokenId/action": "url:token:action"
}}var token = map.getToken("/url/token/entity/1234");
console.log(token); // will output "url:token:entity"
```
### Building the Map Programmatically
```javascriptvar PermissionMap = require('empower-permission');
var map = PermissionMap();map
.addToken("/url/token/entity/:entityId", "url:token:entity")
.addToken("/url/token/:tokenId", "url:token")
.addToken("/url/token", "url:token:list")
.addToken("/url/token/:tokenId/action", "url:token:action")var token = map.getToken("/url/token");
console.log(token); // will output "url:token:list"
```