@azure/msal-common 6.0.0 → 6.3.0-beta.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.
Files changed (188) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +62 -62
  3. package/dist/_virtual/_tslib.js +1 -1
  4. package/dist/account/AccountInfo.d.ts +6 -1
  5. package/dist/account/AccountInfo.d.ts.map +1 -1
  6. package/dist/account/AuthToken.js +1 -1
  7. package/dist/account/AuthToken.js.map +1 -1
  8. package/dist/account/CcsCredential.js +1 -1
  9. package/dist/account/CcsCredential.js.map +1 -1
  10. package/dist/account/ClientInfo.js +1 -1
  11. package/dist/account/ClientInfo.js.map +1 -1
  12. package/dist/account/TokenClaims.d.ts +30 -0
  13. package/dist/account/TokenClaims.d.ts.map +1 -1
  14. package/dist/authority/Authority.d.ts +9 -1
  15. package/dist/authority/Authority.d.ts.map +1 -1
  16. package/dist/authority/Authority.js +36 -11
  17. package/dist/authority/Authority.js.map +1 -1
  18. package/dist/authority/AuthorityFactory.d.ts +2 -2
  19. package/dist/authority/AuthorityFactory.d.ts.map +1 -1
  20. package/dist/authority/AuthorityFactory.js +5 -5
  21. package/dist/authority/AuthorityFactory.js.map +1 -1
  22. package/dist/authority/AuthorityOptions.d.ts +8 -0
  23. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  24. package/dist/authority/AuthorityOptions.js +24 -0
  25. package/dist/authority/AuthorityOptions.js.map +1 -0
  26. package/dist/authority/AuthorityType.js +1 -1
  27. package/dist/authority/AuthorityType.js.map +1 -1
  28. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  29. package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -1
  30. package/dist/authority/ImdsOptions.d.ts +7 -0
  31. package/dist/authority/ImdsOptions.d.ts.map +1 -0
  32. package/dist/authority/OpenIdConfigResponse.js +1 -1
  33. package/dist/authority/OpenIdConfigResponse.js.map +1 -1
  34. package/dist/authority/ProtocolMode.js +1 -1
  35. package/dist/authority/ProtocolMode.js.map +1 -1
  36. package/dist/authority/RegionDiscovery.d.ts +3 -6
  37. package/dist/authority/RegionDiscovery.d.ts.map +1 -1
  38. package/dist/authority/RegionDiscovery.js +19 -11
  39. package/dist/authority/RegionDiscovery.js.map +1 -1
  40. package/dist/cache/CacheManager.d.ts +1 -1
  41. package/dist/cache/CacheManager.js +3 -3
  42. package/dist/cache/CacheManager.js.map +1 -1
  43. package/dist/cache/entities/AccessTokenEntity.js +1 -1
  44. package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
  45. package/dist/cache/entities/AccountEntity.d.ts +3 -1
  46. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  47. package/dist/cache/entities/AccountEntity.js +16 -12
  48. package/dist/cache/entities/AccountEntity.js.map +1 -1
  49. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  50. package/dist/cache/entities/AppMetadataEntity.js.map +1 -1
  51. package/dist/cache/entities/AuthorityMetadataEntity.js +1 -1
  52. package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -1
  53. package/dist/cache/entities/CacheRecord.js +1 -1
  54. package/dist/cache/entities/CacheRecord.js.map +1 -1
  55. package/dist/cache/entities/CredentialEntity.js +5 -5
  56. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  57. package/dist/cache/entities/IdTokenEntity.js +1 -1
  58. package/dist/cache/entities/IdTokenEntity.js.map +1 -1
  59. package/dist/cache/entities/RefreshTokenEntity.js +1 -1
  60. package/dist/cache/entities/RefreshTokenEntity.js.map +1 -1
  61. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  62. package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -1
  63. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  64. package/dist/cache/entities/ThrottlingEntity.js.map +1 -1
  65. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  66. package/dist/cache/persistence/TokenCacheContext.js.map +1 -1
  67. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  68. package/dist/client/AuthorizationCodeClient.js +122 -93
  69. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  70. package/dist/client/BaseClient.js +2 -2
  71. package/dist/client/BaseClient.js.map +1 -1
  72. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  73. package/dist/client/ClientCredentialClient.js +4 -3
  74. package/dist/client/ClientCredentialClient.js.map +1 -1
  75. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  76. package/dist/client/DeviceCodeClient.js +4 -2
  77. package/dist/client/DeviceCodeClient.js.map +1 -1
  78. package/dist/client/OnBehalfOfClient.js +3 -2
  79. package/dist/client/OnBehalfOfClient.js.map +1 -1
  80. package/dist/client/RefreshTokenClient.js +2 -1
  81. package/dist/client/RefreshTokenClient.js.map +1 -1
  82. package/dist/client/SilentFlowClient.js +1 -1
  83. package/dist/client/SilentFlowClient.js.map +1 -1
  84. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  85. package/dist/client/UsernamePasswordClient.js +3 -1
  86. package/dist/client/UsernamePasswordClient.js.map +1 -1
  87. package/dist/config/ClientConfiguration.d.ts +29 -1
  88. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  89. package/dist/config/ClientConfiguration.js +21 -8
  90. package/dist/config/ClientConfiguration.js.map +1 -1
  91. package/dist/crypto/ICrypto.d.ts +4 -2
  92. package/dist/crypto/ICrypto.d.ts.map +1 -1
  93. package/dist/crypto/ICrypto.js +1 -1
  94. package/dist/crypto/ICrypto.js.map +1 -1
  95. package/dist/crypto/IGuidGenerator.d.ts +5 -0
  96. package/dist/crypto/IGuidGenerator.d.ts.map +1 -0
  97. package/dist/crypto/PopTokenGenerator.d.ts +30 -0
  98. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  99. package/dist/crypto/PopTokenGenerator.js +38 -2
  100. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  101. package/dist/error/AuthError.js +3 -3
  102. package/dist/error/AuthError.js.map +1 -1
  103. package/dist/error/ClientAuthError.js +1 -1
  104. package/dist/error/ClientAuthError.js.map +1 -1
  105. package/dist/error/ClientConfigurationError.d.ts +11 -0
  106. package/dist/error/ClientConfigurationError.d.ts.map +1 -1
  107. package/dist/error/ClientConfigurationError.js +12 -2
  108. package/dist/error/ClientConfigurationError.js.map +1 -1
  109. package/dist/error/InteractionRequiredAuthError.js +1 -1
  110. package/dist/error/InteractionRequiredAuthError.js.map +1 -1
  111. package/dist/error/ServerError.js +1 -1
  112. package/dist/error/ServerError.js.map +1 -1
  113. package/dist/index.cjs.js +764 -176
  114. package/dist/index.cjs.js.map +1 -1
  115. package/dist/index.d.ts +8 -2
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +5 -1
  118. package/dist/index.js.map +1 -1
  119. package/dist/logger/Logger.js +13 -13
  120. package/dist/logger/Logger.js.map +1 -1
  121. package/dist/network/INetworkModule.d.ts +1 -0
  122. package/dist/network/INetworkModule.d.ts.map +1 -1
  123. package/dist/network/INetworkModule.js +1 -1
  124. package/dist/network/INetworkModule.js.map +1 -1
  125. package/dist/network/NetworkManager.js +1 -1
  126. package/dist/network/NetworkManager.js.map +1 -1
  127. package/dist/network/ThrottlingUtils.js +1 -1
  128. package/dist/network/ThrottlingUtils.js.map +1 -1
  129. package/dist/packageMetadata.d.ts +1 -1
  130. package/dist/packageMetadata.d.ts.map +1 -1
  131. package/dist/packageMetadata.js +2 -2
  132. package/dist/packageMetadata.js.map +1 -1
  133. package/dist/request/AuthenticationHeaderParser.js +3 -3
  134. package/dist/request/AuthenticationHeaderParser.js.map +1 -1
  135. package/dist/request/BaseAuthRequest.d.ts +8 -5
  136. package/dist/request/BaseAuthRequest.d.ts.map +1 -1
  137. package/dist/request/CommonAuthorizationUrlRequest.d.ts +1 -0
  138. package/dist/request/CommonAuthorizationUrlRequest.d.ts.map +1 -1
  139. package/dist/request/CommonEndSessionRequest.d.ts +2 -0
  140. package/dist/request/CommonEndSessionRequest.d.ts.map +1 -1
  141. package/dist/request/RequestParameterBuilder.d.ts +18 -1
  142. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  143. package/dist/request/RequestParameterBuilder.js +37 -3
  144. package/dist/request/RequestParameterBuilder.js.map +1 -1
  145. package/dist/request/RequestValidator.js +1 -1
  146. package/dist/request/RequestValidator.js.map +1 -1
  147. package/dist/request/ScopeSet.js +4 -4
  148. package/dist/request/ScopeSet.js.map +1 -1
  149. package/dist/response/AuthenticationResult.d.ts +1 -0
  150. package/dist/response/AuthenticationResult.d.ts.map +1 -1
  151. package/dist/response/ResponseHandler.d.ts.map +1 -1
  152. package/dist/response/ResponseHandler.js +6 -5
  153. package/dist/response/ResponseHandler.js.map +1 -1
  154. package/dist/response/ServerAuthorizationCodeResponse.d.ts +1 -0
  155. package/dist/response/ServerAuthorizationCodeResponse.d.ts.map +1 -1
  156. package/dist/telemetry/performance/IPerformanceClient.d.ts +22 -0
  157. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -0
  158. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +6 -0
  159. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts.map +1 -0
  160. package/dist/telemetry/performance/PerformanceClient.d.ts +125 -0
  161. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -0
  162. package/dist/telemetry/performance/PerformanceClient.js +275 -0
  163. package/dist/telemetry/performance/PerformanceClient.js.map +1 -0
  164. package/dist/telemetry/performance/PerformanceEvent.d.ts +203 -0
  165. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -0
  166. package/dist/telemetry/performance/PerformanceEvent.js +100 -0
  167. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -0
  168. package/dist/telemetry/performance/StubPerformanceClient.d.ts +13 -0
  169. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -0
  170. package/dist/telemetry/performance/StubPerformanceClient.js +37 -0
  171. package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -0
  172. package/dist/telemetry/server/ServerTelemetryManager.js +4 -4
  173. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
  174. package/dist/url/UrlString.js +2 -2
  175. package/dist/url/UrlString.js.map +1 -1
  176. package/dist/utils/Constants.d.ts +8 -1
  177. package/dist/utils/Constants.d.ts.map +1 -1
  178. package/dist/utils/Constants.js +9 -2
  179. package/dist/utils/Constants.js.map +1 -1
  180. package/dist/utils/ProtocolUtils.js +3 -3
  181. package/dist/utils/ProtocolUtils.js.map +1 -1
  182. package/dist/utils/StringUtils.js +1 -1
  183. package/dist/utils/StringUtils.js.map +1 -1
  184. package/dist/utils/TimeUtils.js +1 -1
  185. package/dist/utils/TimeUtils.js.map +1 -1
  186. package/package.json +74 -76
  187. package/CHANGELOG.json +0 -1282
  188. package/CHANGELOG.md +0 -491
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v6.0.0 2022-01-04 */
1
+ /*! @azure/msal-common v6.3.0-beta.0 2022-04-27 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -102,6 +102,7 @@ var Constants = {
102
102
  // default authority
103
103
  DEFAULT_AUTHORITY: "https://login.microsoftonline.com/common/",
104
104
  DEFAULT_AUTHORITY_HOST: "login.microsoftonline.com",
105
+ DEFAULT_COMMON_TENANT: "common",
105
106
  // ADFS String
106
107
  ADFS: "adfs",
107
108
  // Default AAD Instance Discovery Endpoint
@@ -135,7 +136,9 @@ var Constants = {
135
136
  IMDS_TIMEOUT: 2000,
136
137
  AZURE_REGION_AUTO_DISCOVER_FLAG: "TryAutoDetect",
137
138
  REGIONAL_AUTH_PUBLIC_CLOUD_SUFFIX: "login.microsoft.com",
138
- KNOWN_PUBLIC_CLOUDS: ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"]
139
+ KNOWN_PUBLIC_CLOUDS: ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"],
140
+ TOKEN_RESPONSE_TYPE: "token",
141
+ ID_TOKEN_RESPONSE_TYPE: "id_token"
139
142
  };
140
143
  var OIDC_DEFAULT_SCOPES = [
141
144
  Constants.OPENID_SCOPE,
@@ -212,6 +215,8 @@ var AADServerParamKeys;
212
215
  AADServerParamKeys["X_CLIENT_CURR_TELEM"] = "x-client-current-telemetry";
213
216
  AADServerParamKeys["X_CLIENT_LAST_TELEM"] = "x-client-last-telemetry";
214
217
  AADServerParamKeys["X_MS_LIB_CAPABILITY"] = "x-ms-lib-capability";
218
+ AADServerParamKeys["X_APP_NAME"] = "x-app-name";
219
+ AADServerParamKeys["X_APP_VER"] = "x-app-ver";
215
220
  AADServerParamKeys["POST_LOGOUT_URI"] = "post_logout_redirect_uri";
216
221
  AADServerParamKeys["ID_TOKEN_HINT"] = "id_token_hint";
217
222
  AADServerParamKeys["DEVICE_CODE"] = "device_code";
@@ -226,6 +231,8 @@ var AADServerParamKeys;
226
231
  AADServerParamKeys["FOCI"] = "foci";
227
232
  AADServerParamKeys["CCS_HEADER"] = "X-AnchorMailbox";
228
233
  AADServerParamKeys["RETURN_SPA_CODE"] = "return_spa_code";
234
+ AADServerParamKeys["NATIVE_BROKER"] = "nativebroker";
235
+ AADServerParamKeys["LOGOUT_HINT"] = "logout_hint";
229
236
  })(AADServerParamKeys || (AADServerParamKeys = {}));
230
237
  /**
231
238
  * Claims request keys
@@ -481,8 +488,8 @@ var AuthError = /** @class */ (function (_super) {
481
488
  _this = _super.call(this, errorString) || this;
482
489
  Object.setPrototypeOf(_this, AuthError.prototype);
483
490
  _this.errorCode = errorCode || Constants.EMPTY_STRING;
484
- _this.errorMessage = errorMessage || "";
485
- _this.subError = suberror || "";
491
+ _this.errorMessage = errorMessage || Constants.EMPTY_STRING;
492
+ _this.subError = suberror || Constants.EMPTY_STRING;
486
493
  _this.name = "AuthError";
487
494
  return _this;
488
495
  }
@@ -1183,7 +1190,7 @@ var Logger = /** @class */ (function () {
1183
1190
  this.localCallback = loggerOptions.loggerCallback || defaultLoggerCallback;
1184
1191
  this.piiLoggingEnabled = loggerOptions.piiLoggingEnabled || false;
1185
1192
  this.level = typeof (loggerOptions.logLevel) === "number" ? loggerOptions.logLevel : exports.LogLevel.Info;
1186
- this.correlationId = loggerOptions.correlationId || "";
1193
+ this.correlationId = loggerOptions.correlationId || Constants.EMPTY_STRING;
1187
1194
  this.packageName = packageName || Constants.EMPTY_STRING;
1188
1195
  this.packageVersion = packageVersion || Constants.EMPTY_STRING;
1189
1196
  }
@@ -1213,7 +1220,7 @@ var Logger = /** @class */ (function () {
1213
1220
  logHeader = "[" + timestamp + "]";
1214
1221
  }
1215
1222
  var log = logHeader + " : " + this.packageName + "@" + this.packageVersion + " : " + exports.LogLevel[options.logLevel] + " - " + logMessage;
1216
- // debug(`msal:${LogLevel[options.logLevel]}${options.containsPii ? "-Pii": ""}${options.context ? `:${options.context}` : ""}`)(logMessage);
1223
+ // debug(`msal:${LogLevel[options.logLevel]}${options.containsPii ? "-Pii": Constants.EMPTY_STRING}${options.context ? `:${options.context}` : Constants.EMPTY_STRING}`)(logMessage);
1217
1224
  this.executeCallback(options.logLevel, log, options.containsPii || false);
1218
1225
  };
1219
1226
  /**
@@ -1231,7 +1238,7 @@ var Logger = /** @class */ (function () {
1231
1238
  this.logMessage(message, {
1232
1239
  logLevel: exports.LogLevel.Error,
1233
1240
  containsPii: false,
1234
- correlationId: correlationId || ""
1241
+ correlationId: correlationId || Constants.EMPTY_STRING
1235
1242
  });
1236
1243
  };
1237
1244
  /**
@@ -1241,7 +1248,7 @@ var Logger = /** @class */ (function () {
1241
1248
  this.logMessage(message, {
1242
1249
  logLevel: exports.LogLevel.Error,
1243
1250
  containsPii: true,
1244
- correlationId: correlationId || ""
1251
+ correlationId: correlationId || Constants.EMPTY_STRING
1245
1252
  });
1246
1253
  };
1247
1254
  /**
@@ -1251,7 +1258,7 @@ var Logger = /** @class */ (function () {
1251
1258
  this.logMessage(message, {
1252
1259
  logLevel: exports.LogLevel.Warning,
1253
1260
  containsPii: false,
1254
- correlationId: correlationId || ""
1261
+ correlationId: correlationId || Constants.EMPTY_STRING
1255
1262
  });
1256
1263
  };
1257
1264
  /**
@@ -1261,7 +1268,7 @@ var Logger = /** @class */ (function () {
1261
1268
  this.logMessage(message, {
1262
1269
  logLevel: exports.LogLevel.Warning,
1263
1270
  containsPii: true,
1264
- correlationId: correlationId || ""
1271
+ correlationId: correlationId || Constants.EMPTY_STRING
1265
1272
  });
1266
1273
  };
1267
1274
  /**
@@ -1271,7 +1278,7 @@ var Logger = /** @class */ (function () {
1271
1278
  this.logMessage(message, {
1272
1279
  logLevel: exports.LogLevel.Info,
1273
1280
  containsPii: false,
1274
- correlationId: correlationId || ""
1281
+ correlationId: correlationId || Constants.EMPTY_STRING
1275
1282
  });
1276
1283
  };
1277
1284
  /**
@@ -1281,7 +1288,7 @@ var Logger = /** @class */ (function () {
1281
1288
  this.logMessage(message, {
1282
1289
  logLevel: exports.LogLevel.Info,
1283
1290
  containsPii: true,
1284
- correlationId: correlationId || ""
1291
+ correlationId: correlationId || Constants.EMPTY_STRING
1285
1292
  });
1286
1293
  };
1287
1294
  /**
@@ -1291,7 +1298,7 @@ var Logger = /** @class */ (function () {
1291
1298
  this.logMessage(message, {
1292
1299
  logLevel: exports.LogLevel.Verbose,
1293
1300
  containsPii: false,
1294
- correlationId: correlationId || ""
1301
+ correlationId: correlationId || Constants.EMPTY_STRING
1295
1302
  });
1296
1303
  };
1297
1304
  /**
@@ -1301,7 +1308,7 @@ var Logger = /** @class */ (function () {
1301
1308
  this.logMessage(message, {
1302
1309
  logLevel: exports.LogLevel.Verbose,
1303
1310
  containsPii: true,
1304
- correlationId: correlationId || ""
1311
+ correlationId: correlationId || Constants.EMPTY_STRING
1305
1312
  });
1306
1313
  };
1307
1314
  /**
@@ -1311,7 +1318,7 @@ var Logger = /** @class */ (function () {
1311
1318
  this.logMessage(message, {
1312
1319
  logLevel: exports.LogLevel.Trace,
1313
1320
  containsPii: false,
1314
- correlationId: correlationId || ""
1321
+ correlationId: correlationId || Constants.EMPTY_STRING
1315
1322
  });
1316
1323
  };
1317
1324
  /**
@@ -1321,7 +1328,7 @@ var Logger = /** @class */ (function () {
1321
1328
  this.logMessage(message, {
1322
1329
  logLevel: exports.LogLevel.Trace,
1323
1330
  containsPii: true,
1324
- correlationId: correlationId || ""
1331
+ correlationId: correlationId || Constants.EMPTY_STRING
1325
1332
  });
1326
1333
  };
1327
1334
  /**
@@ -1335,7 +1342,27 @@ var Logger = /** @class */ (function () {
1335
1342
 
1336
1343
  /* eslint-disable header/header */
1337
1344
  var name = "@azure/msal-common";
1338
- var version = "6.0.0";
1345
+ var version = "6.3.0-beta.0";
1346
+
1347
+ /*
1348
+ * Copyright (c) Microsoft Corporation. All rights reserved.
1349
+ * Licensed under the MIT License.
1350
+ */
1351
+ exports.AzureCloudInstance = void 0;
1352
+ (function (AzureCloudInstance) {
1353
+ // AzureCloudInstance is not specified.
1354
+ AzureCloudInstance[AzureCloudInstance["None"] = 0] = "None";
1355
+ // Microsoft Azure public cloud
1356
+ AzureCloudInstance["AzurePublic"] = "https://login.microsoftonline.com";
1357
+ // Microsoft PPE
1358
+ AzureCloudInstance["AzurePpe"] = "https://login.windows-ppe.net";
1359
+ // Microsoft Chinese national cloud
1360
+ AzureCloudInstance["AzureChina"] = "https://login.chinacloudapi.cn";
1361
+ // Microsoft German national cloud ("Black Forest")
1362
+ AzureCloudInstance["AzureGermany"] = "https://login.microsoftonline.de";
1363
+ // US Government cloud
1364
+ AzureCloudInstance["AzureUsGovernment"] = "https://login.microsoftonline.us";
1365
+ })(exports.AzureCloudInstance || (exports.AzureCloudInstance = {}));
1339
1366
 
1340
1367
  /*
1341
1368
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1465,7 +1492,7 @@ var CredentialEntity = /** @class */ (function () {
1465
1492
  var credentialId = [
1466
1493
  credentialType,
1467
1494
  clientOrFamilyId,
1468
- realm || "",
1495
+ realm || Constants.EMPTY_STRING,
1469
1496
  ];
1470
1497
  return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
1471
1498
  };
@@ -1473,13 +1500,13 @@ var CredentialEntity = /** @class */ (function () {
1473
1500
  * Generate target key component as per schema: <target>
1474
1501
  */
1475
1502
  CredentialEntity.generateTargetForCacheKey = function (scopes) {
1476
- return (scopes || "").toLowerCase();
1503
+ return (scopes || Constants.EMPTY_STRING).toLowerCase();
1477
1504
  };
1478
1505
  /**
1479
1506
  * Generate requested claims key component as per schema: <requestedClaims>
1480
1507
  */
1481
1508
  CredentialEntity.generateClaimsHashForCacheKey = function (requestedClaimsHash) {
1482
- return (requestedClaimsHash || "").toLowerCase();
1509
+ return (requestedClaimsHash || Constants.EMPTY_STRING).toLowerCase();
1483
1510
  };
1484
1511
  /**
1485
1512
  * Generate scheme key componenet as per schema: <scheme>
@@ -1489,7 +1516,7 @@ var CredentialEntity = /** @class */ (function () {
1489
1516
  * PoP Tokens and SSH certs include scheme in cache key
1490
1517
  * Cast to lowercase to handle "bearer" from ADFS
1491
1518
  */
1492
- return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : "";
1519
+ return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : Constants.EMPTY_STRING;
1493
1520
  };
1494
1521
  return CredentialEntity;
1495
1522
  }());
@@ -1574,6 +1601,10 @@ var ClientConfigurationErrorMessage = {
1574
1601
  code: "untrusted_authority",
1575
1602
  desc: "The provided authority is not a trusted authority. Please include this authority in the knownAuthorities config parameter."
1576
1603
  },
1604
+ invalidAzureCloudInstance: {
1605
+ code: "invalid_azure_cloud_instance",
1606
+ desc: "Invalid AzureCloudInstance provided. Please refer MSAL JS docs: aks.ms/msaljs/azure_cloud_instance for valid values"
1607
+ },
1577
1608
  missingSshJwk: {
1578
1609
  code: "missing_ssh_jwk",
1579
1610
  desc: "Missing sshJwk in SSH certificate request. A stringified JSON Web Key is required when using the SSH authentication scheme."
@@ -1710,7 +1741,13 @@ var ClientConfigurationError = /** @class */ (function (_super) {
1710
1741
  ClientConfigurationError.createUntrustedAuthorityError = function () {
1711
1742
  return new ClientConfigurationError(ClientConfigurationErrorMessage.untrustedAuthority.code, ClientConfigurationErrorMessage.untrustedAuthority.desc);
1712
1743
  };
1713
- /*
1744
+ /**
1745
+ * Throws error when the AzureCloudInstance is set to an invalid value
1746
+ */
1747
+ ClientConfigurationError.createInvalidAzureCloudInstanceError = function () {
1748
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidAzureCloudInstance.code, ClientConfigurationErrorMessage.invalidAzureCloudInstance.desc);
1749
+ };
1750
+ /**
1714
1751
  * Throws an error when the authentication scheme is set to SSH but the SSH public key is omitted from the request
1715
1752
  */
1716
1753
  ClientConfigurationError.createMissingSshJwkError = function () {
@@ -1764,7 +1801,7 @@ var ScopeSet = /** @class */ (function () {
1764
1801
  * @param scopesRequired
1765
1802
  */
1766
1803
  ScopeSet.fromString = function (inputScopeString) {
1767
- var scopeString = inputScopeString || "";
1804
+ var scopeString = inputScopeString || Constants.EMPTY_STRING;
1768
1805
  var inputScopes = scopeString.split(" ");
1769
1806
  return new ScopeSet(inputScopes);
1770
1807
  };
@@ -1908,7 +1945,7 @@ var ScopeSet = /** @class */ (function () {
1908
1945
  var scopeArr = this.asArray();
1909
1946
  return scopeArr.join(" ");
1910
1947
  }
1911
- return "";
1948
+ return Constants.EMPTY_STRING;
1912
1949
  };
1913
1950
  /**
1914
1951
  * Prints scopes into a space-delimited lower-case string (used for caching)
@@ -1993,6 +2030,7 @@ exports.AuthorityType = void 0;
1993
2030
  * lastModificationApp:
1994
2031
  * oboAssertion: access token passed in as part of OBO request
1995
2032
  * idTokenClaims: Object containing claims parsed from ID token
2033
+ * nativeAccountId: Account identifier on the native device
1996
2034
  * }
1997
2035
  */
1998
2036
  var AccountEntity = /** @class */ (function () {
@@ -2046,7 +2084,8 @@ var AccountEntity = /** @class */ (function () {
2046
2084
  username: this.username,
2047
2085
  localAccountId: this.localAccountId,
2048
2086
  name: this.name,
2049
- idTokenClaims: this.idTokenClaims
2087
+ idTokenClaims: this.idTokenClaims,
2088
+ nativeAccountId: this.nativeAccountId
2050
2089
  };
2051
2090
  };
2052
2091
  /**
@@ -2056,8 +2095,8 @@ var AccountEntity = /** @class */ (function () {
2056
2095
  AccountEntity.generateAccountCacheKey = function (accountInterface) {
2057
2096
  var accountKey = [
2058
2097
  accountInterface.homeAccountId,
2059
- accountInterface.environment || "",
2060
- accountInterface.tenantId || "",
2098
+ accountInterface.environment || Constants.EMPTY_STRING,
2099
+ accountInterface.tenantId || Constants.EMPTY_STRING,
2061
2100
  ];
2062
2101
  return accountKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
2063
2102
  };
@@ -2068,29 +2107,30 @@ var AccountEntity = /** @class */ (function () {
2068
2107
  * @param idToken
2069
2108
  * @param policy
2070
2109
  */
2071
- AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment) {
2110
+ AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment, nativeAccountId) {
2072
2111
  var _a, _b, _c, _d, _e, _f;
2073
2112
  var account = new AccountEntity();
2074
2113
  account.authorityType = exports.CacheAccountType.MSSTS_ACCOUNT_TYPE;
2075
2114
  account.clientInfo = clientInfo;
2076
2115
  account.homeAccountId = homeAccountId;
2116
+ account.nativeAccountId = nativeAccountId;
2077
2117
  var env = environment || (authority && authority.getPreferredCache());
2078
2118
  if (!env) {
2079
2119
  throw ClientAuthError.createInvalidCacheEnvironmentError();
2080
2120
  }
2081
2121
  account.environment = env;
2082
2122
  // non AAD scenarios can have empty realm
2083
- account.realm = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.tid) || "";
2123
+ account.realm = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.tid) || Constants.EMPTY_STRING;
2084
2124
  account.oboAssertion = oboAssertion;
2085
2125
  if (idToken) {
2086
2126
  account.idTokenClaims = idToken.claims;
2087
2127
  // How do you account for MSA CID here?
2088
- account.localAccountId = ((_b = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _b === void 0 ? void 0 : _b.oid) || ((_c = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _c === void 0 ? void 0 : _c.sub) || "";
2128
+ account.localAccountId = ((_b = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _b === void 0 ? void 0 : _b.oid) || ((_c = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _c === void 0 ? void 0 : _c.sub) || Constants.EMPTY_STRING;
2089
2129
  /*
2090
2130
  * In B2C scenarios the emails claim is used instead of preferred_username and it is an array. In most cases it will contain a single email.
2091
2131
  * This field should not be relied upon if a custom policy is configured to return more than 1 email.
2092
2132
  */
2093
- account.username = ((_d = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _d === void 0 ? void 0 : _d.preferred_username) || (((_e = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _e === void 0 ? void 0 : _e.emails) ? idToken.claims.emails[0] : "");
2133
+ account.username = ((_d = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _d === void 0 ? void 0 : _d.preferred_username) || (((_e = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _e === void 0 ? void 0 : _e.emails) ? idToken.claims.emails[0] : Constants.EMPTY_STRING);
2094
2134
  account.name = (_f = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _f === void 0 ? void 0 : _f.name;
2095
2135
  }
2096
2136
  account.cloudGraphHostName = cloudGraphHostName;
@@ -2108,7 +2148,7 @@ var AccountEntity = /** @class */ (function () {
2108
2148
  account.authorityType = (authority && authority.authorityType === exports.AuthorityType.Adfs) ? exports.CacheAccountType.ADFS_ACCOUNT_TYPE : exports.CacheAccountType.GENERIC_ACCOUNT_TYPE;
2109
2149
  account.homeAccountId = homeAccountId;
2110
2150
  // non AAD scenarios can have empty realm
2111
- account.realm = "";
2151
+ account.realm = Constants.EMPTY_STRING;
2112
2152
  account.oboAssertion = oboAssertion;
2113
2153
  var env = environment || authority && authority.getPreferredCache();
2114
2154
  if (!env) {
@@ -2116,10 +2156,10 @@ var AccountEntity = /** @class */ (function () {
2116
2156
  }
2117
2157
  if (idToken) {
2118
2158
  // How do you account for MSA CID here?
2119
- account.localAccountId = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.oid) || ((_b = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _b === void 0 ? void 0 : _b.sub) || "";
2159
+ account.localAccountId = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.oid) || ((_b = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _b === void 0 ? void 0 : _b.sub) || Constants.EMPTY_STRING;
2120
2160
  // upn claim for most ADFS scenarios
2121
- account.username = ((_c = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _c === void 0 ? void 0 : _c.upn) || "";
2122
- account.name = ((_d = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _d === void 0 ? void 0 : _d.name) || "";
2161
+ account.username = ((_c = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _c === void 0 ? void 0 : _c.upn) || Constants.EMPTY_STRING;
2162
+ account.name = ((_d = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _d === void 0 ? void 0 : _d.name) || Constants.EMPTY_STRING;
2123
2163
  account.idTokenClaims = idToken === null || idToken === void 0 ? void 0 : idToken.claims;
2124
2164
  }
2125
2165
  account.environment = env;
@@ -2195,6 +2235,7 @@ var AccountEntity = /** @class */ (function () {
2195
2235
  (accountA.username === accountB.username) &&
2196
2236
  (accountA.tenantId === accountB.tenantId) &&
2197
2237
  (accountA.environment === accountB.environment) &&
2238
+ (accountA.nativeAccountId === accountB.nativeAccountId) &&
2198
2239
  claimsMatch;
2199
2240
  };
2200
2241
  return AccountEntity;
@@ -2356,7 +2397,7 @@ var CacheManager = /** @class */ (function () {
2356
2397
  * @param realm
2357
2398
  */
2358
2399
  CacheManager.prototype.getAccountsFilteredBy = function (accountFilter) {
2359
- return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : "", accountFilter ? accountFilter.environment : "", accountFilter ? accountFilter.realm : "");
2400
+ return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : Constants.EMPTY_STRING, accountFilter ? accountFilter.environment : Constants.EMPTY_STRING, accountFilter ? accountFilter.realm : Constants.EMPTY_STRING);
2360
2401
  };
2361
2402
  /**
2362
2403
  * retrieve accounts matching all provided filters; if no filter is set, get all accounts
@@ -2602,7 +2643,7 @@ var CacheManager = /** @class */ (function () {
2602
2643
  });
2603
2644
  };
2604
2645
  /**
2605
- * returns a boolean if the given account is removed
2646
+ * Removes credentials associated with the provided account
2606
2647
  * @param account
2607
2648
  */
2608
2649
  CacheManager.prototype.removeAccountContext = function (account) {
@@ -3084,7 +3125,8 @@ var DefaultStorageClass = /** @class */ (function (_super) {
3084
3125
  var DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;
3085
3126
  var DEFAULT_SYSTEM_OPTIONS = {
3086
3127
  tokenRenewalOffsetSeconds: DEFAULT_TOKEN_RENEWAL_OFFSET_SEC,
3087
- preventCorsPreflight: false
3128
+ preventCorsPreflight: false,
3129
+ proxyUrl: Constants.EMPTY_STRING
3088
3130
  };
3089
3131
  var DEFAULT_LOGGER_IMPLEMENTATION = {
3090
3132
  loggerCallback: function () {
@@ -3092,7 +3134,7 @@ var DEFAULT_LOGGER_IMPLEMENTATION = {
3092
3134
  },
3093
3135
  piiLoggingEnabled: false,
3094
3136
  logLevel: exports.LogLevel.Info,
3095
- correlationId: ""
3137
+ correlationId: Constants.EMPTY_STRING
3096
3138
  };
3097
3139
  var DEFAULT_NETWORK_IMPLEMENTATION = {
3098
3140
  sendGetRequestAsync: function () {
@@ -3117,13 +3159,23 @@ var DEFAULT_NETWORK_IMPLEMENTATION = {
3117
3159
  var DEFAULT_LIBRARY_INFO = {
3118
3160
  sku: Constants.SKU,
3119
3161
  version: version,
3120
- cpu: "",
3121
- os: ""
3162
+ cpu: Constants.EMPTY_STRING,
3163
+ os: Constants.EMPTY_STRING
3122
3164
  };
3123
3165
  var DEFAULT_CLIENT_CREDENTIALS = {
3124
- clientSecret: "",
3166
+ clientSecret: Constants.EMPTY_STRING,
3125
3167
  clientAssertion: undefined
3126
3168
  };
3169
+ var DEFAULT_AZURE_CLOUD_OPTIONS = {
3170
+ azureCloudInstance: exports.AzureCloudInstance.None,
3171
+ tenant: "" + Constants.DEFAULT_COMMON_TENANT
3172
+ };
3173
+ var DEFAULT_TELEMETRY_OPTIONS = {
3174
+ application: {
3175
+ appName: "",
3176
+ appVersion: ""
3177
+ }
3178
+ };
3127
3179
  /**
3128
3180
  * Function that sets the default options when not explicitly configured from app developer
3129
3181
  *
@@ -3132,7 +3184,7 @@ var DEFAULT_CLIENT_CREDENTIALS = {
3132
3184
  * @returns Configuration
3133
3185
  */
3134
3186
  function buildClientConfiguration(_a) {
3135
- var userAuthOptions = _a.authOptions, userSystemOptions = _a.systemOptions, userLoggerOption = _a.loggerOptions, storageImplementation = _a.storageInterface, networkImplementation = _a.networkInterface, cryptoImplementation = _a.cryptoInterface, clientCredentials = _a.clientCredentials, libraryInfo = _a.libraryInfo, serverTelemetryManager = _a.serverTelemetryManager, persistencePlugin = _a.persistencePlugin, serializableCache = _a.serializableCache;
3187
+ var userAuthOptions = _a.authOptions, userSystemOptions = _a.systemOptions, userLoggerOption = _a.loggerOptions, storageImplementation = _a.storageInterface, networkImplementation = _a.networkInterface, cryptoImplementation = _a.cryptoInterface, clientCredentials = _a.clientCredentials, libraryInfo = _a.libraryInfo, telemetry = _a.telemetry, serverTelemetryManager = _a.serverTelemetryManager, persistencePlugin = _a.persistencePlugin, serializableCache = _a.serializableCache;
3136
3188
  var loggerOptions = __assign(__assign({}, DEFAULT_LOGGER_IMPLEMENTATION), userLoggerOption);
3137
3189
  return {
3138
3190
  authOptions: buildAuthOptions(userAuthOptions),
@@ -3143,6 +3195,7 @@ function buildClientConfiguration(_a) {
3143
3195
  cryptoInterface: cryptoImplementation || DEFAULT_CRYPTO_IMPLEMENTATION,
3144
3196
  clientCredentials: clientCredentials || DEFAULT_CLIENT_CREDENTIALS,
3145
3197
  libraryInfo: __assign(__assign({}, DEFAULT_LIBRARY_INFO), libraryInfo),
3198
+ telemetry: __assign(__assign({}, DEFAULT_TELEMETRY_OPTIONS), telemetry),
3146
3199
  serverTelemetryManager: serverTelemetryManager || null,
3147
3200
  persistencePlugin: persistencePlugin || null,
3148
3201
  serializableCache: serializableCache || null
@@ -3153,7 +3206,7 @@ function buildClientConfiguration(_a) {
3153
3206
  * @param authOptions
3154
3207
  */
3155
3208
  function buildAuthOptions(authOptions) {
3156
- return __assign({ clientCapabilities: [] }, authOptions);
3209
+ return __assign({ clientCapabilities: [], azureCloudOptions: DEFAULT_AZURE_CLOUD_OPTIONS }, authOptions);
3157
3210
  }
3158
3211
 
3159
3212
  /*
@@ -3387,7 +3440,7 @@ var BaseClient = /** @class */ (function () {
3387
3440
  var response;
3388
3441
  return __generator(this, function (_a) {
3389
3442
  switch (_a.label) {
3390
- case 0: return [4 /*yield*/, this.networkManager.sendPostRequest(thumbprint, tokenEndpoint, { body: queryString, headers: headers })];
3443
+ case 0: return [4 /*yield*/, this.networkManager.sendPostRequest(thumbprint, tokenEndpoint, { body: queryString, headers: headers, proxyUrl: this.config.systemOptions.proxyUrl })];
3391
3444
  case 1:
3392
3445
  response = _a.sent();
3393
3446
  if (this.config.serverTelemetryManager && response.status < 500 && response.status !== 429) {
@@ -3510,6 +3563,12 @@ var RequestParameterBuilder = /** @class */ (function () {
3510
3563
  RequestParameterBuilder.prototype.addResponseTypeCode = function () {
3511
3564
  this.parameters.set(AADServerParamKeys.RESPONSE_TYPE, encodeURIComponent(Constants.CODE_RESPONSE_TYPE));
3512
3565
  };
3566
+ /**
3567
+ * add response_type = token id_token
3568
+ */
3569
+ RequestParameterBuilder.prototype.addResponseTypeForTokenAndIdToken = function () {
3570
+ this.parameters.set(AADServerParamKeys.RESPONSE_TYPE, encodeURIComponent(Constants.TOKEN_RESPONSE_TYPE + " " + Constants.ID_TOKEN_RESPONSE_TYPE));
3571
+ };
3513
3572
  /**
3514
3573
  * add response_mode. defaults to query.
3515
3574
  * @param responseMode
@@ -3517,6 +3576,12 @@ var RequestParameterBuilder = /** @class */ (function () {
3517
3576
  RequestParameterBuilder.prototype.addResponseMode = function (responseMode) {
3518
3577
  this.parameters.set(AADServerParamKeys.RESPONSE_MODE, encodeURIComponent((responseMode) ? responseMode : exports.ResponseMode.QUERY));
3519
3578
  };
3579
+ /**
3580
+ * Add flag to indicate STS should attempt to use WAM if available
3581
+ */
3582
+ RequestParameterBuilder.prototype.addNativeBroker = function () {
3583
+ this.parameters.set(AADServerParamKeys.NATIVE_BROKER, encodeURIComponent("1"));
3584
+ };
3520
3585
  /**
3521
3586
  * add scopes. set addOidcScopes to false to prevent default scopes in non-user scenarios
3522
3587
  * @param scopeSet
@@ -3617,8 +3682,24 @@ var RequestParameterBuilder = /** @class */ (function () {
3617
3682
  // Telemetry Info
3618
3683
  this.parameters.set(AADServerParamKeys.X_CLIENT_SKU, libraryInfo.sku);
3619
3684
  this.parameters.set(AADServerParamKeys.X_CLIENT_VER, libraryInfo.version);
3620
- this.parameters.set(AADServerParamKeys.X_CLIENT_OS, libraryInfo.os);
3621
- this.parameters.set(AADServerParamKeys.X_CLIENT_CPU, libraryInfo.cpu);
3685
+ if (libraryInfo.os) {
3686
+ this.parameters.set(AADServerParamKeys.X_CLIENT_OS, libraryInfo.os);
3687
+ }
3688
+ if (libraryInfo.cpu) {
3689
+ this.parameters.set(AADServerParamKeys.X_CLIENT_CPU, libraryInfo.cpu);
3690
+ }
3691
+ };
3692
+ /**
3693
+ * Add client telemetry parameters
3694
+ * @param appTelemetry
3695
+ */
3696
+ RequestParameterBuilder.prototype.addApplicationTelemetry = function (appTelemetry) {
3697
+ if (appTelemetry === null || appTelemetry === void 0 ? void 0 : appTelemetry.appName) {
3698
+ this.parameters.set(AADServerParamKeys.X_APP_NAME, appTelemetry.appName);
3699
+ }
3700
+ if (appTelemetry === null || appTelemetry === void 0 ? void 0 : appTelemetry.appVersion) {
3701
+ this.parameters.set(AADServerParamKeys.X_APP_VER, appTelemetry.appVersion);
3702
+ }
3622
3703
  };
3623
3704
  /**
3624
3705
  * add prompt
@@ -3821,6 +3902,12 @@ var RequestParameterBuilder = /** @class */ (function () {
3821
3902
  RequestParameterBuilder.prototype.addThrottling = function () {
3822
3903
  this.parameters.set(AADServerParamKeys.X_MS_LIB_CAPABILITY, ThrottlingConstants.X_MS_LIB_CAPABILITY_VALUE);
3823
3904
  };
3905
+ /**
3906
+ * Adds logout_hint parameter for "silent" logout which prevent server account picker
3907
+ */
3908
+ RequestParameterBuilder.prototype.addLogoutHint = function (logoutHint) {
3909
+ this.parameters.set(AADServerParamKeys.LOGOUT_HINT, encodeURIComponent(logoutHint));
3910
+ };
3824
3911
  /**
3825
3912
  * Utility to create a URL from the params map
3826
3913
  */
@@ -4254,11 +4341,11 @@ var ProtocolUtils = /** @class */ (function () {
4254
4341
  // Split the state between library state and user passed state and decode them separately
4255
4342
  var splitState = state.split(Constants.RESOURCE_DELIM);
4256
4343
  var libraryState = splitState[0];
4257
- var userState = splitState.length > 1 ? splitState.slice(1).join(Constants.RESOURCE_DELIM) : "";
4344
+ var userState = splitState.length > 1 ? splitState.slice(1).join(Constants.RESOURCE_DELIM) : Constants.EMPTY_STRING;
4258
4345
  var libraryStateString = cryptoObj.base64Decode(libraryState);
4259
4346
  var libraryStateObj = JSON.parse(libraryStateString);
4260
4347
  return {
4261
- userRequestState: !StringUtils.isEmpty(userState) ? userState : "",
4348
+ userRequestState: !StringUtils.isEmpty(userState) ? userState : Constants.EMPTY_STRING,
4262
4349
  libraryState: libraryStateObj
4263
4350
  };
4264
4351
  }
@@ -4428,7 +4515,7 @@ var UrlString = /** @class */ (function () {
4428
4515
  else if (hashIndex1 > -1) {
4429
4516
  return hashString.substring(hashIndex1 + 1);
4430
4517
  }
4431
- return "";
4518
+ return Constants.EMPTY_STRING;
4432
4519
  };
4433
4520
  UrlString.constructAuthorityUriFromObject = function (urlObject) {
4434
4521
  return new UrlString(urlObject.Protocol + "//" + urlObject.HostNameAndPort + "/" + urlObject.PathSegments.join("/"));
@@ -4481,6 +4568,11 @@ var PopTokenGenerator = /** @class */ (function () {
4481
4568
  function PopTokenGenerator(cryptoUtils) {
4482
4569
  this.cryptoUtils = cryptoUtils;
4483
4570
  }
4571
+ /**
4572
+ * Generates the req_cnf validated at the RP in the POP protocol for SHR parameters
4573
+ * @param request
4574
+ * @returns
4575
+ */
4484
4576
  PopTokenGenerator.prototype.generateCnf = function (request) {
4485
4577
  return __awaiter(this, void 0, void 0, function () {
4486
4578
  var reqCnf;
@@ -4494,6 +4586,23 @@ var PopTokenGenerator = /** @class */ (function () {
4494
4586
  });
4495
4587
  });
4496
4588
  };
4589
+ /**
4590
+ * Generates the hash of the req_cnf
4591
+ * @param cnf
4592
+ * @returns
4593
+ */
4594
+ PopTokenGenerator.prototype.generateCnfHash = function (cnf) {
4595
+ return __awaiter(this, void 0, void 0, function () {
4596
+ return __generator(this, function (_a) {
4597
+ return [2 /*return*/, this.cryptoUtils.hashString(cnf)];
4598
+ });
4599
+ });
4600
+ };
4601
+ /**
4602
+ * Generates key_id for a SHR token request
4603
+ * @param request
4604
+ * @returns
4605
+ */
4497
4606
  PopTokenGenerator.prototype.generateKid = function (request) {
4498
4607
  return __awaiter(this, void 0, void 0, function () {
4499
4608
  var kidThumbprint;
@@ -4510,6 +4619,12 @@ var PopTokenGenerator = /** @class */ (function () {
4510
4619
  });
4511
4620
  });
4512
4621
  };
4622
+ /**
4623
+ * Signs the POP access_token with the local generated key-pair
4624
+ * @param accessToken
4625
+ * @param request
4626
+ * @returns
4627
+ */
4513
4628
  PopTokenGenerator.prototype.signPopToken = function (accessToken, request) {
4514
4629
  var _a;
4515
4630
  return __awaiter(this, void 0, void 0, function () {
@@ -4523,6 +4638,14 @@ var PopTokenGenerator = /** @class */ (function () {
4523
4638
  });
4524
4639
  });
4525
4640
  };
4641
+ /**
4642
+ * Utility function to generate the signed JWT for an access_token
4643
+ * @param payload
4644
+ * @param kid
4645
+ * @param request
4646
+ * @param claims
4647
+ * @returns
4648
+ */
4526
4649
  PopTokenGenerator.prototype.signPayload = function (payload, kid, request, claims) {
4527
4650
  return __awaiter(this, void 0, void 0, function () {
4528
4651
  var resourceRequestMethod, resourceRequestUri, shrClaims, shrNonce, resourceUrlString, resourceUrlComponents;
@@ -4532,7 +4655,7 @@ var PopTokenGenerator = /** @class */ (function () {
4532
4655
  resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims, shrNonce = request.shrNonce;
4533
4656
  resourceUrlString = (resourceRequestUri) ? new UrlString(resourceRequestUri) : undefined;
4534
4657
  resourceUrlComponents = resourceUrlString === null || resourceUrlString === void 0 ? void 0 : resourceUrlString.getUrlComponents();
4535
- return [4 /*yield*/, this.cryptoUtils.signJwt(__assign({ at: payload, ts: TimeUtils.nowSeconds(), m: resourceRequestMethod === null || resourceRequestMethod === void 0 ? void 0 : resourceRequestMethod.toUpperCase(), u: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.HostNameAndPort, nonce: shrNonce || this.cryptoUtils.createNewGuid(), p: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.AbsolutePath, q: (resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.QueryString) ? [[], resourceUrlComponents.QueryString] : undefined, client_claims: shrClaims || undefined }, claims), kid)];
4658
+ return [4 /*yield*/, this.cryptoUtils.signJwt(__assign({ at: payload, ts: TimeUtils.nowSeconds(), m: resourceRequestMethod === null || resourceRequestMethod === void 0 ? void 0 : resourceRequestMethod.toUpperCase(), u: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.HostNameAndPort, nonce: shrNonce || this.cryptoUtils.createNewGuid(), p: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.AbsolutePath, q: (resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.QueryString) ? [[], resourceUrlComponents.QueryString] : undefined, client_claims: shrClaims || undefined }, claims), kid, request.correlationId)];
4536
4659
  case 1: return [2 /*return*/, _a.sent()];
4537
4660
  }
4538
4661
  });
@@ -4823,8 +4946,8 @@ var ResponseHandler = /** @class */ (function () {
4823
4946
  */
4824
4947
  ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, oboAssertion, authCodePayload) {
4825
4948
  var authorityType = authority.authorityType;
4826
- var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : "";
4827
- var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : "";
4949
+ var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : Constants.EMPTY_STRING;
4950
+ var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : Constants.EMPTY_STRING;
4828
4951
  // ADFS does not require client_info in the response
4829
4952
  if (authorityType === exports.AuthorityType.Adfs) {
4830
4953
  this.logger.verbose("Authority type is ADFS, creating ADFS account");
@@ -4855,7 +4978,7 @@ var ResponseHandler = /** @class */ (function () {
4855
4978
  return __generator(this, function (_d) {
4856
4979
  switch (_d.label) {
4857
4980
  case 0:
4858
- accessToken = "";
4981
+ accessToken = Constants.EMPTY_STRING;
4859
4982
  responseScopes = [];
4860
4983
  expiresOn = null;
4861
4984
  familyId = Constants.EMPTY_STRING;
@@ -4898,7 +5021,8 @@ var ResponseHandler = /** @class */ (function () {
4898
5021
  state: requestState ? requestState.userRequestState : Constants.EMPTY_STRING,
4899
5022
  cloudGraphHostName: ((_b = cacheRecord.account) === null || _b === void 0 ? void 0 : _b.cloudGraphHostName) || Constants.EMPTY_STRING,
4900
5023
  msGraphHost: ((_c = cacheRecord.account) === null || _c === void 0 ? void 0 : _c.msGraphHost) || Constants.EMPTY_STRING,
4901
- code: code
5024
+ code: code,
5025
+ fromNativeBroker: false
4902
5026
  }];
4903
5027
  }
4904
5028
  });
@@ -4936,8 +5060,12 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
4936
5060
  return __awaiter(this, void 0, void 0, function () {
4937
5061
  var queryString;
4938
5062
  return __generator(this, function (_a) {
4939
- queryString = this.createAuthCodeUrlQueryString(request);
4940
- return [2 /*return*/, UrlString.appendQueryString(this.authority.authorizationEndpoint, queryString)];
5063
+ switch (_a.label) {
5064
+ case 0: return [4 /*yield*/, this.createAuthCodeUrlQueryString(request)];
5065
+ case 1:
5066
+ queryString = _a.sent();
5067
+ return [2 /*return*/, UrlString.appendQueryString(this.authority.authorizationEndpoint, queryString)];
5068
+ }
4941
5069
  });
4942
5070
  });
4943
5071
  };
@@ -5093,6 +5221,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5093
5221
  parameterBuilder.addAuthorizationCode(request.code);
5094
5222
  // Add library metadata
5095
5223
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5224
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5096
5225
  parameterBuilder.addThrottling();
5097
5226
  if (this.serverTelemetryManager) {
5098
5227
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -5186,95 +5315,116 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5186
5315
  * @param request
5187
5316
  */
5188
5317
  AuthorizationCodeClient.prototype.createAuthCodeUrlQueryString = function (request) {
5189
- var parameterBuilder = new RequestParameterBuilder();
5190
- parameterBuilder.addClientId(this.config.authOptions.clientId);
5191
- var requestScopes = __spreadArrays(request.scopes || [], request.extraScopesToConsent || []);
5192
- parameterBuilder.addScopes(requestScopes);
5193
- // validate the redirectUri (to be a non null value)
5194
- parameterBuilder.addRedirectUri(request.redirectUri);
5195
- // generate the correlationId if not set by the user and add
5196
- var correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
5197
- parameterBuilder.addCorrelationId(correlationId);
5198
- // add response_mode. If not passed in it defaults to query.
5199
- parameterBuilder.addResponseMode(request.responseMode);
5200
- // add response_type = code
5201
- parameterBuilder.addResponseTypeCode();
5202
- // add library info parameters
5203
- parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5204
- // add client_info=1
5205
- parameterBuilder.addClientInfo();
5206
- if (request.codeChallenge && request.codeChallengeMethod) {
5207
- parameterBuilder.addCodeChallengeParams(request.codeChallenge, request.codeChallengeMethod);
5208
- }
5209
- if (request.prompt) {
5210
- parameterBuilder.addPrompt(request.prompt);
5211
- }
5212
- if (request.domainHint) {
5213
- parameterBuilder.addDomainHint(request.domainHint);
5214
- }
5215
- // Add sid or loginHint with preference for sid -> loginHint -> username of AccountInfo object
5216
- if (request.prompt !== PromptValue.SELECT_ACCOUNT) {
5217
- // AAD will throw if prompt=select_account is passed with an account hint
5218
- if (request.sid && request.prompt === PromptValue.NONE) {
5219
- // SessionID is only used in silent calls
5220
- this.logger.verbose("createAuthCodeUrlQueryString: Prompt is none, adding sid from request");
5221
- parameterBuilder.addSid(request.sid);
5222
- }
5223
- else if (request.account) {
5224
- var accountSid = this.extractAccountSid(request.account);
5225
- // If account and loginHint are provided, we will check account first for sid before adding loginHint
5226
- if (accountSid && request.prompt === PromptValue.NONE) {
5227
- // SessionId is only used in silent calls
5228
- this.logger.verbose("createAuthCodeUrlQueryString: Prompt is none, adding sid from account");
5229
- parameterBuilder.addSid(accountSid);
5230
- try {
5231
- var clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
5232
- parameterBuilder.addCcsOid(clientInfo);
5233
- }
5234
- catch (e) {
5235
- this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
5236
- }
5237
- }
5238
- else if (request.loginHint) {
5239
- this.logger.verbose("createAuthCodeUrlQueryString: Adding login_hint from request");
5240
- parameterBuilder.addLoginHint(request.loginHint);
5241
- parameterBuilder.addCcsUpn(request.loginHint);
5242
- }
5243
- else if (request.account.username) {
5244
- // Fallback to account username if provided
5245
- this.logger.verbose("createAuthCodeUrlQueryString: Adding login_hint from account");
5246
- parameterBuilder.addLoginHint(request.account.username);
5247
- try {
5248
- var clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
5249
- parameterBuilder.addCcsOid(clientInfo);
5250
- }
5251
- catch (e) {
5252
- this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
5253
- }
5318
+ return __awaiter(this, void 0, void 0, function () {
5319
+ var parameterBuilder, requestScopes, correlationId, accountSid, clientInfo, clientInfo, popTokenGenerator, cnf, cnfHash;
5320
+ return __generator(this, function (_a) {
5321
+ switch (_a.label) {
5322
+ case 0:
5323
+ parameterBuilder = new RequestParameterBuilder();
5324
+ parameterBuilder.addClientId(this.config.authOptions.clientId);
5325
+ requestScopes = __spreadArrays(request.scopes || [], request.extraScopesToConsent || []);
5326
+ parameterBuilder.addScopes(requestScopes);
5327
+ // validate the redirectUri (to be a non null value)
5328
+ parameterBuilder.addRedirectUri(request.redirectUri);
5329
+ correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
5330
+ parameterBuilder.addCorrelationId(correlationId);
5331
+ // add response_mode. If not passed in it defaults to query.
5332
+ parameterBuilder.addResponseMode(request.responseMode);
5333
+ // add response_type = code
5334
+ parameterBuilder.addResponseTypeCode();
5335
+ // add library info parameters
5336
+ parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5337
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5338
+ // add client_info=1
5339
+ parameterBuilder.addClientInfo();
5340
+ if (request.codeChallenge && request.codeChallengeMethod) {
5341
+ parameterBuilder.addCodeChallengeParams(request.codeChallenge, request.codeChallengeMethod);
5342
+ }
5343
+ if (request.prompt) {
5344
+ parameterBuilder.addPrompt(request.prompt);
5345
+ }
5346
+ if (request.domainHint) {
5347
+ parameterBuilder.addDomainHint(request.domainHint);
5348
+ }
5349
+ // Add sid or loginHint with preference for sid -> loginHint -> username of AccountInfo object
5350
+ if (request.prompt !== PromptValue.SELECT_ACCOUNT) {
5351
+ // AAD will throw if prompt=select_account is passed with an account hint
5352
+ if (request.sid && request.prompt === PromptValue.NONE) {
5353
+ // SessionID is only used in silent calls
5354
+ this.logger.verbose("createAuthCodeUrlQueryString: Prompt is none, adding sid from request");
5355
+ parameterBuilder.addSid(request.sid);
5356
+ }
5357
+ else if (request.account) {
5358
+ accountSid = this.extractAccountSid(request.account);
5359
+ // If account and loginHint are provided, we will check account first for sid before adding loginHint
5360
+ if (accountSid && request.prompt === PromptValue.NONE) {
5361
+ // SessionId is only used in silent calls
5362
+ this.logger.verbose("createAuthCodeUrlQueryString: Prompt is none, adding sid from account");
5363
+ parameterBuilder.addSid(accountSid);
5364
+ try {
5365
+ clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
5366
+ parameterBuilder.addCcsOid(clientInfo);
5367
+ }
5368
+ catch (e) {
5369
+ this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
5370
+ }
5371
+ }
5372
+ else if (request.loginHint) {
5373
+ this.logger.verbose("createAuthCodeUrlQueryString: Adding login_hint from request");
5374
+ parameterBuilder.addLoginHint(request.loginHint);
5375
+ parameterBuilder.addCcsUpn(request.loginHint);
5376
+ }
5377
+ else if (request.account.username) {
5378
+ // Fallback to account username if provided
5379
+ this.logger.verbose("createAuthCodeUrlQueryString: Adding login_hint from account");
5380
+ parameterBuilder.addLoginHint(request.account.username);
5381
+ try {
5382
+ clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
5383
+ parameterBuilder.addCcsOid(clientInfo);
5384
+ }
5385
+ catch (e) {
5386
+ this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
5387
+ }
5388
+ }
5389
+ }
5390
+ else if (request.loginHint) {
5391
+ this.logger.verbose("createAuthCodeUrlQueryString: No account, adding login_hint from request");
5392
+ parameterBuilder.addLoginHint(request.loginHint);
5393
+ parameterBuilder.addCcsUpn(request.loginHint);
5394
+ }
5395
+ }
5396
+ else {
5397
+ this.logger.verbose("createAuthCodeUrlQueryString: Prompt is select_account, ignoring account hints");
5398
+ }
5399
+ if (request.nonce) {
5400
+ parameterBuilder.addNonce(request.nonce);
5401
+ }
5402
+ if (request.state) {
5403
+ parameterBuilder.addState(request.state);
5404
+ }
5405
+ if (!StringUtils.isEmpty(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
5406
+ parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
5407
+ }
5408
+ if (request.extraQueryParameters) {
5409
+ parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
5410
+ }
5411
+ if (!request.nativeBroker) return [3 /*break*/, 3];
5412
+ // signal ests that this is a WAM call
5413
+ parameterBuilder.addNativeBroker();
5414
+ if (!(request.authenticationScheme === exports.AuthenticationScheme.POP)) return [3 /*break*/, 3];
5415
+ popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5416
+ return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5417
+ case 1:
5418
+ cnf = _a.sent();
5419
+ return [4 /*yield*/, popTokenGenerator.generateCnfHash(cnf)];
5420
+ case 2:
5421
+ cnfHash = _a.sent();
5422
+ parameterBuilder.addPopToken(cnfHash);
5423
+ _a.label = 3;
5424
+ case 3: return [2 /*return*/, parameterBuilder.createQueryString()];
5254
5425
  }
5255
- }
5256
- else if (request.loginHint) {
5257
- this.logger.verbose("createAuthCodeUrlQueryString: No account, adding login_hint from request");
5258
- parameterBuilder.addLoginHint(request.loginHint);
5259
- parameterBuilder.addCcsUpn(request.loginHint);
5260
- }
5261
- }
5262
- else {
5263
- this.logger.verbose("createAuthCodeUrlQueryString: Prompt is select_account, ignoring account hints");
5264
- }
5265
- if (request.nonce) {
5266
- parameterBuilder.addNonce(request.nonce);
5267
- }
5268
- if (request.state) {
5269
- parameterBuilder.addState(request.state);
5270
- }
5271
- if (!StringUtils.isEmpty(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
5272
- parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
5273
- }
5274
- if (request.extraQueryParameters) {
5275
- parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
5276
- }
5277
- return parameterBuilder.createQueryString();
5426
+ });
5427
+ });
5278
5428
  };
5279
5429
  /**
5280
5430
  * This API validates the `EndSessionRequest` and creates a URL
@@ -5294,6 +5444,9 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5294
5444
  if (request.state) {
5295
5445
  parameterBuilder.addState(request.state);
5296
5446
  }
5447
+ if (request.logoutHint) {
5448
+ parameterBuilder.addLogoutHint(request.logoutHint);
5449
+ }
5297
5450
  if (request.extraQueryParameters) {
5298
5451
  parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
5299
5452
  }
@@ -5390,7 +5543,8 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5390
5543
  switch (_b.label) {
5391
5544
  case 0: return [4 /*yield*/, this.networkManager.sendPostRequest(thumbprint, deviceCodeEndpoint, {
5392
5545
  body: queryString,
5393
- headers: headers
5546
+ headers: headers,
5547
+ proxyUrl: this.config.systemOptions.proxyUrl
5394
5548
  })];
5395
5549
  case 1:
5396
5550
  _a = (_b.sent()).body, userCode = _a.user_code, deviceCode = _a.device_code, verificationUri = _a.verification_uri, expiresIn = _a.expires_in, interval = _a.interval, message = _a.message;
@@ -5512,6 +5666,7 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5512
5666
  requestParameters.addCorrelationId(correlationId);
5513
5667
  requestParameters.addClientInfo();
5514
5668
  requestParameters.addLibraryInfo(this.config.libraryInfo);
5669
+ requestParameters.addApplicationTelemetry(this.config.telemetry.application);
5515
5670
  requestParameters.addThrottling();
5516
5671
  if (this.serverTelemetryManager) {
5517
5672
  requestParameters.addServerTelemetry(this.serverTelemetryManager);
@@ -5673,6 +5828,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5673
5828
  parameterBuilder.addGrantType(GrantType.REFRESH_TOKEN_GRANT);
5674
5829
  parameterBuilder.addClientInfo();
5675
5830
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5831
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5676
5832
  parameterBuilder.addThrottling();
5677
5833
  if (this.serverTelemetryManager) {
5678
5834
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -5807,7 +5963,7 @@ var ClientCredentialClient = /** @class */ (function (_super) {
5807
5963
  */
5808
5964
  ClientCredentialClient.prototype.readAccessTokenFromCache = function () {
5809
5965
  var accessTokenFilter = {
5810
- homeAccountId: "",
5966
+ homeAccountId: Constants.EMPTY_STRING,
5811
5967
  environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
5812
5968
  credentialType: exports.CredentialType.ACCESS_TOKEN,
5813
5969
  clientId: this.config.authOptions.clientId,
@@ -5872,6 +6028,7 @@ var ClientCredentialClient = /** @class */ (function (_super) {
5872
6028
  parameterBuilder.addScopes(request.scopes, false);
5873
6029
  parameterBuilder.addGrantType(GrantType.CLIENT_CREDENTIALS_GRANT);
5874
6030
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6031
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5875
6032
  parameterBuilder.addThrottling();
5876
6033
  if (this.serverTelemetryManager) {
5877
6034
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -5959,7 +6116,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
5959
6116
  environment: cachedIdToken.environment,
5960
6117
  tenantId: cachedIdToken.realm,
5961
6118
  username: Constants.EMPTY_STRING,
5962
- localAccountId: localAccountId || ""
6119
+ localAccountId: localAccountId || Constants.EMPTY_STRING
5963
6120
  };
5964
6121
  cachedAccount = this.readAccountFromCache(accountInfo);
5965
6122
  }
@@ -6074,6 +6231,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6074
6231
  parameterBuilder.addGrantType(GrantType.JWT_BEARER);
6075
6232
  parameterBuilder.addClientInfo();
6076
6233
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6234
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
6077
6235
  parameterBuilder.addThrottling();
6078
6236
  if (this.serverTelemetryManager) {
6079
6237
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -6286,9 +6444,11 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6286
6444
  parameterBuilder.addUsername(request.username);
6287
6445
  parameterBuilder.addPassword(request.password);
6288
6446
  parameterBuilder.addScopes(request.scopes);
6447
+ parameterBuilder.addResponseTypeForTokenAndIdToken();
6289
6448
  parameterBuilder.addGrantType(GrantType.RESOURCE_OWNER_PASSWORD_GRANT);
6290
6449
  parameterBuilder.addClientInfo();
6291
6450
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6451
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
6292
6452
  parameterBuilder.addThrottling();
6293
6453
  if (this.serverTelemetryManager) {
6294
6454
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -6432,18 +6592,22 @@ var RegionDiscovery = /** @class */ (function () {
6432
6592
  *
6433
6593
  * @returns Promise<string | null>
6434
6594
  */
6435
- RegionDiscovery.prototype.detectRegion = function (environmentRegion, regionDiscoveryMetadata) {
6595
+ RegionDiscovery.prototype.detectRegion = function (environmentRegion, regionDiscoveryMetadata, proxyUrl) {
6436
6596
  return __awaiter(this, void 0, void 0, function () {
6437
- var autodetectedRegionName, localIMDSVersionResponse, currentIMDSVersion, currentIMDSVersionResponse;
6597
+ var autodetectedRegionName, options, localIMDSVersionResponse, currentIMDSVersion, currentIMDSVersionResponse;
6438
6598
  return __generator(this, function (_a) {
6439
6599
  switch (_a.label) {
6440
6600
  case 0:
6441
6601
  autodetectedRegionName = environmentRegion;
6442
6602
  if (!!autodetectedRegionName) return [3 /*break*/, 8];
6603
+ options = RegionDiscovery.IMDS_OPTIONS;
6604
+ if (proxyUrl) {
6605
+ options.proxyUrl = proxyUrl;
6606
+ }
6443
6607
  _a.label = 1;
6444
6608
  case 1:
6445
6609
  _a.trys.push([1, 6, , 7]);
6446
- return [4 /*yield*/, this.getRegionFromIMDS(Constants.IMDS_VERSION)];
6610
+ return [4 /*yield*/, this.getRegionFromIMDS(Constants.IMDS_VERSION, options)];
6447
6611
  case 2:
6448
6612
  localIMDSVersionResponse = _a.sent();
6449
6613
  if (localIMDSVersionResponse.status === ResponseCodes.httpSuccess) {
@@ -6451,14 +6615,14 @@ var RegionDiscovery = /** @class */ (function () {
6451
6615
  regionDiscoveryMetadata.region_source = RegionDiscoverySources.IMDS;
6452
6616
  }
6453
6617
  if (!(localIMDSVersionResponse.status === ResponseCodes.httpBadRequest)) return [3 /*break*/, 5];
6454
- return [4 /*yield*/, this.getCurrentVersion()];
6618
+ return [4 /*yield*/, this.getCurrentVersion(options)];
6455
6619
  case 3:
6456
6620
  currentIMDSVersion = _a.sent();
6457
6621
  if (!currentIMDSVersion) {
6458
6622
  regionDiscoveryMetadata.region_source = RegionDiscoverySources.FAILED_AUTO_DETECTION;
6459
6623
  return [2 /*return*/, null];
6460
6624
  }
6461
- return [4 /*yield*/, this.getRegionFromIMDS(currentIMDSVersion)];
6625
+ return [4 /*yield*/, this.getRegionFromIMDS(currentIMDSVersion, options)];
6462
6626
  case 4:
6463
6627
  currentIMDSVersionResponse = _a.sent();
6464
6628
  if (currentIMDSVersionResponse.status === ResponseCodes.httpSuccess) {
@@ -6491,10 +6655,10 @@ var RegionDiscovery = /** @class */ (function () {
6491
6655
  * @param imdsEndpointUrl
6492
6656
  * @returns Promise<NetworkResponse<string>>
6493
6657
  */
6494
- RegionDiscovery.prototype.getRegionFromIMDS = function (version) {
6658
+ RegionDiscovery.prototype.getRegionFromIMDS = function (version, options) {
6495
6659
  return __awaiter(this, void 0, void 0, function () {
6496
6660
  return __generator(this, function (_a) {
6497
- return [2 /*return*/, this.networkInterface.sendGetRequestAsync(Constants.IMDS_ENDPOINT + "?api-version=" + version + "&format=text", RegionDiscovery.IMDS_OPTIONS, Constants.IMDS_TIMEOUT)];
6661
+ return [2 /*return*/, this.networkInterface.sendGetRequestAsync(Constants.IMDS_ENDPOINT + "?api-version=" + version + "&format=text", options, Constants.IMDS_TIMEOUT)];
6498
6662
  });
6499
6663
  });
6500
6664
  };
@@ -6503,14 +6667,14 @@ var RegionDiscovery = /** @class */ (function () {
6503
6667
  *
6504
6668
  * @returns Promise<string | null>
6505
6669
  */
6506
- RegionDiscovery.prototype.getCurrentVersion = function () {
6670
+ RegionDiscovery.prototype.getCurrentVersion = function (options) {
6507
6671
  return __awaiter(this, void 0, void 0, function () {
6508
6672
  var response;
6509
6673
  return __generator(this, function (_a) {
6510
6674
  switch (_a.label) {
6511
6675
  case 0:
6512
6676
  _a.trys.push([0, 2, , 3]);
6513
- return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(Constants.IMDS_ENDPOINT + "?format=json", RegionDiscovery.IMDS_OPTIONS)];
6677
+ return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(Constants.IMDS_ENDPOINT + "?format=json", options)];
6514
6678
  case 1:
6515
6679
  response = _a.sent();
6516
6680
  // When IMDS endpoint is called without the api version query param, bad request response comes back with latest version.
@@ -6527,7 +6691,11 @@ var RegionDiscovery = /** @class */ (function () {
6527
6691
  });
6528
6692
  };
6529
6693
  // Options for the IMDS endpoint request
6530
- RegionDiscovery.IMDS_OPTIONS = { headers: { "Metadata": "true" } };
6694
+ RegionDiscovery.IMDS_OPTIONS = {
6695
+ headers: {
6696
+ Metadata: "true",
6697
+ },
6698
+ };
6531
6699
  return RegionDiscovery;
6532
6700
  }());
6533
6701
 
@@ -6540,7 +6708,7 @@ var RegionDiscovery = /** @class */ (function () {
6540
6708
  * endpoint. It will store the pertinent config data in this object for use during token calls.
6541
6709
  */
6542
6710
  var Authority = /** @class */ (function () {
6543
- function Authority(authority, networkInterface, cacheManager, authorityOptions) {
6711
+ function Authority(authority, networkInterface, cacheManager, authorityOptions, proxyUrl) {
6544
6712
  this.canonicalAuthority = authority;
6545
6713
  this._canonicalAuthority.validateAsUri();
6546
6714
  this.networkInterface = networkInterface;
@@ -6548,6 +6716,7 @@ var Authority = /** @class */ (function () {
6548
6716
  this.authorityOptions = authorityOptions;
6549
6717
  this.regionDiscovery = new RegionDiscovery(networkInterface);
6550
6718
  this.regionDiscoveryMetadata = { region_used: undefined, region_source: undefined, region_outcome: undefined };
6719
+ this.proxyUrl = proxyUrl || Constants.EMPTY_STRING;
6551
6720
  }
6552
6721
  Object.defineProperty(Authority.prototype, "authorityType", {
6553
6722
  // See above for AuthorityType
@@ -6816,7 +6985,7 @@ var Authority = /** @class */ (function () {
6816
6985
  metadata = _b.sent();
6817
6986
  if (!metadata) return [3 /*break*/, 4];
6818
6987
  if (!((_a = this.authorityOptions.azureRegionConfiguration) === null || _a === void 0 ? void 0 : _a.azureRegion)) return [3 /*break*/, 3];
6819
- return [4 /*yield*/, this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration.environmentRegion, this.regionDiscoveryMetadata)];
6988
+ return [4 /*yield*/, this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration.environmentRegion, this.regionDiscoveryMetadata, this.proxyUrl)];
6820
6989
  case 2:
6821
6990
  autodetectedRegionName = _b.sent();
6822
6991
  azureRegion = this.authorityOptions.azureRegionConfiguration.azureRegion === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG
@@ -6879,19 +7048,25 @@ var Authority = /** @class */ (function () {
6879
7048
  */
6880
7049
  Authority.prototype.getEndpointMetadataFromNetwork = function () {
6881
7050
  return __awaiter(this, void 0, void 0, function () {
6882
- var response;
7051
+ var options, response;
6883
7052
  return __generator(this, function (_a) {
6884
7053
  switch (_a.label) {
6885
7054
  case 0:
6886
- _a.trys.push([0, 2, , 3]);
6887
- return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(this.defaultOpenIdConfigurationEndpoint)];
7055
+ options = {};
7056
+ if (this.proxyUrl) {
7057
+ options.proxyUrl = this.proxyUrl;
7058
+ }
7059
+ _a.label = 1;
6888
7060
  case 1:
7061
+ _a.trys.push([1, 3, , 4]);
7062
+ return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(this.defaultOpenIdConfigurationEndpoint, options)];
7063
+ case 2:
6889
7064
  response = _a.sent();
6890
7065
  return [2 /*return*/, isOpenIdConfigResponse(response.body) ? response.body : null];
6891
- case 2:
7066
+ case 3:
6892
7067
  _a.sent();
6893
7068
  return [2 /*return*/, null];
6894
- case 3: return [2 /*return*/];
7069
+ case 4: return [2 /*return*/];
6895
7070
  }
6896
7071
  });
6897
7072
  });
@@ -6961,16 +7136,20 @@ var Authority = /** @class */ (function () {
6961
7136
  */
6962
7137
  Authority.prototype.getCloudDiscoveryMetadataFromNetwork = function () {
6963
7138
  return __awaiter(this, void 0, void 0, function () {
6964
- var instanceDiscoveryEndpoint, match, response, metadata;
7139
+ var instanceDiscoveryEndpoint, options, match, response, metadata;
6965
7140
  return __generator(this, function (_a) {
6966
7141
  switch (_a.label) {
6967
7142
  case 0:
6968
7143
  instanceDiscoveryEndpoint = "" + Constants.AAD_INSTANCE_DISCOVERY_ENDPT + this.canonicalAuthority + "oauth2/v2.0/authorize";
7144
+ options = {};
7145
+ if (this.proxyUrl) {
7146
+ options.proxyUrl = this.proxyUrl;
7147
+ }
6969
7148
  match = null;
6970
7149
  _a.label = 1;
6971
7150
  case 1:
6972
7151
  _a.trys.push([1, 3, , 4]);
6973
- return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(instanceDiscoveryEndpoint)];
7152
+ return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(instanceDiscoveryEndpoint, options)];
6974
7153
  case 2:
6975
7154
  response = _a.sent();
6976
7155
  metadata = isCloudInstanceDiscoveryResponse(response.body) ? response.body.metadata : [];
@@ -6985,7 +7164,7 @@ var Authority = /** @class */ (function () {
6985
7164
  return [2 /*return*/, null];
6986
7165
  case 4:
6987
7166
  if (!match) {
6988
- // Custom Domain scenario, host is trusted because Instance Discovery call succeeded
7167
+ // Custom Domain scenario, host is trusted because Instance Discovery call succeeded
6989
7168
  match = Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
6990
7169
  }
6991
7170
  return [2 /*return*/, match];
@@ -7003,6 +7182,19 @@ var Authority = /** @class */ (function () {
7003
7182
  });
7004
7183
  return matches.length > 0;
7005
7184
  };
7185
+ /**
7186
+ * helper function to populate the authority based on azureCloudOptions
7187
+ * @param authorityString
7188
+ * @param azureCloudOptions
7189
+ */
7190
+ Authority.generateAuthority = function (authorityString, azureCloudOptions) {
7191
+ var authorityAzureCloudInstance;
7192
+ if (azureCloudOptions && azureCloudOptions.azureCloudInstance !== exports.AzureCloudInstance.None) {
7193
+ var tenant = azureCloudOptions.tenant ? azureCloudOptions.tenant : Constants.DEFAULT_COMMON_TENANT;
7194
+ authorityAzureCloudInstance = azureCloudOptions.azureCloudInstance + "/" + tenant + "/";
7195
+ }
7196
+ return authorityAzureCloudInstance ? authorityAzureCloudInstance : authorityString;
7197
+ };
7006
7198
  /**
7007
7199
  * Creates cloud discovery metadata object from a given host
7008
7200
  * @param host
@@ -7112,13 +7304,13 @@ var AuthorityFactory = /** @class */ (function () {
7112
7304
  * @param networkClient
7113
7305
  * @param protocolMode
7114
7306
  */
7115
- AuthorityFactory.createDiscoveredInstance = function (authorityUri, networkClient, cacheManager, authorityOptions) {
7307
+ AuthorityFactory.createDiscoveredInstance = function (authorityUri, networkClient, cacheManager, authorityOptions, proxyUrl) {
7116
7308
  return __awaiter(this, void 0, void 0, function () {
7117
7309
  var acquireTokenAuthority, e_1;
7118
7310
  return __generator(this, function (_a) {
7119
7311
  switch (_a.label) {
7120
7312
  case 0:
7121
- acquireTokenAuthority = AuthorityFactory.createInstance(authorityUri, networkClient, cacheManager, authorityOptions);
7313
+ acquireTokenAuthority = AuthorityFactory.createInstance(authorityUri, networkClient, cacheManager, authorityOptions, proxyUrl);
7122
7314
  _a.label = 1;
7123
7315
  case 1:
7124
7316
  _a.trys.push([1, 3, , 4]);
@@ -7144,12 +7336,12 @@ var AuthorityFactory = /** @class */ (function () {
7144
7336
  * @param networkInterface
7145
7337
  * @param protocolMode
7146
7338
  */
7147
- AuthorityFactory.createInstance = function (authorityUrl, networkInterface, cacheManager, authorityOptions) {
7339
+ AuthorityFactory.createInstance = function (authorityUrl, networkInterface, cacheManager, authorityOptions, proxyUrl) {
7148
7340
  // Throw error if authority url is empty
7149
7341
  if (StringUtils.isEmpty(authorityUrl)) {
7150
7342
  throw ClientConfigurationError.createUrlEmptyError();
7151
7343
  }
7152
- return new Authority(authorityUrl, networkInterface, cacheManager, authorityOptions);
7344
+ return new Authority(authorityUrl, networkInterface, cacheManager, authorityOptions, proxyUrl);
7153
7345
  };
7154
7346
  return AuthorityFactory;
7155
7347
  }());
@@ -7274,7 +7466,7 @@ var AuthenticationHeaderParser = /** @class */ (function () {
7274
7466
  challenges.forEach(function (challenge) {
7275
7467
  var _a = challenge.split("="), key = _a[0], value = _a[1];
7276
7468
  // Remove escaped quotation marks (', ") from challenge string to keep only the challenge value
7277
- challengeMap[key] = unescape(value.replace(/['"]+/g, ""));
7469
+ challengeMap[key] = unescape(value.replace(/['"]+/g, Constants.EMPTY_STRING));
7278
7470
  });
7279
7471
  return challengeMap;
7280
7472
  };
@@ -7416,9 +7608,9 @@ var ServerTelemetryManager = /** @class */ (function () {
7416
7608
  */
7417
7609
  ServerTelemetryManager.prototype.getRegionDiscoveryFields = function () {
7418
7610
  var regionDiscoveryFields = [];
7419
- regionDiscoveryFields.push(this.regionUsed || "");
7420
- regionDiscoveryFields.push(this.regionSource || "");
7421
- regionDiscoveryFields.push(this.regionOutcome || "");
7611
+ regionDiscoveryFields.push(this.regionUsed || Constants.EMPTY_STRING);
7612
+ regionDiscoveryFields.push(this.regionSource || Constants.EMPTY_STRING);
7613
+ regionDiscoveryFields.push(this.regionOutcome || Constants.EMPTY_STRING);
7422
7614
  return regionDiscoveryFields.join(",");
7423
7615
  };
7424
7616
  /**
@@ -7441,6 +7633,400 @@ var ServerTelemetryManager = /** @class */ (function () {
7441
7633
  return ServerTelemetryManager;
7442
7634
  }());
7443
7635
 
7636
+ /*
7637
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7638
+ * Licensed under the MIT License.
7639
+ */
7640
+ /**
7641
+ * Enumeration of operations that are instrumented by have their performance measured by the PerformanceClient.
7642
+ *
7643
+ * @export
7644
+ * @enum {number}
7645
+ */
7646
+ exports.PerformanceEvents = void 0;
7647
+ (function (PerformanceEvents) {
7648
+ /**
7649
+ * acquireTokenByCode API (msal-browser and msal-node).
7650
+ * Used to acquire tokens by trading an authorization code against the token endpoint.
7651
+ */
7652
+ PerformanceEvents["AcquireTokenByCode"] = "acquireTokenByCode";
7653
+ /**
7654
+ * acquireTokenByRefreshToken API (msal-browser and msal-node).
7655
+ * Used to renew an access token using a refresh token against the token endpoint.
7656
+ */
7657
+ PerformanceEvents["AcquireTokenByRefreshToken"] = "acquireTokenByRefreshToken";
7658
+ /**
7659
+ * acquireTokenSilent API (msal-browser and msal-node).
7660
+ * Used to silently acquire a new access token (from the cache or the network).
7661
+ */
7662
+ PerformanceEvents["AcquireTokenSilent"] = "acquireTokenSilent";
7663
+ /**
7664
+ * acquireTokenSilentAsync (msal-browser).
7665
+ * Internal API for acquireTokenSilent.
7666
+ */
7667
+ PerformanceEvents["AcquireTokenSilentAsync"] = "acquireTokenSilentAsync";
7668
+ /**
7669
+ * acquireTokenPopup (msal-browser).
7670
+ * Used to acquire a new access token interactively through pop ups
7671
+ */
7672
+ PerformanceEvents["AcquireTokenPopup"] = "acquireTokenPopup";
7673
+ /**
7674
+ * getPublicKeyThumbprint API in CryptoOpts class (msal-browser).
7675
+ * Used to generate a public/private keypair and generate a public key thumbprint for pop requests.
7676
+ */
7677
+ PerformanceEvents["CryptoOptsGetPublicKeyThumbprint"] = "cryptoOptsGetPublicKeyThumbprint";
7678
+ /**
7679
+ * signJwt API in CryptoOpts class (msal-browser).
7680
+ * Used to signed a pop token.
7681
+ */
7682
+ PerformanceEvents["CryptoOptsSignJwt"] = "cryptoOptsSignJwt";
7683
+ /**
7684
+ * acquireToken API in the SilentCacheClient class (msal-browser).
7685
+ * Used to read access tokens from the cache.
7686
+ */
7687
+ PerformanceEvents["SilentCacheClientAcquireToken"] = "silentCacheClientAcquireToken";
7688
+ /**
7689
+ * acquireToken API in the SilentIframeClient class (msal-browser).
7690
+ * Used to acquire a new set of tokens from the authorize endpoint in a hidden iframe.
7691
+ */
7692
+ PerformanceEvents["SilentIframeClientAcquireToken"] = "silentIframeClientAcquireToken";
7693
+ /**
7694
+ * acquireToken API in SilentRereshClient (msal-browser).
7695
+ * Used to acquire a new set of tokens from the token endpoint using a refresh token.
7696
+ */
7697
+ PerformanceEvents["SilentRefreshClientAcquireToken"] = "silentRefreshClientAcquireToken";
7698
+ /**
7699
+ * ssoSilent API (msal-browser).
7700
+ * Used to silently acquire an authorization code and set of tokens using a hidden iframe.
7701
+ */
7702
+ PerformanceEvents["SsoSilent"] = "ssoSilent";
7703
+ /**
7704
+ * getDiscoveredAuthority API in StandardInteractionClient class (msal-browser).
7705
+ * Used to load authority metadata for a request.
7706
+ */
7707
+ PerformanceEvents["StandardInteractionClientGetDiscoveredAuthority"] = "standardInteractionClientGetDiscoveredAuthority";
7708
+ /**
7709
+ * acquireToken APIs in msal-browser.
7710
+ * Used to make an /authorize endpoint call with native brokering enabled.
7711
+ */
7712
+ PerformanceEvents["FetchAccountIdWithNativeBroker"] = "fetchAccountIdWithNativeBroker";
7713
+ /**
7714
+ * acquireToken API in NativeInteractionClient class (msal-browser).
7715
+ * Used to acquire a token from Native component when native brokering is enabled.
7716
+ */
7717
+ PerformanceEvents["NativeInteractionClientAcquireToken"] = "nativeInteractionClientAcquireToken";
7718
+ })(exports.PerformanceEvents || (exports.PerformanceEvents = {}));
7719
+ /**
7720
+ * State of the performance event.
7721
+ *
7722
+ * @export
7723
+ * @enum {number}
7724
+ */
7725
+ exports.PerformanceEventStatus = void 0;
7726
+ (function (PerformanceEventStatus) {
7727
+ PerformanceEventStatus[PerformanceEventStatus["NotStarted"] = 0] = "NotStarted";
7728
+ PerformanceEventStatus[PerformanceEventStatus["InProgress"] = 1] = "InProgress";
7729
+ PerformanceEventStatus[PerformanceEventStatus["Completed"] = 2] = "Completed";
7730
+ })(exports.PerformanceEventStatus || (exports.PerformanceEventStatus = {}));
7731
+
7732
+ /*
7733
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7734
+ * Licensed under the MIT License.
7735
+ */
7736
+ var PerformanceClient = /** @class */ (function () {
7737
+ /**
7738
+ * Creates an instance of PerformanceClient,
7739
+ * an abstract class containing core performance telemetry logic.
7740
+ *
7741
+ * @constructor
7742
+ * @param {string} clientId Client ID of the application
7743
+ * @param {string} authority Authority used by the application
7744
+ * @param {Logger} logger Logger used by the application
7745
+ * @param {string} libraryName Name of the library
7746
+ * @param {string} libraryVersion Version of the library
7747
+ */
7748
+ function PerformanceClient(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry) {
7749
+ this.authority = authority;
7750
+ this.libraryName = libraryName;
7751
+ this.libraryVersion = libraryVersion;
7752
+ this.applicationTelemetry = applicationTelemetry;
7753
+ this.clientId = clientId;
7754
+ this.logger = logger;
7755
+ this.callbacks = new Map();
7756
+ this.eventsByCorrelationId = new Map();
7757
+ this.measurementsById = new Map();
7758
+ }
7759
+ /**
7760
+ * Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.
7761
+ *
7762
+ * @param {PerformanceEvents} measureName
7763
+ * @param {?string} [correlationId]
7764
+ * @returns {InProgressPerformanceEvent}
7765
+ */
7766
+ PerformanceClient.prototype.startMeasurement = function (measureName, correlationId) {
7767
+ var _this = this;
7768
+ var _a, _b;
7769
+ // Generate a placeholder correlation if the request does not provide one
7770
+ var eventCorrelationId = correlationId || this.generateId();
7771
+ if (!correlationId) {
7772
+ this.logger.info("PerformanceClient: No correlation id provided for " + measureName + ", generating", eventCorrelationId);
7773
+ }
7774
+ this.logger.trace("PerformanceClient: Performance measurement started for " + measureName, eventCorrelationId);
7775
+ var performanceMeasurement = this.startPerformanceMeasuremeant(measureName, eventCorrelationId);
7776
+ performanceMeasurement.startMeasurement();
7777
+ var inProgressEvent = {
7778
+ eventId: this.generateId(),
7779
+ status: exports.PerformanceEventStatus.InProgress,
7780
+ authority: this.authority,
7781
+ libraryName: this.libraryName,
7782
+ libraryVersion: this.libraryVersion,
7783
+ appName: (_a = this.applicationTelemetry) === null || _a === void 0 ? void 0 : _a.appName,
7784
+ appVersion: (_b = this.applicationTelemetry) === null || _b === void 0 ? void 0 : _b.appVersion,
7785
+ clientId: this.clientId,
7786
+ name: measureName,
7787
+ startTimeMs: Date.now(),
7788
+ correlationId: eventCorrelationId
7789
+ };
7790
+ // Store in progress events so they can be discarded if not ended properly
7791
+ this.cacheEventByCorrelationId(inProgressEvent);
7792
+ this.cacheMeasurement(inProgressEvent, performanceMeasurement);
7793
+ // Return the event and functions the caller can use to properly end/flush the measurement
7794
+ return {
7795
+ endMeasurement: function (event) {
7796
+ var completedEvent = _this.endMeasurement(__assign(__assign({}, inProgressEvent), event));
7797
+ if (completedEvent) {
7798
+ // Cache event so that submeasurements can be added downstream
7799
+ _this.cacheEventByCorrelationId(completedEvent);
7800
+ }
7801
+ return completedEvent;
7802
+ },
7803
+ flushMeasurement: function () {
7804
+ return _this.flushMeasurements(inProgressEvent.name, inProgressEvent.correlationId);
7805
+ },
7806
+ discardMeasurement: function () {
7807
+ return _this.discardMeasurements(inProgressEvent.correlationId);
7808
+ },
7809
+ measurement: performanceMeasurement,
7810
+ event: inProgressEvent
7811
+ };
7812
+ };
7813
+ /**
7814
+ * Stops measuring the performance for an operation. Should only be called directly by PerformanceClient classes,
7815
+ * as consumers should instead use the function returned by startMeasurement.
7816
+ *
7817
+ * @param {PerformanceEvent} event
7818
+ * @returns {(PerformanceEvent | null)}
7819
+ */
7820
+ PerformanceClient.prototype.endMeasurement = function (event) {
7821
+ var performanceMeasurement = this.measurementsById.get(event.eventId);
7822
+ if (performanceMeasurement) {
7823
+ // Immediately delete so that the same event isnt ended twice
7824
+ this.measurementsById.delete(event.eventId);
7825
+ performanceMeasurement.endMeasurement();
7826
+ var durationMs = performanceMeasurement.flushMeasurement();
7827
+ // null indicates no measurement was taken (e.g. needed performance APIs not present)
7828
+ if (durationMs !== null) {
7829
+ this.logger.trace("PerformanceClient: Performance measurement ended for " + event.name + ": " + durationMs + " ms", event.correlationId);
7830
+ var completedEvent = __assign(__assign({
7831
+ // Allow duration to be overwritten when event ends (e.g. testing), but not status
7832
+ durationMs: Math.round(durationMs) }, event), { status: exports.PerformanceEventStatus.Completed });
7833
+ return completedEvent;
7834
+ }
7835
+ else {
7836
+ this.logger.trace("PerformanceClient: Performance measurement not taken", event.correlationId);
7837
+ }
7838
+ }
7839
+ else {
7840
+ this.logger.trace("PerformanceClient: Measurement not found for " + event.eventId, event.correlationId);
7841
+ }
7842
+ return null;
7843
+ };
7844
+ /**
7845
+ * Upserts event into event cache.
7846
+ * First key is the correlation id, second key is the event id.
7847
+ * Allows for events to be grouped by correlation id,
7848
+ * and to easily allow for properties on them to be updated.
7849
+ *
7850
+ * @private
7851
+ * @param {PerformanceEvent} event
7852
+ */
7853
+ PerformanceClient.prototype.cacheEventByCorrelationId = function (event) {
7854
+ var existingEvents = this.eventsByCorrelationId.get(event.correlationId);
7855
+ if (existingEvents) {
7856
+ this.logger.trace("PerformanceClient: Performance measurement for " + event.name + " added/updated", event.correlationId);
7857
+ existingEvents.set(event.eventId, event);
7858
+ }
7859
+ else {
7860
+ this.logger.trace("PerformanceClient: Performance measurement for " + event.name + " started", event.correlationId);
7861
+ this.eventsByCorrelationId.set(event.correlationId, new Map().set(event.eventId, event));
7862
+ }
7863
+ };
7864
+ /**
7865
+ * Cache measurements by their id.
7866
+ *
7867
+ * @private
7868
+ * @param {PerformanceEvent} event
7869
+ * @param {IPerformanceMeasurement} measurement
7870
+ */
7871
+ PerformanceClient.prototype.cacheMeasurement = function (event, measurement) {
7872
+ this.measurementsById.set(event.eventId, measurement);
7873
+ };
7874
+ /**
7875
+ * Gathers and emits performance events for measurements taked for the given top-level API and correlation ID.
7876
+ *
7877
+ * @param {PerformanceEvents} measureName
7878
+ * @param {string} correlationId
7879
+ */
7880
+ PerformanceClient.prototype.flushMeasurements = function (measureName, correlationId) {
7881
+ var _this = this;
7882
+ this.logger.trace("PerformanceClient: Performance measurements flushed for " + measureName, correlationId);
7883
+ var eventsForCorrelationId = this.eventsByCorrelationId.get(correlationId);
7884
+ if (eventsForCorrelationId) {
7885
+ this.discardMeasurements(correlationId);
7886
+ /*
7887
+ * Manually end incomplete submeasurements to ensure there arent orphaned/never ending events.
7888
+ * Incomplete submeasurements are likely an instrumentation bug that should be fixed.
7889
+ * IE only supports Map.forEach.
7890
+ */
7891
+ var completedEvents_1 = [];
7892
+ eventsForCorrelationId.forEach(function (event) {
7893
+ if (event.name !== measureName && event.status !== exports.PerformanceEventStatus.Completed) {
7894
+ _this.logger.trace("PerformanceClient: Incomplete submeasurement " + event.name + " found for " + measureName, correlationId);
7895
+ var completedEvent = _this.endMeasurement(event);
7896
+ if (completedEvent) {
7897
+ completedEvents_1.push(completedEvent);
7898
+ }
7899
+ }
7900
+ completedEvents_1.push(event);
7901
+ });
7902
+ // Sort events by start time (earliest first)
7903
+ var sortedCompletedEvents = completedEvents_1.sort(function (eventA, eventB) { return eventA.startTimeMs - eventB.startTimeMs; });
7904
+ // Take completed top level event and add completed submeasurements durations as properties
7905
+ var topLevelEvents = sortedCompletedEvents.filter(function (event) { return event.name === measureName && event.status === exports.PerformanceEventStatus.Completed; });
7906
+ if (topLevelEvents.length > 0) {
7907
+ /*
7908
+ * Only take the first top-level event if there are multiple events with the same correlation id.
7909
+ * This greatly simplifies logic for submeasurements.
7910
+ */
7911
+ if (topLevelEvents.length > 1) {
7912
+ this.logger.verbose("PerformanceClient: Multiple distinct top-level performance events found, using the first", correlationId);
7913
+ }
7914
+ var topLevelEvent = topLevelEvents[0];
7915
+ this.logger.verbose("PerformanceClient: Measurement found for " + measureName, correlationId);
7916
+ // Build event object with top level and sub measurements
7917
+ var eventToEmit = sortedCompletedEvents.reduce(function (previous, current) {
7918
+ if (current.name !== measureName) {
7919
+ _this.logger.trace("PerformanceClient: Complete submeasurement found for " + current.name, correlationId);
7920
+ // TODO: Emit additional properties for each subMeasurement
7921
+ var subMeasurementName = current.name + "DurationMs";
7922
+ /*
7923
+ * Some code paths, such as resolving an authority, can occur multiple times.
7924
+ * Only take the first measurement, since the second could be read from the cache,
7925
+ * or due to the same correlation id being used for two distinct requests.
7926
+ */
7927
+ if (!previous[subMeasurementName]) {
7928
+ previous[subMeasurementName] = current.durationMs;
7929
+ }
7930
+ else {
7931
+ _this.logger.verbose("PerformanceClient: Submeasurement for " + measureName + " already exists for " + current.name + ", ignoring", correlationId);
7932
+ }
7933
+ }
7934
+ return previous;
7935
+ }, topLevelEvent);
7936
+ this.emitEvents([eventToEmit], eventToEmit.correlationId);
7937
+ }
7938
+ else {
7939
+ this.logger.verbose("PerformanceClient: No completed top-level measurements found for " + measureName, correlationId);
7940
+ }
7941
+ }
7942
+ else {
7943
+ this.logger.verbose("PerformanceClient: No measurements found", correlationId);
7944
+ }
7945
+ };
7946
+ /**
7947
+ * Removes measurements for a given correlation id.
7948
+ *
7949
+ * @param {string} correlationId
7950
+ */
7951
+ PerformanceClient.prototype.discardMeasurements = function (correlationId) {
7952
+ this.logger.trace("PerformanceClient: Performance measurements discarded", correlationId);
7953
+ this.eventsByCorrelationId.delete(correlationId);
7954
+ };
7955
+ /**
7956
+ * Registers a callback function to receive performance events.
7957
+ *
7958
+ * @param {PerformanceCallbackFunction} callback
7959
+ * @returns {string}
7960
+ */
7961
+ PerformanceClient.prototype.addPerformanceCallback = function (callback) {
7962
+ var callbackId = this.generateId();
7963
+ this.callbacks.set(callbackId, callback);
7964
+ this.logger.verbose("PerformanceClient: Performance callback registered with id: " + callbackId);
7965
+ return callbackId;
7966
+ };
7967
+ /**
7968
+ * Removes a callback registered with addPerformanceCallback.
7969
+ *
7970
+ * @param {string} callbackId
7971
+ * @returns {boolean}
7972
+ */
7973
+ PerformanceClient.prototype.removePerformanceCallback = function (callbackId) {
7974
+ var result = this.callbacks.delete(callbackId);
7975
+ if (result) {
7976
+ this.logger.verbose("PerformanceClient: Performance callback " + callbackId + " removed.");
7977
+ }
7978
+ else {
7979
+ this.logger.verbose("PerformanceClient: Performance callback " + callbackId + " not removed.");
7980
+ }
7981
+ return result;
7982
+ };
7983
+ /**
7984
+ * Emits events to all registered callbacks.
7985
+ *
7986
+ * @param {PerformanceEvent[]} events
7987
+ * @param {?string} [correlationId]
7988
+ */
7989
+ PerformanceClient.prototype.emitEvents = function (events, correlationId) {
7990
+ var _this = this;
7991
+ this.logger.verbose("PerformanceClient: Emitting performance events", correlationId);
7992
+ this.callbacks.forEach(function (callback, callbackId) {
7993
+ _this.logger.trace("PerformanceClient: Emitting event to callback " + callbackId, correlationId);
7994
+ callback.apply(null, [events]);
7995
+ });
7996
+ };
7997
+ return PerformanceClient;
7998
+ }());
7999
+
8000
+ /*
8001
+ * Copyright (c) Microsoft Corporation. All rights reserved.
8002
+ * Licensed under the MIT License.
8003
+ */
8004
+ var StubPerformanceMeasurement = /** @class */ (function () {
8005
+ function StubPerformanceMeasurement() {
8006
+ }
8007
+ /* eslint-disable-next-line @typescript-eslint/no-empty-function */
8008
+ StubPerformanceMeasurement.prototype.startMeasurement = function () { };
8009
+ /* eslint-disable-next-line @typescript-eslint/no-empty-function */
8010
+ StubPerformanceMeasurement.prototype.endMeasurement = function () { };
8011
+ StubPerformanceMeasurement.prototype.flushMeasurement = function () {
8012
+ return null;
8013
+ };
8014
+ return StubPerformanceMeasurement;
8015
+ }());
8016
+ var StubPerformanceClient = /** @class */ (function (_super) {
8017
+ __extends(StubPerformanceClient, _super);
8018
+ function StubPerformanceClient() {
8019
+ return _super !== null && _super.apply(this, arguments) || this;
8020
+ }
8021
+ StubPerformanceClient.prototype.generateId = function () {
8022
+ return "callback-id";
8023
+ };
8024
+ StubPerformanceClient.prototype.startPerformanceMeasuremeant = function () {
8025
+ return new StubPerformanceMeasurement();
8026
+ };
8027
+ return StubPerformanceClient;
8028
+ }(PerformanceClient));
8029
+
7444
8030
  exports.AccessTokenEntity = AccessTokenEntity;
7445
8031
  exports.AccountEntity = AccountEntity;
7446
8032
  exports.AppMetadataEntity = AppMetadataEntity;
@@ -7472,6 +8058,7 @@ exports.Logger = Logger;
7472
8058
  exports.NetworkManager = NetworkManager;
7473
8059
  exports.OIDC_DEFAULT_SCOPES = OIDC_DEFAULT_SCOPES;
7474
8060
  exports.OnBehalfOfClient = OnBehalfOfClient;
8061
+ exports.PerformanceClient = PerformanceClient;
7475
8062
  exports.PopTokenGenerator = PopTokenGenerator;
7476
8063
  exports.PromptValue = PromptValue;
7477
8064
  exports.ProtocolUtils = ProtocolUtils;
@@ -7483,6 +8070,7 @@ exports.ServerTelemetryEntity = ServerTelemetryEntity;
7483
8070
  exports.ServerTelemetryManager = ServerTelemetryManager;
7484
8071
  exports.SilentFlowClient = SilentFlowClient;
7485
8072
  exports.StringUtils = StringUtils;
8073
+ exports.StubPerformanceClient = StubPerformanceClient;
7486
8074
  exports.StubbedNetworkModule = StubbedNetworkModule;
7487
8075
  exports.ThrottlingEntity = ThrottlingEntity;
7488
8076
  exports.ThrottlingUtils = ThrottlingUtils;