@microsoft/teamsfx 0.6.3-alpha.768a76f6e.0 → 0.6.3-alpha.81c48cbfc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,7 @@ var botbuilder = require('botbuilder');
12
12
  var botbuilderDialogs = require('botbuilder-dialogs');
13
13
  var uuid = require('uuid');
14
14
  var axios = require('axios');
15
+ var https = require('https');
15
16
  var path = require('path');
16
17
  var fs = require('fs');
17
18
 
@@ -121,6 +122,9 @@ ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token
121
122
  ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
122
123
  // IdentityTypeNotSupported Error
123
124
  ErrorMessage.IdentityTypeNotSupported = "{0} identity is not supported in {1}";
125
+ // InvalidParameter Error
126
+ ErrorMessage.EmptyParameter = "Parameter {0} is empty";
127
+ ErrorMessage.DuplicateHttpsOptionProperty = "Axios HTTPS agent already defined value for property {0}";
124
128
  /**
125
129
  * Error class with code and message thrown by the SDK.
126
130
  *
@@ -1506,6 +1510,105 @@ class BearerTokenAuthProvider {
1506
1510
  }
1507
1511
  }
1508
1512
 
1513
+ // Copyright (c) Microsoft Corporation.
1514
+ /**
1515
+ * Provider that handles Certificate authentication
1516
+ *
1517
+ * @beta
1518
+ */
1519
+ class CertificateAuthProvider {
1520
+ /**
1521
+ *
1522
+ * @param { SecureContextOptions } certOption - information about the cert used in http requests
1523
+ *
1524
+ * @beta
1525
+ */
1526
+ constructor(certOption) {
1527
+ if (certOption && Object.keys(certOption).length !== 0) {
1528
+ this.certOption = certOption;
1529
+ }
1530
+ else {
1531
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "certOption"), exports.ErrorCode.InvalidParameter);
1532
+ }
1533
+ }
1534
+ /**
1535
+ * Adds authentication info to http requests.
1536
+ *
1537
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
1538
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1539
+ *
1540
+ * @returns Updated axios request config.
1541
+ *
1542
+ * @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
1543
+ *
1544
+ * @beta
1545
+ */
1546
+ AddAuthenticationInfo(config) {
1547
+ return tslib.__awaiter(this, void 0, void 0, function* () {
1548
+ if (!config.httpsAgent) {
1549
+ config.httpsAgent = new https.Agent(this.certOption);
1550
+ }
1551
+ else {
1552
+ const existingProperties = new Set(Object.keys(config.httpsAgent.options));
1553
+ for (const property of Object.keys(this.certOption)) {
1554
+ if (existingProperties.has(property)) {
1555
+ throw new ErrorWithCode(formatString(ErrorMessage.DuplicateHttpsOptionProperty, property), exports.ErrorCode.InvalidParameter);
1556
+ }
1557
+ }
1558
+ Object.assign(config.httpsAgent.options, this.certOption);
1559
+ }
1560
+ return config;
1561
+ });
1562
+ }
1563
+ }
1564
+ /**
1565
+ * Helper to create SecureContextOptions from PEM format cert
1566
+ *
1567
+ * @param { string | Buffer } cert - The cert chain in PEM format
1568
+ * @param { string | Buffer } key - The private key for the cert chain
1569
+ * @param { string? } passphrase - The passphrase for private key
1570
+ * @param { string? | Buffer? } ca - Overrides the trusted CA certificates
1571
+ *
1572
+ * @returns Instance of SecureContextOptions
1573
+ *
1574
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1575
+ *
1576
+ */
1577
+ function createPemCertOption(cert, key, passphrase, ca) {
1578
+ if (cert.length === 0) {
1579
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "cert"), exports.ErrorCode.InvalidParameter);
1580
+ }
1581
+ if (key.length === 0) {
1582
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "key"), exports.ErrorCode.InvalidParameter);
1583
+ }
1584
+ return {
1585
+ cert,
1586
+ key,
1587
+ passphrase,
1588
+ ca,
1589
+ };
1590
+ }
1591
+ /**
1592
+ * Helper to create SecureContextOptions from PFX format cert
1593
+ *
1594
+ * @param { string | Buffer } pfx - The content of .pfx file
1595
+ * @param { string? } passphrase - Optional. The passphrase of .pfx file
1596
+ *
1597
+ * @returns Instance of SecureContextOptions
1598
+ *
1599
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
1600
+ *
1601
+ */
1602
+ function createPfxCertOption(pfx, passphrase) {
1603
+ if (pfx.length === 0) {
1604
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "pfx"), exports.ErrorCode.InvalidParameter);
1605
+ }
1606
+ return {
1607
+ pfx,
1608
+ passphrase,
1609
+ };
1610
+ }
1611
+
1509
1612
  // Copyright (c) Microsoft Corporation.
1510
1613
  /**
1511
1614
  * A class providing credential and configuration.
@@ -2703,6 +2806,7 @@ class MessageBuilder {
2703
2806
 
2704
2807
  exports.AppCredential = AppCredential;
2705
2808
  exports.BearerTokenAuthProvider = BearerTokenAuthProvider;
2809
+ exports.CertificateAuthProvider = CertificateAuthProvider;
2706
2810
  exports.Channel = Channel;
2707
2811
  exports.CommandBot = CommandBot;
2708
2812
  exports.ConversationBot = ConversationBot;
@@ -2718,6 +2822,8 @@ exports.TeamsFx = TeamsFx;
2718
2822
  exports.TeamsUserCredential = TeamsUserCredential;
2719
2823
  exports.createApiClient = createApiClient;
2720
2824
  exports.createMicrosoftGraphClient = createMicrosoftGraphClient;
2825
+ exports.createPemCertOption = createPemCertOption;
2826
+ exports.createPfxCertOption = createPfxCertOption;
2721
2827
  exports.getLogLevel = getLogLevel;
2722
2828
  exports.getTediousConnectionConfig = getTediousConnectionConfig;
2723
2829
  exports.sendAdaptiveCard = sendAdaptiveCard;