UNPKG

@planet-a/affinity-node

Version:
40 lines (39 loc) 1.14 kB
/** * Applies http authentication to the request context. */ export class BearerAuthAuthentication { /** * Configures the http authentication with the required details. * * @param tokenProvider service that can provide the up-to-date token when needed */ constructor(tokenProvider) { Object.defineProperty(this, "tokenProvider", { enumerable: true, configurable: true, writable: true, value: tokenProvider }); } getName() { return "bearerAuth"; } async applySecurityAuthentication(context) { context.setHeaderParam("Authorization", "Bearer " + await this.tokenProvider.getToken()); } } /** * Creates the authentication methods from a swagger description. * */ export function configureAuthMethods(config) { let authMethods = {}; if (!config) { return authMethods; } authMethods["default"] = config["default"]; if (config["bearerAuth"]) { authMethods["bearerAuth"] = new BearerAuthAuthentication(config["bearerAuth"]["tokenProvider"]); } return authMethods; }