Function ensureBearerTokenProvider

Generates a "service middleware" that can be used on route controllers in order to validate the presence of a bearer token on the requests authorization header.

The registered service is an instance of EnsureBearerToken, and it uses the key ensureBearerToken.

Since it's a "provider creator", when registering it, you can pass custom options.

  // Register it on the container
container.register(ensureBearerTokenProvider);

// Let's assume we are in a controller now...
// Getting access to the middleware.
const ensureBearerToken = container.get<ExpressMiddleware>('ensureBearerToken');
  // Register it on the container
container.register(
ensureBearerTokenProvider({
serviceName: 'ensureBearerTokenCustom',
error: {
message: 'Missing token!',
},
}),
);

Properties

Properties

provider
register: ProviderRegisterFn<Jimpex>