@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.
@@ -71,6 +71,10 @@ var ErrorCode;
71
71
  * Identity type error.
72
72
  */
73
73
  ErrorCode["IdentityTypeNotSupported"] = "IdentityTypeNotSupported";
74
+ /**
75
+ * Authentication info already exists error.
76
+ */
77
+ ErrorCode["AuthorizationInfoAlreadyExists"] = "AuthorizationInfoAlreadyExists";
74
78
  })(ErrorCode || (ErrorCode = {}));
75
79
  /**
76
80
  * @internal
@@ -92,6 +96,9 @@ ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token
92
96
  ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
93
97
  // IdentityTypeNotSupported Error
94
98
  ErrorMessage.IdentityTypeNotSupported = "{0} identity is not supported in {1}";
99
+ // AuthorizationInfoError
100
+ ErrorMessage.AuthorizationHeaderAlreadyExists = "Authorization header already exists!";
101
+ ErrorMessage.BasicCredentialAlreadyExists = "Basic credential already exists!";
95
102
  // InvalidParameter Error
96
103
  ErrorMessage.EmptyParameter = "Parameter {0} is empty";
97
104
  ErrorMessage.DuplicateHttpsOptionProperty = "Axios HTTPS agent already defined value for property {0}";
@@ -1419,7 +1426,6 @@ function createApiClient(apiEndpoint, authProvider) {
1419
1426
  }
1420
1427
 
1421
1428
  // Copyright (c) Microsoft Corporation.
1422
- // Licensed under the MIT license.
1423
1429
  /**
1424
1430
  * Provider that handles Bearer Token authentication
1425
1431
  *
@@ -1440,6 +1446,10 @@ class BearerTokenAuthProvider {
1440
1446
  * @param config - Contains all the request information and can be updated to include extra authentication info.
1441
1447
  * Refer https://axios-http.com/docs/req_config for detailed document.
1442
1448
  *
1449
+ * @returns Updated axios request config.
1450
+ *
1451
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header already exists in request configuration.
1452
+ *
1443
1453
  * @beta
1444
1454
  */
1445
1455
  async AddAuthenticationInfo(config) {
@@ -1448,13 +1458,64 @@ class BearerTokenAuthProvider {
1448
1458
  config.headers = {};
1449
1459
  }
1450
1460
  if (config.headers["Authorization"]) {
1451
- throw new Error("Authorization header already exists!");
1461
+ throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
1452
1462
  }
1453
1463
  config.headers["Authorization"] = `Bearer ${token}`;
1454
1464
  return config;
1455
1465
  }
1456
1466
  }
1457
1467
 
1468
+ // Copyright (c) Microsoft Corporation.
1469
+ /**
1470
+ * Provider that handles Basic authentication
1471
+ *
1472
+ * @beta
1473
+ */
1474
+ class BasicAuthProvider {
1475
+ /**
1476
+ *
1477
+ * @param userName - Username used in basic auth
1478
+ * @param password - Password used in basic auth
1479
+ *
1480
+ * @beta
1481
+ */
1482
+ constructor(userName, password) {
1483
+ if (!userName) {
1484
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "username"), ErrorCode.InvalidParameter);
1485
+ }
1486
+ if (!password) {
1487
+ throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "password"), ErrorCode.InvalidParameter);
1488
+ }
1489
+ this.userName = userName;
1490
+ this.password = password;
1491
+ }
1492
+ /**
1493
+ * Adds authentication info to http requests
1494
+ *
1495
+ * @param config - Contains all the request information and can be updated to include extra authentication info.
1496
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1497
+ *
1498
+ * @returns Updated axios request config.
1499
+ *
1500
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
1501
+ *
1502
+ * @beta
1503
+ */
1504
+ async AddAuthenticationInfo(config) {
1505
+ if (config.headers && config.headers["Authorization"]) {
1506
+ throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
1507
+ }
1508
+ if (config.auth) {
1509
+ throw new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
1510
+ }
1511
+ config.auth = {
1512
+ username: this.userName,
1513
+ password: this.password,
1514
+ };
1515
+ return config;
1516
+ }
1517
+ }
1518
+
1458
1519
  // Copyright (c) Microsoft Corporation.
1459
1520
  /**
1460
1521
  * Provider that handles Certificate authentication
@@ -2711,5 +2772,5 @@ class MessageBuilder {
2711
2772
  }
2712
2773
  }
2713
2774
 
2714
- export { AppCredential, BearerTokenAuthProvider, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MessageBuilder, MsGraphAuthProvider, NotificationBot, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
2775
+ export { AppCredential, BasicAuthProvider, BearerTokenAuthProvider, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MessageBuilder, MsGraphAuthProvider, NotificationBot, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
2715
2776
  //# sourceMappingURL=index.esm2017.mjs.map