Git Product home page Git Product logo

mongoose-adapter's Introduction

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

mongoose-adapter's People

Contributors

zxilly avatar hsluoyz avatar emanuelet avatar ghaiklor avatar semantic-release-bot avatar nodece avatar sefriol avatar hariprasadiit avatar zhmushan avatar dependabot[bot] avatar stefanopastore avatar selflocking avatar fabian4 avatar fdionisi avatar kohtala avatar exigentcoder avatar shubhanshusingh avatar ulanmurzatayev avatar keitatata avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.