Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.
);
```