botframework-connector
Version:
Bot Connector is autorest generated connector client.
42 lines • 1.69 kB
JavaScript
;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenCredentials = void 0;
const core_http_1 = require("@azure/core-http");
const HeaderConstants = core_http_1.Constants.HeaderConstants;
const DEFAULT_AUTHORIZATION_SCHEME = 'Bearer';
/**
* A credentials object that uses a token string and a authorzation scheme to authenticate.
*/
class TokenCredentials {
/**
* Creates a new TokenCredentials object.
*
* @class
* @param {string} token The token.
* @param {string} [authorizationScheme] The authorization scheme.
*/
constructor(token, authorizationScheme = DEFAULT_AUTHORIZATION_SCHEME) {
this.authorizationScheme = DEFAULT_AUTHORIZATION_SCHEME;
if (!token) {
throw new Error('token cannot be null or undefined.');
}
this.token = token;
this.authorizationScheme = authorizationScheme;
}
/**
* Signs a request with the Authentication header.
*
* @param {WebResourceLike} webResource The WebResourceLike to be signed.
* @returns {Promise<WebResourceLike>} The signed request object.
*/
signRequest(webResource) {
if (!webResource.headers)
webResource.headers = new core_http_1.HttpHeaders();
webResource.headers.set(HeaderConstants.AUTHORIZATION, `${this.authorizationScheme} ${this.token}`);
return Promise.resolve(webResource);
}
}
exports.TokenCredentials = TokenCredentials;
//# sourceMappingURL=tokenCredentials.js.map