Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

casbin-mongoose-adapter

Package Overview
Dependencies
Maintainers
5
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

casbin-mongoose-adapter

Mongoose adapter for Casbin

  • 5.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.7K
increased by2.43%
Maintainers
5
Weekly downloads
 
Created
Source

Mongoose Adapter

NPM version NPM download codebeat badge Coverage Status Discord tests

Mongoose Adapter is the Mongoose adapter for Node-Casbin. With this library, Node-Casbin can load policy from Mongoose supported database or save policy to it. It is originally developed by @ghaiklor from @elasticio.

Based on Officially Supported Databases, The current supported database is MongoDB.

Mongoose Adapter has been rewritten to TypeScript since v3.x.

Getting Started

Install the package as dependency in your project:

npm install --save casbin-mongoose-adapter casbin

Note: casbin as peerDependencies!

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

const path = require('path');
const { newEnforcer } = require('casbin');
const { MongooseAdapter } = require('casbin-mongoose-adapter');

// const MongooseAdapter = require('casbin-mongoose-adapter');
// You should use this in v2.x

const model = path.resolve(__dirname, './your_model.conf');
const adapter = await MongooseAdapter.newAdapter('mongodb://your_mongodb_uri:27017');
const enforcer = await newEnforcer(model, adapter);

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 mongooose-specific options when instantiating the adapter:

const { MongooseAdapter } = require('casbin-mongoose-adapter');
const adapter = await MongooseAdapter.newAdapter('mongodb://your_mongodb_uri:27017', { mongoose_options: 'here' });

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

Filtered Adapter

You can create an adapter instance that will load only those rules you need to.

A simple case for it is when you have separate policy rules for separate domains (tenants). You do not need to load all the rules for all domains to make an authorization in specific domain.

For such cases, filtered adapter exists in casbin.

const { MongooseAdapter } = require('casbin-mongoose-adapter');
const adapter = await MongooseAdapter.newFilteredAdapter('mongodb://your_mongodb_uri:27017');

License

Apache-2.0

Keywords

FAQs

Package last updated on 06 Aug 2023

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