@microsoft/teamsfx 0.6.3-alpha.633d9d21e.0 → 0.6.3-alpha.85a816c65.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.
@@ -101,6 +101,10 @@ exports.ErrorCode = void 0;
101
101
  * Identity type error.
102
102
  */
103
103
  ErrorCode["IdentityTypeNotSupported"] = "IdentityTypeNotSupported";
104
+ /**
105
+ * Authentication info already exists error.
106
+ */
107
+ ErrorCode["AuthorizationInfoAlreadyExists"] = "AuthorizationInfoAlreadyExists";
104
108
  })(exports.ErrorCode || (exports.ErrorCode = {}));
105
109
  /**
106
110
  * @internal
@@ -122,6 +126,9 @@ ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token
122
126
  ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
123
127
  // IdentityTypeNotSupported Error
124
128
  ErrorMessage.IdentityTypeNotSupported = "{0} identity is not supported in {1}";
129
+ // AuthorizationInfoError
130
+ ErrorMessage.AuthorizationHeaderAlreadyExists = "Authorization header already exists!";
131
+ ErrorMessage.BasicCredentialAlreadyExists = "Basic credential already exists!";
125
132
  // InvalidParameter Error
126
133
  ErrorMessage.EmptyParameter = "Parameter {0} is empty";
127
134
  ErrorMessage.DuplicateHttpsOptionProperty = "Axios HTTPS agent already defined value for property {0}";
@@ -1493,6 +1500,10 @@ class BearerTokenAuthProvider {
1493
1500
  * @param config - Contains all the request information and can be updated to include extra authentication info.
1494
1501
  * Refer https://axios-http.com/docs/req_config for detailed document.
1495
1502
  *
1503
+ * @returns Updated axios request config.
1504
+ *
1505
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header already exists in request configuration.
1506
+ *
1496
1507
  * @beta
1497
1508
  */
1498
1509
  AddAuthenticationInfo(config) {
@@ -1502,7 +1513,7 @@ class BearerTokenAuthProvider {
1502
1513
  config.headers = {};
1503
1514
  }
1504
1515
  if (config.headers["Authorization"]) {
1505
- throw new Error("Authorization header already exists!");
1516
+ throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1506
1517
  }
1507
1518
  config.headers["Authorization"] = `Bearer ${token}`;
1508
1519
  return config;
@@ -1510,6 +1521,59 @@ class BearerTokenAuthProvider {
1510
1521
  }
1511
1522
  }
1512
1523
 
1524
+ // Copyright (c) Microsoft Corporation.
1525
+ /**
1526
+ * Provider that handles Basic authentication
1527
+ *
1528
+ * @beta
1529
+ */
1530
+ class BasicAuthProvider {
1531
+ /**
1532
+ *
1533
+ * @param userName - Username used in basic auth
1534
+ * @param password - Password used in basic auth
1535
+ *
1536
+ * @beta
1537
+ */
1538
+ constructor(userName, password) {
1539
+ if (!userName) {
1540
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "username"), exports.ErrorCode.InvalidParameter);
1541
+ }
1542
+ if (!password) {
1543
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "password"), exports.ErrorCode.InvalidParameter);
1544
+ }
1545
+ this.userName = userName;
1546
+ this.password = password;
1547
+ }
1548
+ /**
1549
+ * Adds authentication info to http requests
1550
+ *
1551
+ * @param config - Contains all the request information and can be updated to include extra authentication info.
1552
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1553
+ *
1554
+ * @returns Updated axios request config.
1555
+ *
1556
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
1557
+ *
1558
+ * @beta
1559
+ */
1560
+ AddAuthenticationInfo(config) {
1561
+ return tslib.__awaiter(this, void 0, void 0, function* () {
1562
+ if (config.headers && config.headers["Authorization"]) {
1563
+ throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1564
+ }
1565
+ if (config.auth) {
1566
+ throw new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
1567
+ }
1568
+ config.auth = {
1569
+ username: this.userName,
1570
+ password: this.password,
1571
+ };
1572
+ return config;
1573
+ });
1574
+ }
1575
+ }
1576
+
1513
1577
  // Copyright (c) Microsoft Corporation.
1514
1578
  /**
1515
1579
  * Provider that handles Certificate authentication
@@ -2805,6 +2869,7 @@ class MessageBuilder {
2805
2869
  }
2806
2870
 
2807
2871
  exports.AppCredential = AppCredential;
2872
+ exports.BasicAuthProvider = BasicAuthProvider;
2808
2873
  exports.BearerTokenAuthProvider = BearerTokenAuthProvider;
2809
2874
  exports.CertificateAuthProvider = CertificateAuthProvider;
2810
2875
  exports.Channel = Channel;