MdialloC19 / RBAC-in-Node.js

This project implements Role-Based Access Control (RBAC) in Node.js, providing a flexible and scalable solution for managing access permissions in your application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Role-Based Access Control (RBAC) in Node.js

Introduction

This project implements Role-Based Access Control (RBAC) in Node.js, providing a flexible and scalable solution for managing access permissions in your application.

Features

  • Define roles and permissions
  • Assign roles to users
  • Check permissions for specific actions
  • Flexible and customizable configuration

Installation

To install the RBAC module, use npm:

npm install rbac-node

Usage

1. Configuration

First, configure your roles and permissions in the rbac-config.js file:

const rbacConfig = {
  roles: {
    admin: {
      permissions: ['create', 'read', 'update', 'delete']
    },
    user: {
      permissions: ['read']
    }
  }
};

2. Initialize RBAC

const RBAC = require('rbac-node');

const rbac = new RBAC(rbacConfig);

3. Assign Roles

rbac.addUserRoles(userId, ['admin']);

4. Check Permissions

if (rbac.can(userId, 'create')) {
  // Allow user to create
} else {
  // Deny access
}

Examples

Check out the examples directory for sample applications demonstrating RBAC usage in Node.js.

Contributing

Contributions are welcome! If you'd like to contribute to this project, please follow these guidelines:

  1. Fork the repository
  2. Create a new branch (git checkout -b feature)
  3. Make your changes
  4. Commit your changes (git commit -am 'Add feature')
  5. Push to the branch (git push origin feature)
  6. Create a new Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

This project implements Role-Based Access Control (RBAC) in Node.js, providing a flexible and scalable solution for managing access permissions in your application.


Languages

Language:JavaScript 100.0%