All Projects → Slynova-Org → fence

Slynova-Org / fence

Licence: MIT License
🔰 Framework-agnostic package who provides powerful ACL abilities to JavaScript

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to fence

browser-acl
Simple acceess control (ACL) library for the browser inspired by Laravel's guards and policies.
Stars: ✭ 36 (-43.75%)
Mutual labels:  acl
laravel-casbin
This repository has moved to https://github.com/php-casbin/laravel-authz
Stars: ✭ 42 (-34.37%)
Mutual labels:  acl
paper-survey
Summary of machine learning papers
Stars: ✭ 26 (-59.37%)
Mutual labels:  acl
opentab
开源的轻应用后端(Open Tiny App Backend),轻量,高效,易部署。
Stars: ✭ 27 (-57.81%)
Mutual labels:  acl
position-rank
PositionRank: An Unsupervised Approach to Keyphrase Extraction from Scholarly Documents
Stars: ✭ 89 (+39.06%)
Mutual labels:  acl
casbin-ex
An authorization library that supports access control models like ACL, RBAC, ABAC in Elixir
Stars: ✭ 37 (-42.19%)
Mutual labels:  acl
sqlx-adapter
Asynchronous casbin adapter for mysql, postgres, sqlite based on sqlx-rs
Stars: ✭ 27 (-57.81%)
Mutual labels:  acl
nestjs-toolbox
The repository contains a suite of components and modules for Nest.js
Stars: ✭ 166 (+159.38%)
Mutual labels:  acl
domain-lookup-tree
A tree structure in Rust optimized for looking up domain names, with wildcard support
Stars: ✭ 17 (-73.44%)
Mutual labels:  acl
repl
Framework Agnostic REPL For Node.js. Used by AdonisJS
Stars: ✭ 76 (+18.75%)
Mutual labels:  framework-agnostic
ngx-security
Security directives for your Angular application to show/hide elements based on a user roles / permissions.
Stars: ✭ 18 (-71.87%)
Mutual labels:  acl
A-Persona-Based-Neural-Conversation-Model
No description or website provided.
Stars: ✭ 22 (-65.62%)
Mutual labels:  acl
speedle-plus
Speedle+ is an open source project for access management. It is based on Speedle open source project and maintained by previous Speedle maintainers.
Stars: ✭ 45 (-29.69%)
Mutual labels:  acl
linguistic-style-transfer-pytorch
Implementation of "Disentangled Representation Learning for Non-Parallel Text Style Transfer(ACL 2019)" in Pytorch
Stars: ✭ 55 (-14.06%)
Mutual labels:  acl
watson-personality-insights-php
Framework Agnostic Watson Personality Insights Client
Stars: ✭ 13 (-79.69%)
Mutual labels:  framework-agnostic
Acl
The Hoa\Acl library.
Stars: ✭ 27 (-57.81%)
Mutual labels:  acl
feathers-casl
feathers.js + casl: hooks & channels
Stars: ✭ 25 (-60.94%)
Mutual labels:  acl
vue-acl
Access Control List plugin for VueJS 2.0
Stars: ✭ 381 (+495.31%)
Mutual labels:  acl
access-control
Simple, flexible and reliable access control for NodeJS and Typescript. Supports both RBAC and ABAC.
Stars: ✭ 29 (-54.69%)
Mutual labels:  acl
graphyne
⚡ Lightning-fast JavaScript GraphQL Server ⚡
Stars: ✭ 18 (-71.87%)
Mutual labels:  framework-agnostic

fence

Build Status Coverage Status Version Downloads License

fence is a framework-agnostic package which provides powerful ACL abilities to JavaScript.
It lets you easily manage ACL with a fluent API easy to learn and to work with. 🚀



Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @slynova/fence
# or
$ yarn add @slynova/fence

When you require the package in your file, it will give you access to the Guard and Gate class.

const { Gate, Guard } = require('@slynova/fence')

Gate & Policy

A Gate is a closure that returns a boolean to determine if the user is allowed to perform a certain action. Instead of using a closure, you can also write a Policy. Those are classes that let you organise your authorisation around a particular model or resource.

Writing a Gate

To define a new Gate you will need to call the define method on the Gate facade.

Gate.define('name-of-the-gate', async (user, resource) => {
  // Payload
  // e.g. return user.id === resource.author_id
})

Writing a Policy

To define a new Policy you will need to call the policy method on the Gate facade.

Gate.policy(post, PostPolicy)

The first argument is the object you want to define the policy for. It can be a simple JSON or an ES2015 class.

The policy must be an ES2015 class.


Guard

The Guard is the guardian of your gates.

Most of the time, you'll want to use the authenticated user to test your gates. For this reason, node-fence let you use the method Guard.setDefaultUser().

// The user can be retrieve from the auth middleware you are using
const guard = Guard.setDefaultUser({ id: 1, username: 'romainlanz' })

Public API

guard.allows('gateName/Policy Method', resource) // It will use per default the defined user or return false if not defined
guard.denies('gateName/Policy Method', resource) // It will use per default the defined user or return true if not defined
guard.allows('gateName/Policy Method', resource, user)
guard.denies('gateName/Policy Method', resource, user)
guard.can(user).pass('gateName').for(resource)
guard.can(user).callPolicy('Policy Method', resource)

Contribution Guidelines

Any pull requests or discussions are welcome.
Note that every pull request providing a new feature or correcting a bug should be created with appropriate unit tests.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].