How to use the @loopback/context.BindingKey.create function in @loopback/context

To help you get started, we’ve selected a few @loopback/context examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strongloop / loopback4-example-shopping / packages / shopping / src / keys.ts View on Github external
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {BindingKey} from '@loopback/context';
import {PasswordHasher} from './services/hash.password.bcryptjs';
import {TokenService, UserService} from '@loopback/authentication';
import {User} from './models';
import {Credentials} from './repositories';

export namespace TokenServiceConstants {
  export const TOKEN_SECRET_VALUE = 'myjwts3cr3t';
  export const TOKEN_EXPIRES_IN_VALUE = '600';
}

export namespace TokenServiceBindings {
  export const TOKEN_SECRET = BindingKey.create(
    'authentication.jwt.secret',
  );
  export const TOKEN_EXPIRES_IN = BindingKey.create(
    'authentication.jwt.expires.in.seconds',
  );
  export const TOKEN_SERVICE = BindingKey.create(
    'services.authentication.jwt.tokenservice',
  );
}

export namespace PasswordHasherBindings {
  export const PASSWORD_HASHER = BindingKey.create(
    'services.hasher',
  );
  export const ROUNDS = BindingKey.create('services.hasher.round');
}
github strongloop / loopback-next / packages / core / src / keys.ts View on Github external
export const SERVERS = 'servers';

  // component
  /**
   * Binding key for components
   */
  export const COMPONENTS = 'components';

  // controller
  export const CONTROLLERS = 'controllers';

  /**
   * Binding key for the controller class resolved in the current request
   * context
   */
  export const CONTROLLER_CLASS = BindingKey.create(
    'controller.current.ctor',
  );

  /**
   * Binding key for the controller method resolved in the current request
   * context
   */
  export const CONTROLLER_METHOD_NAME = BindingKey.create(
    'controller.current.operation',
  );

  /**
   * Binding key for the controller method metadata resolved in the current
   * request context
   */
  export const CONTROLLER_METHOD_META = 'controller.method.meta';
github strongloop / loopback-next / packages / core / src / keys.ts View on Github external
// controller
  export const CONTROLLERS = 'controllers';

  /**
   * Binding key for the controller class resolved in the current request
   * context
   */
  export const CONTROLLER_CLASS = BindingKey.create(
    'controller.current.ctor',
  );

  /**
   * Binding key for the controller method resolved in the current request
   * context
   */
  export const CONTROLLER_METHOD_NAME = BindingKey.create(
    'controller.current.operation',
  );

  /**
   * Binding key for the controller method metadata resolved in the current
   * request context
   */
  export const CONTROLLER_METHOD_META = 'controller.method.meta';

  /**
   * Binding key for the controller instance resolved in the current request
   * context
   */
  export const CONTROLLER_CURRENT = BindingKey.create('controller.current');

  export const LIFE_CYCLE_OBSERVERS = 'lifeCycleObservers';
github strongloop / loopback-next / packages / authentication / src / keys.ts View on Github external
export const USER_PROFILE_FACTORY = BindingKey.create<
    UserProfileFactory
  >('authentication.userProfileFactory');

  /**
   * Key used to bind an authentication strategy to the context for the
   * authentication function to use.
   *
   * @example
   * ```ts
   * server
   *   .bind(AuthenticationBindings.STRATEGY)
   *   .toProvider(MyAuthenticationStrategy);
   * ```
   */
  export const STRATEGY = BindingKey.create(
    'authentication.strategy',
  );

  /**
   * Key used to inject the authentication function into the sequence.
   *
   * @example
   * ```ts
   * class MySequence implements SequenceHandler {
   *   constructor(
   *     @inject(AuthenticationBindings.AUTH_ACTION)
   *     protected authenticateRequest: AuthenticateFn,
   *     // ... other sequence action injections
   *   ) {}
   *
   *   async handle(context: RequestContext) {
github strongloop / loopback-next / examples / context / src / interceptor-proxy.ts View on Github external
ValueOrPromise,
} from '@loopback/context';

type RequestIdGenerator = (requestCtx: Context) => string;

const REQUEST_CONTEXT = BindingKey.create('request.context');
const REQUEST_ID = BindingKey.create('tracing.requestId');
const REQUEST_ID_GENERATOR = BindingKey.create(
  'tracing.requestIdGenerator',
);

const TRACING_INTERCEPTOR = BindingKey.create(
  'tracing.interceptor',
);

const CONVERTER = BindingKey.create('converter');
const GREETER = BindingKey.create('greeter');

@bind(asGlobalInterceptor('tracing'))
class TracingInterceptor implements Provider {
  constructor(
    @inject(REQUEST_ID_GENERATOR) private generator: RequestIdGenerator,
  ) {}

  value() {
    return this.intercept.bind(this);
  }

  async intercept(
    invocationCtx: InvocationContext,
    next: () => ValueOrPromise,
  ) {
github strongloop / loopback-next / examples / context / src / dependency-injection.ts View on Github external
ContextView,
  filterByTag,
  Getter,
  inject,
  invokeMethod,
} from '@loopback/context';

/**
 * A strongly-typed binding key for current date
 */
