Page Contents

Enforcer libraries help developers in coding security policies as configurations and provides out-of-the-box matching rules, strategies and authorization patterns. These libraries also help with mundane tasks like mapping user profiles to scopes and roles, modifying configurations dynamically, etc. Please look at the loopback shopping example to see how CasBin library is injected as an enforcer into the authorization provider.

import * as casbin from 'casbin';

// Class level authorizer
export class CasbinAuthorizationProvider implements Provider<Authorizer> {
  constructor(@inject('casbin.enforcer') private enforcer: casbin.Enforcer) {}

   * @returns authorizeFn
  value(): Authorizer {
    return this.authorize.bind(this);

  async authorize(
    authorizationCtx: AuthorizationContext,
    metadata: AuthorizationMetadata,
  ) {

    * call enforcer and determine action
    return AuthorizationDecision.ABSTAIN;