UNPKG

@camunda8/sdk

Version:

[![NPM](https://nodei.co/npm/@camunda8/sdk.png)](https://www.npmjs.com/package/@camunda8/sdk)

48 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BearerAuthProvider = void 0; const debug_1 = require("debug"); const lib_1 = require("../../lib"); /** * The `BearerAuthProvider` class is an implementation of {@link IHeadersProvider} * that uses a bearer token for authentication. This class is * responsible for providing the authentication headers to the SDK. Note that it does * not handle token expiration or renewal. The token must be set manually using the * `setToken` method. Nor does it handle token retrieval. The token must be provided * in the configuration object or set manually using the `setToken` method. * * This class is useful for scenarios where you have a static bearer token that * does not expire or where you want to manage the token lifecycle yourself. * * @example * ```typescript * const authProvider = new BearerAuthProvider({ * config: { * CAMUNDA_OAUTH_TOKEN: 'your-bearer-token', * }, * }) * * authProvider.setToken('newTokenValue') * ``` */ class BearerAuthProvider { constructor(options) { const config = lib_1.CamundaEnvironmentConfigurator.mergeConfigWithEnvironment(options?.config ?? {}); this.bearerToken = (0, lib_1.RequireConfiguration)(config.CAMUNDA_OAUTH_TOKEN, 'CAMUNDA_OAUTH_TOKEN'); } async getHeaders(audienceType) { (0, debug_1.debug)(`Token request for ${audienceType}`); return Promise.resolve({ authorization: `Bearer ${this.bearerToken}` }); } /** * Updates the bearer token used for authentication. * * @param bearerToken - The new bearer token to be used. This should be a valid * token string obtained from a trusted source. */ async setToken(bearerToken) { this.bearerToken = bearerToken; } } exports.BearerAuthProvider = BearerAuthProvider; //# sourceMappingURL=BearerAuthProvider.js.map