Registry / security / casbin-grpc-client-node

casbin-grpc-client-node

JSON →
library1.0.3jsnpmunverified

A gRPC client for communicating with a Casbin authorization server from Node.js applications. Version 1.0.3 is the current stable release, updated monthly. Provides a comprehensive API to manage policies, roles, and permissions remotely via gRPC, enabling centralized authorization across microservices. Unlike direct Casbin usage with local models, this client delegates enforcement to a remote Casbin server, simplifying policy management in distributed systems. Supports TypeScript definitions and requires a running Casbin gRPC server.

npm install casbin-grpc-client-node
INSTALL
IMPORT
SIG · CASBIN-GRPC-CLIENT
C
casbin-grpc-client-node
securityjavascriptv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CasbinClient
const { CasbinClient } = require('casbin-grpc-client')
const casbin-grpc-client = require('casbin-grpc-client')
Named import required; do not use default import.
CasbinClient
import { CasbinClient } from 'casbin-grpc-client'
import CasbinClient from 'casbin-grpc-client'
ESM uses named import; default import not supported.
CasbinClient
import type { CasbinClient } from 'casbin-grpc-client'
Type-only import available for TypeScript users.

Shows initialization of CasbinClient, starting with constructor options, then calling initializeAdapterAndEnforcer with DB connection and model, then adding a policy and performing an enforce check.

const { CasbinClient } = require('casbin-grpc-client'); const casbinClient = new CasbinClient({ grpcHost: process.env.ACCESS_CONTROL_GRPC_HOST || 'localhost', grpcPort: parseInt(process.env.ACCESS_CONTROL_GRPC_PORT || '50051'), }); async function main() { try { // Initialize adapter and enforcer with database connection string and model const connectString = 'mysql://user:password@tcp(localhost:3306)/casbin'; const modelText = ` [request_definition] r = sub, obj, act [policy_definition] p = sub, obj, act [policy_effect] e = some(where (p.eft == allow)) [matchers] m = r.sub == p.sub && r.obj == p.obj && r.act == p.act `; await casbinClient.initializeAdapterAndEnforcer(connectString, modelText); // Add a policy await casbinClient.addPolicy('alice', 'data1', 'read'); // Check enforcement const allowed = await casbinClient.enforce('alice', 'data1', 'read'); console.log('Access allowed:', allowed); // true or false // Get policies const policies = await casbinClient.getPolicies(); console.log('Policies:', policies); } catch (error) { console.error('Error:', error); } } main();
Debug
Known issues
breakingConstructor options changed from host/port to grpcHost/grpcPort in v1.0.0
fix
Use grpcHost and grpcPort options instead of host and port.
affects: <1.0.0
deprecatedenforce() method used to accept separate subject, object, action arguments; now passes a tuple
fix
Call enforce(sub, obj, act) with three string arguments as before (actually not changed). This warning is a placeholder; no known deprecations.
affects: <1.0.0
gotchagRPC server must be running before calling any methods; otherwise connection errors occur
fix
Ensure the Casbin gRPC server is started and reachable at the configured host and port.
affects: >=1.0.0
gotchaModel text must include proper Casbin model sections; incomplete model leads to enforce() failures
fix
Validate model string with Casbin editor before passing to initializeAdapterAndEnforcer.
affects: >=1.0.0
Errors
Common errors & fixes
Error: 14 UNAVAILABLE: No connection established
gRPC server is not running or unreachable
fix
Start the Casbin gRPC server and verify network connectivity. Check host and port.
TypeError: casbinClient.initializeAdapterAndEnforcer is not a function
CasbinClient imported incorrectly as default instead of named export
fix
Use const { CasbinClient } = require('casbin-grpc-client') or import { CasbinClient } from 'casbin-grpc-client'.
Error: Model text parsing error: unknown section
Invalid Casbin model syntax in modelText parameter
fix
Ensure the model string includes required sections like [request_definition], [policy_definition], [policy_effect], [matchers].
Error: 2 UNKNOWN: exception: table 'casbin_rule' doesn't exist
Database schema not initialized for Casbin adapter
fix
Run Casbin migration scripts to create necessary tables, e.g., using Casbin's autoMigrate feature.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredgRPC client for Node.js
@grpc/proto-loaderrequiredLoads .proto files for gRPC service definitions
Agent activity
20 hits · last 30 days
node
18
Resources
casbin-grpc-client-node — npm install casbin-grpc-client-node · libregistry