Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joonhocho/auth-perm
A simple level-based permission / authorization / access control
https://github.com/joonhocho/auth-perm
Last synced: about 1 month ago
JSON representation
A simple level-based permission / authorization / access control
- Host: GitHub
- URL: https://github.com/joonhocho/auth-perm
- Owner: joonhocho
- License: mit
- Created: 2016-05-02T19:50:13.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-05-14T07:52:11.000Z (over 8 years ago)
- Last Synced: 2024-05-06T03:02:21.621Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# auth-perm
A simple level-based permission authorization## NOT MAINTAINED
ATTENTION! USE RULE-BASED [joonhocho/graphql-rule](https://github.com/joonhocho/graphql-rule) INSTEAD!!!### Install
```
npm install --save auth-perm
```### Usage
```javascript
const perm = new Permissions({
admins: ['adminId1', 'adminId2'], // Admin user ids
defaultLevel: 0, // Default required user permission level
authenticatedLevel = 1, // Level assigned to authenticated users
adminLevel = 10, // Level assigned to admin user
});// Returns true if allowed.
perm.check(
{
p: 2, // User permission level required for this check
a: ['allowedUserId1'], // Whitelisted user ids
b: ['blockedUserId1'], // Blacklisted user ids
},
'sessionUserId', // Optional user id.
// If provided, authenticated user level will be assigned.
// Also, it will be tested against whitelist and blacklist ids.
// If not provided, user permission level will be 0.
3 // Optional user level.
// If provided, Math.max(custom, userLevel) will be used as the user's permission level.
);
```