New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

casbin-mongodb-adapter

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

casbin-mongodb-adapter

Pure MongoDB adapter for Casbin

  • 1.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
decreased by-19.69%
Maintainers
1
Weekly downloads
 
Created
Source

casbin-mongodb-adapter

MongoDB policy storage, implemented as an adapter for node-casbin.

NPM Version NPM Version Build Code Quality Build Build Build

Getting Started

Install the package as dependency in your project:

npm install --save casbin-mongodb-adapter

Require it in a place, where you are instantiating an enforcer (read more about enforcer here):

import {newEnforcer, Enforcer} from 'casbin';
import { MongoAdapter } from 'casbin-mongodb-adapter';
import * as path from 'path';

async function myFunction() {
  const model = path.resolve(__dirname, 'casbin-files/rbac_model.conf');

  const adapter = await MongoAdapter.newAdapter({
    uri: 'mongodb://localhost:27017',
    collection: 'casbin',
    database: 'node-casbin-official'
  });

  const e = await newEnforcer(model, adapter);

  await e.loadPolicy();

  // Check the permission.
  e.enforce('alice', 'data1', 'read');

  // Modify the policy.
  // await e.addPolicy(...);
  // await e.removePolicy(...);

  // Save the policy back to DB.
  await e.savePolicy();
}

That is all what required for integrating the adapter into casbin. Casbin itself calls adapter methods to persist updates you made through it.

Configuration

You can pass mongodb-specific options when instantiating the adapter:

import { MongoAdapter } from 'casbin-mongodb-adapter';

const adapter = await MongoAdapter.newAdapter({
  uri: 'mongodb://localhost:27017',
  collection: 'casbin',
  database: 'node-casbin-official',
  option: {
    ...mongoOptions
  }
});

Additional information regard to options you can pass in you can find in mongodb documentation

License

Apache-2.0

FAQs

Package last updated on 11 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc