casbin-couchbase-adapter
Couchbase adapter for Casbin https://github.com/casbin/node-casbin
Couchbase Adapter is the Couchbase adapter for Casbin. With this library, Casbin can load policy from Couchbase supported database or save policy to it.
Based on casbin-couchbase-adapter.
Installation
npm install casbin-couchbase-adapter
Simple Example
const Casbin = ;const CasbinCouchbaseAdapter = ; ~{ // Initialize a Couchbase adapter and use it in a Node-Casbin enforcer: // The adapter will use the CouchbaseDB database named "test". // If it doesn't exist, the adapter will create it automatically. try const casbinModel = ; casbinModel; const casbinAdapter = '<uri>' bucketURI:'<uri>' bucketName:'bucket' clusterPassword:'password' clusterUsername:'username' keyDelimiter:'<delimiter>'// e.g., '::' keyPrefix:'<prefix>'// e.g., 'Permission' ; const enforcer = await Casbin; // Load policies from the database. await enforcer; // Add a policy. await enforcer; // Check permissions. let isMatched = enforcer; console; await enforcer; // Save policies back to the database. await enforcer; process; catch exc console;};
More Elaborate Example
// Simple interface for a RBAC (Role-Based Access Control) data model // with domain/tenant and deny-override. {thisenforcer = enforcer;} /** * @returns Promise<void> */ async const self = this; return { const isAuthorized = self; if isAuthorized // Do not resolve a value so `.then( next )` can be used directly. ; else ; }; /** * @returns Promise<void> */ async const self = this; return { const isAuthorized = requestDefinitions ; if isAuthorized // Do not resolve a value so `.then( next )` can be used directly. ; else ; }; /** * @returns boolean */ const isAuthorized = thisenforcer; return isAuthorized ;
// Express or Restify global decorator to expose `authorizer`.{ return async req res next const enforcer = await ; if !enforcer instanceof Enforcer const errorString = "Invalid enforcer"; resstatus 500 ; ; else const authorizer = enforcer; resauthorizer = authorizer; ; ;};
// Express or Restify initialization.server;
// Express or Restify route decorator.expressOrRestifyServer;
Getting Help
License
This project is under GNU General Public License v3.0. See the LICENSE file for the full license text.