const CURRENT_DATE = BindingKey.create('currentDate');

/**
 * A strongly-typed binding key for `GreetingService`
 */
const GREETING_SERVICE = BindingKey.create(
  'services.GreetingService',
);

/**
 * A factory function to return the current date
 */
const getCurrentDate = () => new Date();

interface Greeter {
  language: string;
  greet(name: string): string;
}

class ChineseGreeter implements Greeter {
  language = 'zh';
  greet(name: string) {
github strongloop / loopback-next / packages / rest / src / keys.ts View on Github external
/**
     * Binding key for setting and injecting a parameter parsing function
     */
    export const PARSE_PARAMS = BindingKey.create(
      'rest.sequence.actions.parseParams',
    );
    /**
     * Binding key for setting and injecting a controller route invoking function
     */
    export const INVOKE_METHOD = BindingKey.create(
      'rest.sequence.actions.invokeMethod',
    );
    /**
     * Binding key for setting and injecting an error logging function
     */
    export const LOG_ERROR = BindingKey.create(
      'rest.sequence.actions.logError',
    );
    /**
     * Binding key for setting and injecting a response writing function
     */
    export const SEND = BindingKey.create('rest.sequence.actions.send');
    /**
     * Binding key for setting and injecting a bad response writing function
     */
    export const REJECT = BindingKey.create(
      'rest.sequence.actions.reject',
    );
  }

  /**
   * Binding key for setting and injecting a wrapper function for retrieving
github strongloop / loopback-next / packages / rest / src / keys.ts View on Github external
/**
   * Binding key for setting and injecting the socket path of the RestServer
   */
  export const PATH = BindingKey.create('rest.path');
  /**
   * Binding key for setting and injecting the URL of RestServer
   */
  export const URL = BindingKey.create('rest.url');
  /**
   * Binding key for setting and injecting the protocol of RestServer
   */
  export const PROTOCOL = BindingKey.create('rest.protocol');
  /**
   * Binding key for HTTPS options
   */
  export const HTTPS_OPTIONS = BindingKey.create(
    'rest.httpsOptions',
  );

  /**
   * Binding key for the server itself
   */
  export const SERVER = BindingKey.create('servers.RestServer');

  /**
   * Internal binding key for basePath
   */
  export const BASE_PATH = BindingKey.create('rest.basePath');

  /**
   * Internal binding key for http-handler
   */
github strongloop / loopback-next / examples / context / src / interceptor-proxy.ts View on Github external
inject,
  Interceptor,
  InvocationContext,
  Provider,
  ValueOrPromise,
} from '@loopback/context';

type RequestIdGenerator = (requestCtx: Context) => string;

const REQUEST_CONTEXT = BindingKey.create('request.context');
const REQUEST_ID = BindingKey.create('tracing.requestId');
const REQUEST_ID_GENERATOR = BindingKey.create(
  'tracing.requestIdGenerator',
);

const TRACING_INTERCEPTOR = BindingKey.create(
  'tracing.interceptor',
);

const CONVERTER = BindingKey.create('converter');
const GREETER = BindingKey.create('greeter');

@bind(asGlobalInterceptor('tracing'))
class TracingInterceptor implements Provider {
  constructor(
    @inject(REQUEST_ID_GENERATOR) private generator: RequestIdGenerator,
  ) {}

  value() {
    return this.intercept.bind(this);
  }
github sourcefuse / loopback4-authorization / src / keys.ts View on Github external
import {BindingKey} from '@loopback/context';
import {MetadataAccessor} from '@loopback/metadata';
import {
  AuthorizeFn,
  AuthorizationMetadata,
  UserPermissionsFn,
  AuthorizationConfig,
} from './types';

/**
 * Binding keys used by this component.
 */
export namespace AuthorizationBindings {
  export const AUTHORIZE_ACTION = BindingKey.create(
    'sf.userAuthorization.actions.authorize',
  );

  export const METADATA = BindingKey.create(
    'sf.userAuthorization.operationMetadata',
  );

  export const USER_PERMISSIONS = BindingKey.create>(
    'sf.userAuthorization.actions.userPermissions',
  );

  export const CONFIG = BindingKey.create(
    'sf.userAuthorization.config',
  );

  export const PATHS_TO_ALLOW_ALWAYS = 'sf.userAuthorization.allowAlways';