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: 21 days 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 (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-04T23:28:55.000Z (over 9 years ago)
- Last Synced: 2024-12-28T02:03:26.359Z (about 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
[](https://travis-ci.org/scull7/empower-permission)
[](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"
```