UNPKG

botframework-connector

Version:

Bot Connector is autorest generated connector client.

115 lines 5.61 kB
"use strict"; /** * @module botframework-connector */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CertificateServiceClientCredentialsFactory = void 0; const serviceClientCredentialsFactory_1 = require("./serviceClientCredentialsFactory"); const assert_1 = require("assert"); const certificateAppCredentials_1 = require("./certificateAppCredentials"); const util_1 = require("util"); const opensslWrapper = __importStar(require("openssl-wrapper")); const openssl = (0, util_1.promisify)(opensslWrapper.default); /** * A Certificate implementation of the [ServiceClientCredentialsFactory](xref:botframework-connector.ServiceClientCredentialsFactory) abstract class. */ class CertificateServiceClientCredentialsFactory extends serviceClientCredentialsFactory_1.ServiceClientCredentialsFactory { /** * @internal */ constructor(appId, certificateThumbprintOrx5c, certificatePrivateKey, tenantId, x5c) { super(); (0, assert_1.ok)(appId === null || appId === void 0 ? void 0 : appId.trim(), 'CertificateServiceClientCredentialsFactory.constructor(): missing appId.'); (0, assert_1.ok)(certificatePrivateKey === null || certificatePrivateKey === void 0 ? void 0 : certificatePrivateKey.trim(), 'CertificateServiceClientCredentialsFactory.constructor(): missing certificatePrivateKey.'); if (certificateThumbprintOrx5c === null || certificateThumbprintOrx5c === void 0 ? void 0 : certificateThumbprintOrx5c.includes('-----BEGIN CERTIFICATE-----')) { this.x5c = certificateThumbprintOrx5c; } else { (0, assert_1.ok)(certificateThumbprintOrx5c === null || certificateThumbprintOrx5c === void 0 ? void 0 : certificateThumbprintOrx5c.trim(), 'CertificateServiceClientCredentialsFactory.constructor(): missing certificateThumbprint or x5c value.'); this.certificateThumbprint = certificateThumbprintOrx5c; this.x5c = x5c; } this.appId = appId; this.certificatePrivateKey = certificatePrivateKey; this.tenantId = tenantId; } /** * @inheritdoc */ isValidAppId(appId) { return __awaiter(this, void 0, void 0, function* () { return appId === this.appId; }); } /** * @param cert Value with the certificate content. * @returns The thumbprint value calculated from the cert content. */ getThumbprint(cert) { return __awaiter(this, void 0, void 0, function* () { const fingerprintResponse = yield openssl('x509', Buffer.from(cert), { fingerprint: true, noout: true }); return Buffer.from(fingerprintResponse) .toString() .replace(/^.*Fingerprint=/, '') .replace(/:/g, '') .trim(); }); } /** * @inheritdoc */ isAuthenticationDisabled() { return __awaiter(this, void 0, void 0, function* () { // Auth is always enabled for Certificate. return; }); } /** * @inheritdoc */ createCredentials(appId, audience) { var _a; return __awaiter(this, void 0, void 0, function* () { (0, assert_1.ok)(yield this.isValidAppId(appId), 'CertificateServiceClientCredentialsFactory.createCredentials(): Invalid Managed ID.'); return new certificateAppCredentials_1.CertificateAppCredentials(this.appId, (_a = this.certificateThumbprint) !== null && _a !== void 0 ? _a : (yield this.getThumbprint(this.x5c)), this.certificatePrivateKey, this.tenantId, audience, this.x5c); }); } } exports.CertificateServiceClientCredentialsFactory = CertificateServiceClientCredentialsFactory; //# sourceMappingURL=certificateServiceClientCredentialsFactory.js.map