@azure/msal-common 5.2.0 → 6.2.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 (160) hide show
  1. package/dist/_virtual/_tslib.js +1 -1
  2. package/dist/account/AuthToken.js +1 -1
  3. package/dist/account/CcsCredential.js +1 -1
  4. package/dist/account/ClientInfo.js +1 -1
  5. package/dist/account/TokenClaims.d.ts +1 -0
  6. package/dist/account/TokenClaims.d.ts.map +1 -1
  7. package/dist/authority/Authority.d.ts +9 -1
  8. package/dist/authority/Authority.d.ts.map +1 -1
  9. package/dist/authority/Authority.js +36 -11
  10. package/dist/authority/Authority.js.map +1 -1
  11. package/dist/authority/AuthorityFactory.d.ts +2 -2
  12. package/dist/authority/AuthorityFactory.d.ts.map +1 -1
  13. package/dist/authority/AuthorityFactory.js +5 -5
  14. package/dist/authority/AuthorityFactory.js.map +1 -1
  15. package/dist/authority/AuthorityOptions.d.ts +8 -0
  16. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  17. package/dist/authority/AuthorityOptions.js +24 -0
  18. package/dist/authority/AuthorityOptions.js.map +1 -0
  19. package/dist/authority/AuthorityType.js +1 -1
  20. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  21. package/dist/authority/ImdsOptions.d.ts +7 -0
  22. package/dist/authority/ImdsOptions.d.ts.map +1 -0
  23. package/dist/authority/OpenIdConfigResponse.js +1 -1
  24. package/dist/authority/ProtocolMode.js +1 -1
  25. package/dist/authority/RegionDiscovery.d.ts +3 -6
  26. package/dist/authority/RegionDiscovery.d.ts.map +1 -1
  27. package/dist/authority/RegionDiscovery.js +19 -11
  28. package/dist/authority/RegionDiscovery.js.map +1 -1
  29. package/dist/cache/CacheManager.d.ts +9 -5
  30. package/dist/cache/CacheManager.d.ts.map +1 -1
  31. package/dist/cache/CacheManager.js +39 -29
  32. package/dist/cache/CacheManager.js.map +1 -1
  33. package/dist/cache/entities/AccessTokenEntity.d.ts +3 -1
  34. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  35. package/dist/cache/entities/AccessTokenEntity.js +13 -6
  36. package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
  37. package/dist/cache/entities/AccountEntity.js +10 -10
  38. package/dist/cache/entities/AccountEntity.js.map +1 -1
  39. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  40. package/dist/cache/entities/AuthorityMetadataEntity.js +1 -1
  41. package/dist/cache/entities/CacheRecord.js +1 -1
  42. package/dist/cache/entities/CredentialEntity.d.ts +12 -2
  43. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  44. package/dist/cache/entities/CredentialEntity.js +27 -12
  45. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  46. package/dist/cache/entities/IdTokenEntity.js +1 -1
  47. package/dist/cache/entities/RefreshTokenEntity.js +1 -1
  48. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  49. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  50. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  51. package/dist/cache/utils/CacheTypes.d.ts +1 -0
  52. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  53. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  54. package/dist/client/AuthorizationCodeClient.js +7 -2
  55. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  56. package/dist/client/BaseClient.js +2 -2
  57. package/dist/client/BaseClient.js.map +1 -1
  58. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  59. package/dist/client/ClientCredentialClient.js +5 -4
  60. package/dist/client/ClientCredentialClient.js.map +1 -1
  61. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  62. package/dist/client/DeviceCodeClient.js +6 -4
  63. package/dist/client/DeviceCodeClient.js.map +1 -1
  64. package/dist/client/OnBehalfOfClient.js +4 -3
  65. package/dist/client/OnBehalfOfClient.js.map +1 -1
  66. package/dist/client/RefreshTokenClient.js +3 -2
  67. package/dist/client/RefreshTokenClient.js.map +1 -1
  68. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  69. package/dist/client/SilentFlowClient.js +4 -13
  70. package/dist/client/SilentFlowClient.js.map +1 -1
  71. package/dist/client/UsernamePasswordClient.js +3 -2
  72. package/dist/client/UsernamePasswordClient.js.map +1 -1
  73. package/dist/config/ClientConfiguration.d.ts +29 -1
  74. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  75. package/dist/config/ClientConfiguration.js +21 -8
  76. package/dist/config/ClientConfiguration.js.map +1 -1
  77. package/dist/crypto/ICrypto.d.ts +9 -2
  78. package/dist/crypto/ICrypto.d.ts.map +1 -1
  79. package/dist/crypto/ICrypto.js +10 -1
  80. package/dist/crypto/ICrypto.js.map +1 -1
  81. package/dist/crypto/IGuidGenerator.d.ts +5 -0
  82. package/dist/crypto/IGuidGenerator.d.ts.map +1 -0
  83. package/dist/crypto/PopTokenGenerator.js +2 -2
  84. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  85. package/dist/error/AuthError.js +3 -3
  86. package/dist/error/AuthError.js.map +1 -1
  87. package/dist/error/ClientAuthError.js +1 -1
  88. package/dist/error/ClientConfigurationError.d.ts +11 -0
  89. package/dist/error/ClientConfigurationError.d.ts.map +1 -1
  90. package/dist/error/ClientConfigurationError.js +12 -2
  91. package/dist/error/ClientConfigurationError.js.map +1 -1
  92. package/dist/error/InteractionRequiredAuthError.js +1 -1
  93. package/dist/error/ServerError.js +1 -1
  94. package/dist/index.cjs.js +666 -140
  95. package/dist/index.cjs.js.map +1 -1
  96. package/dist/index.d.ts +8 -2
  97. package/dist/index.d.ts.map +1 -1
  98. package/dist/index.js +5 -1
  99. package/dist/index.js.map +1 -1
  100. package/dist/logger/Logger.js +13 -13
  101. package/dist/logger/Logger.js.map +1 -1
  102. package/dist/network/INetworkModule.d.ts +1 -0
  103. package/dist/network/INetworkModule.d.ts.map +1 -1
  104. package/dist/network/INetworkModule.js +1 -1
  105. package/dist/network/INetworkModule.js.map +1 -1
  106. package/dist/network/NetworkManager.js +1 -1
  107. package/dist/network/RequestThumbprint.d.ts +1 -1
  108. package/dist/network/RequestThumbprint.d.ts.map +1 -1
  109. package/dist/network/ThrottlingUtils.js +2 -2
  110. package/dist/network/ThrottlingUtils.js.map +1 -1
  111. package/dist/packageMetadata.d.ts +1 -1
  112. package/dist/packageMetadata.js +2 -2
  113. package/dist/packageMetadata.js.map +1 -1
  114. package/dist/request/AuthenticationHeaderParser.js +3 -3
  115. package/dist/request/AuthenticationHeaderParser.js.map +1 -1
  116. package/dist/request/BaseAuthRequest.d.ts +10 -5
  117. package/dist/request/BaseAuthRequest.d.ts.map +1 -1
  118. package/dist/request/CommonEndSessionRequest.d.ts +2 -0
  119. package/dist/request/CommonEndSessionRequest.d.ts.map +1 -1
  120. package/dist/request/RequestParameterBuilder.d.ts +10 -1
  121. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  122. package/dist/request/RequestParameterBuilder.js +25 -3
  123. package/dist/request/RequestParameterBuilder.js.map +1 -1
  124. package/dist/request/RequestValidator.js +1 -1
  125. package/dist/request/ScopeSet.js +4 -4
  126. package/dist/request/ScopeSet.js.map +1 -1
  127. package/dist/response/ResponseHandler.d.ts.map +1 -1
  128. package/dist/response/ResponseHandler.js +8 -8
  129. package/dist/response/ResponseHandler.js.map +1 -1
  130. package/dist/telemetry/performance/IPerformanceClient.d.ts +22 -0
  131. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -0
  132. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +6 -0
  133. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts.map +1 -0
  134. package/dist/telemetry/performance/PerformanceClient.d.ts +125 -0
  135. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -0
  136. package/dist/telemetry/performance/PerformanceClient.js +275 -0
  137. package/dist/telemetry/performance/PerformanceClient.js.map +1 -0
  138. package/dist/telemetry/performance/PerformanceEvent.d.ts +182 -0
  139. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -0
  140. package/dist/telemetry/performance/PerformanceEvent.js +85 -0
  141. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -0
  142. package/dist/telemetry/performance/StubPerformanceClient.d.ts +13 -0
  143. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -0
  144. package/dist/telemetry/performance/StubPerformanceClient.js +37 -0
  145. package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -0
  146. package/dist/telemetry/server/ServerTelemetryManager.js +4 -4
  147. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
  148. package/dist/url/UrlString.js +2 -2
  149. package/dist/url/UrlString.js.map +1 -1
  150. package/dist/utils/Constants.d.ts +5 -1
  151. package/dist/utils/Constants.d.ts.map +1 -1
  152. package/dist/utils/Constants.js +5 -1
  153. package/dist/utils/Constants.js.map +1 -1
  154. package/dist/utils/ProtocolUtils.js +3 -3
  155. package/dist/utils/ProtocolUtils.js.map +1 -1
  156. package/dist/utils/StringUtils.js +1 -1
  157. package/dist/utils/TimeUtils.js +1 -1
  158. package/package.json +2 -4
  159. package/CHANGELOG.json +0 -1259
  160. package/CHANGELOG.md +0 -479
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v5.2.0 2021-12-07 */
1
+ /*! @azure/msal-common v6.2.0 2022-04-04 */
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
@@ -212,6 +213,8 @@ var AADServerParamKeys;
212
213
  AADServerParamKeys["X_CLIENT_CURR_TELEM"] = "x-client-current-telemetry";
213
214
  AADServerParamKeys["X_CLIENT_LAST_TELEM"] = "x-client-last-telemetry";
214
215
  AADServerParamKeys["X_MS_LIB_CAPABILITY"] = "x-ms-lib-capability";
216
+ AADServerParamKeys["X_APP_NAME"] = "x-app-name";
217
+ AADServerParamKeys["X_APP_VER"] = "x-app-ver";
215
218
  AADServerParamKeys["POST_LOGOUT_URI"] = "post_logout_redirect_uri";
216
219
  AADServerParamKeys["ID_TOKEN_HINT"] = "id_token_hint";
217
220
  AADServerParamKeys["DEVICE_CODE"] = "device_code";
@@ -226,6 +229,7 @@ var AADServerParamKeys;
226
229
  AADServerParamKeys["FOCI"] = "foci";
227
230
  AADServerParamKeys["CCS_HEADER"] = "X-AnchorMailbox";
228
231
  AADServerParamKeys["RETURN_SPA_CODE"] = "return_spa_code";
232
+ AADServerParamKeys["LOGOUT_HINT"] = "logout_hint";
229
233
  })(AADServerParamKeys || (AADServerParamKeys = {}));
230
234
  /**
231
235
  * Claims request keys
@@ -481,8 +485,8 @@ var AuthError = /** @class */ (function (_super) {
481
485
  _this = _super.call(this, errorString) || this;
482
486
  Object.setPrototypeOf(_this, AuthError.prototype);
483
487
  _this.errorCode = errorCode || Constants.EMPTY_STRING;
484
- _this.errorMessage = errorMessage || "";
485
- _this.subError = suberror || "";
488
+ _this.errorMessage = errorMessage || Constants.EMPTY_STRING;
489
+ _this.subError = suberror || Constants.EMPTY_STRING;
486
490
  _this.name = "AuthError";
487
491
  return _this;
488
492
  }
@@ -560,6 +564,15 @@ var DEFAULT_CRYPTO_IMPLEMENTATION = {
560
564
  throw AuthError.createUnexpectedError(notImplErr);
561
565
  });
562
566
  });
567
+ },
568
+ hashString: function () {
569
+ return __awaiter(this, void 0, void 0, function () {
570
+ var notImplErr;
571
+ return __generator(this, function (_a) {
572
+ notImplErr = "Crypto interface - hashString() has not been implemented";
573
+ throw AuthError.createUnexpectedError(notImplErr);
574
+ });
575
+ });
563
576
  }
564
577
  };
565
578
 
@@ -1174,7 +1187,7 @@ var Logger = /** @class */ (function () {
1174
1187
  this.localCallback = loggerOptions.loggerCallback || defaultLoggerCallback;
1175
1188
  this.piiLoggingEnabled = loggerOptions.piiLoggingEnabled || false;
1176
1189
  this.level = typeof (loggerOptions.logLevel) === "number" ? loggerOptions.logLevel : exports.LogLevel.Info;
1177
- this.correlationId = loggerOptions.correlationId || "";
1190
+ this.correlationId = loggerOptions.correlationId || Constants.EMPTY_STRING;
1178
1191
  this.packageName = packageName || Constants.EMPTY_STRING;
1179
1192
  this.packageVersion = packageVersion || Constants.EMPTY_STRING;
1180
1193
  }
@@ -1204,7 +1217,7 @@ var Logger = /** @class */ (function () {
1204
1217
  logHeader = "[" + timestamp + "]";
1205
1218
  }
1206
1219
  var log = logHeader + " : " + this.packageName + "@" + this.packageVersion + " : " + exports.LogLevel[options.logLevel] + " - " + logMessage;
1207
- // debug(`msal:${LogLevel[options.logLevel]}${options.containsPii ? "-Pii": ""}${options.context ? `:${options.context}` : ""}`)(logMessage);
1220
+ // debug(`msal:${LogLevel[options.logLevel]}${options.containsPii ? "-Pii": Constants.EMPTY_STRING}${options.context ? `:${options.context}` : Constants.EMPTY_STRING}`)(logMessage);
1208
1221
  this.executeCallback(options.logLevel, log, options.containsPii || false);
1209
1222
  };
1210
1223
  /**
@@ -1222,7 +1235,7 @@ var Logger = /** @class */ (function () {
1222
1235
  this.logMessage(message, {
1223
1236
  logLevel: exports.LogLevel.Error,
1224
1237
  containsPii: false,
1225
- correlationId: correlationId || ""
1238
+ correlationId: correlationId || Constants.EMPTY_STRING
1226
1239
  });
1227
1240
  };
1228
1241
  /**
@@ -1232,7 +1245,7 @@ var Logger = /** @class */ (function () {
1232
1245
  this.logMessage(message, {
1233
1246
  logLevel: exports.LogLevel.Error,
1234
1247
  containsPii: true,
1235
- correlationId: correlationId || ""
1248
+ correlationId: correlationId || Constants.EMPTY_STRING
1236
1249
  });
1237
1250
  };
1238
1251
  /**
@@ -1242,7 +1255,7 @@ var Logger = /** @class */ (function () {
1242
1255
  this.logMessage(message, {
1243
1256
  logLevel: exports.LogLevel.Warning,
1244
1257
  containsPii: false,
1245
- correlationId: correlationId || ""
1258
+ correlationId: correlationId || Constants.EMPTY_STRING
1246
1259
  });
1247
1260
  };
1248
1261
  /**
@@ -1252,7 +1265,7 @@ var Logger = /** @class */ (function () {
1252
1265
  this.logMessage(message, {
1253
1266
  logLevel: exports.LogLevel.Warning,
1254
1267
  containsPii: true,
1255
- correlationId: correlationId || ""
1268
+ correlationId: correlationId || Constants.EMPTY_STRING
1256
1269
  });
1257
1270
  };
1258
1271
  /**
@@ -1262,7 +1275,7 @@ var Logger = /** @class */ (function () {
1262
1275
  this.logMessage(message, {
1263
1276
  logLevel: exports.LogLevel.Info,
1264
1277
  containsPii: false,
1265
- correlationId: correlationId || ""
1278
+ correlationId: correlationId || Constants.EMPTY_STRING
1266
1279
  });
1267
1280
  };
1268
1281
  /**
@@ -1272,7 +1285,7 @@ var Logger = /** @class */ (function () {
1272
1285
  this.logMessage(message, {
1273
1286
  logLevel: exports.LogLevel.Info,
1274
1287
  containsPii: true,
1275
- correlationId: correlationId || ""
1288
+ correlationId: correlationId || Constants.EMPTY_STRING
1276
1289
  });
1277
1290
  };
1278
1291
  /**
@@ -1282,7 +1295,7 @@ var Logger = /** @class */ (function () {
1282
1295
  this.logMessage(message, {
1283
1296
  logLevel: exports.LogLevel.Verbose,
1284
1297
  containsPii: false,
1285
- correlationId: correlationId || ""
1298
+ correlationId: correlationId || Constants.EMPTY_STRING
1286
1299
  });
1287
1300
  };
1288
1301
  /**
@@ -1292,7 +1305,7 @@ var Logger = /** @class */ (function () {
1292
1305
  this.logMessage(message, {
1293
1306
  logLevel: exports.LogLevel.Verbose,
1294
1307
  containsPii: true,
1295
- correlationId: correlationId || ""
1308
+ correlationId: correlationId || Constants.EMPTY_STRING
1296
1309
  });
1297
1310
  };
1298
1311
  /**
@@ -1302,7 +1315,7 @@ var Logger = /** @class */ (function () {
1302
1315
  this.logMessage(message, {
1303
1316
  logLevel: exports.LogLevel.Trace,
1304
1317
  containsPii: false,
1305
- correlationId: correlationId || ""
1318
+ correlationId: correlationId || Constants.EMPTY_STRING
1306
1319
  });
1307
1320
  };
1308
1321
  /**
@@ -1312,7 +1325,7 @@ var Logger = /** @class */ (function () {
1312
1325
  this.logMessage(message, {
1313
1326
  logLevel: exports.LogLevel.Trace,
1314
1327
  containsPii: true,
1315
- correlationId: correlationId || ""
1328
+ correlationId: correlationId || Constants.EMPTY_STRING
1316
1329
  });
1317
1330
  };
1318
1331
  /**
@@ -1326,7 +1339,27 @@ var Logger = /** @class */ (function () {
1326
1339
 
1327
1340
  /* eslint-disable header/header */
1328
1341
  var name = "@azure/msal-common";
1329
- var version = "5.2.0";
1342
+ var version = "6.2.0";
1343
+
1344
+ /*
1345
+ * Copyright (c) Microsoft Corporation. All rights reserved.
1346
+ * Licensed under the MIT License.
1347
+ */
1348
+ exports.AzureCloudInstance = void 0;
1349
+ (function (AzureCloudInstance) {
1350
+ // AzureCloudInstance is not specified.
1351
+ AzureCloudInstance[AzureCloudInstance["None"] = 0] = "None";
1352
+ // Microsoft Azure public cloud
1353
+ AzureCloudInstance["AzurePublic"] = "https://login.microsoftonline.com";
1354
+ // Microsoft PPE
1355
+ AzureCloudInstance["AzurePpe"] = "https://login.windows-ppe.net";
1356
+ // Microsoft Chinese national cloud
1357
+ AzureCloudInstance["AzureChina"] = "https://login.chinacloudapi.cn";
1358
+ // Microsoft German national cloud ("Black Forest")
1359
+ AzureCloudInstance["AzureGermany"] = "https://login.microsoftonline.de";
1360
+ // US Government cloud
1361
+ AzureCloudInstance["AzureUsGovernment"] = "https://login.microsoftonline.us";
1362
+ })(exports.AzureCloudInstance || (exports.AzureCloudInstance = {}));
1330
1363
 
1331
1364
  /*
1332
1365
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1337,7 +1370,7 @@ var version = "5.2.0";
1337
1370
  *
1338
1371
  * Key:Value Schema:
1339
1372
  *
1340
- * Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<scheme>
1373
+ * Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<requestedClaims*>-<scheme*>
1341
1374
  *
1342
1375
  * Value Schema:
1343
1376
  * {
@@ -1351,6 +1384,7 @@ var version = "5.2.0";
1351
1384
  * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
1352
1385
  * oboAssertion: access token passed in as part of OBO request
1353
1386
  * tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
1387
+ * requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request
1354
1388
  * }
1355
1389
  */
1356
1390
  var CredentialEntity = /** @class */ (function () {
@@ -1378,7 +1412,7 @@ var CredentialEntity = /** @class */ (function () {
1378
1412
  * generates credential key
1379
1413
  */
1380
1414
  CredentialEntity.prototype.generateCredentialKey = function () {
1381
- return CredentialEntity.generateCredentialCacheKey(this.homeAccountId, this.environment, this.credentialType, this.clientId, this.realm, this.target, this.familyId, this.tokenType);
1415
+ return CredentialEntity.generateCredentialCacheKey(this.homeAccountId, this.environment, this.credentialType, this.clientId, this.realm, this.target, this.familyId, this.tokenType, this.requestedClaimsHash);
1382
1416
  };
1383
1417
  /**
1384
1418
  * returns the type of the cache (in this case credential)
@@ -1422,16 +1456,14 @@ var CredentialEntity = /** @class */ (function () {
1422
1456
  * generates credential key
1423
1457
  * <home_account_id*>-\<environment>-<credential_type>-<client_id>-<realm\*>-<target\*>-<scheme\*>
1424
1458
  */
1425
- CredentialEntity.generateCredentialCacheKey = function (homeAccountId, environment, credentialType, clientId, realm, target, familyId, tokenType) {
1459
+ CredentialEntity.generateCredentialCacheKey = function (homeAccountId, environment, credentialType, clientId, realm, target, familyId, tokenType, requestedClaimsHash) {
1426
1460
  var credentialKey = [
1427
1461
  this.generateAccountIdForCacheKey(homeAccountId, environment),
1428
1462
  this.generateCredentialIdForCacheKey(credentialType, clientId, realm, familyId),
1429
- this.generateTargetForCacheKey(target)
1463
+ this.generateTargetForCacheKey(target),
1464
+ this.generateClaimsHashForCacheKey(requestedClaimsHash),
1465
+ this.generateSchemeForCacheKey(tokenType)
1430
1466
  ];
1431
- // PoP Tokens and SSH certs include scheme in cache key
1432
- if (tokenType && tokenType !== exports.AuthenticationScheme.BEARER) {
1433
- credentialKey.push(tokenType.toLowerCase());
1434
- }
1435
1467
  return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
1436
1468
  };
1437
1469
  /**
@@ -1457,7 +1489,7 @@ var CredentialEntity = /** @class */ (function () {
1457
1489
  var credentialId = [
1458
1490
  credentialType,
1459
1491
  clientOrFamilyId,
1460
- realm || "",
1492
+ realm || Constants.EMPTY_STRING,
1461
1493
  ];
1462
1494
  return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
1463
1495
  };
@@ -1465,7 +1497,23 @@ var CredentialEntity = /** @class */ (function () {
1465
1497
  * Generate target key component as per schema: <target>
1466
1498
  */
1467
1499
  CredentialEntity.generateTargetForCacheKey = function (scopes) {
1468
- return (scopes || "").toLowerCase();
1500
+ return (scopes || Constants.EMPTY_STRING).toLowerCase();
1501
+ };
1502
+ /**
1503
+ * Generate requested claims key component as per schema: <requestedClaims>
1504
+ */
1505
+ CredentialEntity.generateClaimsHashForCacheKey = function (requestedClaimsHash) {
1506
+ return (requestedClaimsHash || Constants.EMPTY_STRING).toLowerCase();
1507
+ };
1508
+ /**
1509
+ * Generate scheme key componenet as per schema: <scheme>
1510
+ */
1511
+ CredentialEntity.generateSchemeForCacheKey = function (tokenType) {
1512
+ /*
1513
+ * PoP Tokens and SSH certs include scheme in cache key
1514
+ * Cast to lowercase to handle "bearer" from ADFS
1515
+ */
1516
+ return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : Constants.EMPTY_STRING;
1469
1517
  };
1470
1518
  return CredentialEntity;
1471
1519
  }());
@@ -1550,6 +1598,10 @@ var ClientConfigurationErrorMessage = {
1550
1598
  code: "untrusted_authority",
1551
1599
  desc: "The provided authority is not a trusted authority. Please include this authority in the knownAuthorities config parameter."
1552
1600
  },
1601
+ invalidAzureCloudInstance: {
1602
+ code: "invalid_azure_cloud_instance",
1603
+ desc: "Invalid AzureCloudInstance provided. Please refer MSAL JS docs: aks.ms/msaljs/azure_cloud_instance for valid values"
1604
+ },
1553
1605
  missingSshJwk: {
1554
1606
  code: "missing_ssh_jwk",
1555
1607
  desc: "Missing sshJwk in SSH certificate request. A stringified JSON Web Key is required when using the SSH authentication scheme."
@@ -1686,7 +1738,13 @@ var ClientConfigurationError = /** @class */ (function (_super) {
1686
1738
  ClientConfigurationError.createUntrustedAuthorityError = function () {
1687
1739
  return new ClientConfigurationError(ClientConfigurationErrorMessage.untrustedAuthority.code, ClientConfigurationErrorMessage.untrustedAuthority.desc);
1688
1740
  };
1689
- /*
1741
+ /**
1742
+ * Throws error when the AzureCloudInstance is set to an invalid value
1743
+ */
1744
+ ClientConfigurationError.createInvalidAzureCloudInstanceError = function () {
1745
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidAzureCloudInstance.code, ClientConfigurationErrorMessage.invalidAzureCloudInstance.desc);
1746
+ };
1747
+ /**
1690
1748
  * Throws an error when the authentication scheme is set to SSH but the SSH public key is omitted from the request
1691
1749
  */
1692
1750
  ClientConfigurationError.createMissingSshJwkError = function () {
@@ -1740,7 +1798,7 @@ var ScopeSet = /** @class */ (function () {
1740
1798
  * @param scopesRequired
1741
1799
  */
1742
1800
  ScopeSet.fromString = function (inputScopeString) {
1743
- var scopeString = inputScopeString || "";
1801
+ var scopeString = inputScopeString || Constants.EMPTY_STRING;
1744
1802
  var inputScopes = scopeString.split(" ");
1745
1803
  return new ScopeSet(inputScopes);
1746
1804
  };
@@ -1884,7 +1942,7 @@ var ScopeSet = /** @class */ (function () {
1884
1942
  var scopeArr = this.asArray();
1885
1943
  return scopeArr.join(" ");
1886
1944
  }
1887
- return "";
1945
+ return Constants.EMPTY_STRING;
1888
1946
  };
1889
1947
  /**
1890
1948
  * Prints scopes into a space-delimited lower-case string (used for caching)
@@ -2032,8 +2090,8 @@ var AccountEntity = /** @class */ (function () {
2032
2090
  AccountEntity.generateAccountCacheKey = function (accountInterface) {
2033
2091
  var accountKey = [
2034
2092
  accountInterface.homeAccountId,
2035
- accountInterface.environment || "",
2036
- accountInterface.tenantId || "",
2093
+ accountInterface.environment || Constants.EMPTY_STRING,
2094
+ accountInterface.tenantId || Constants.EMPTY_STRING,
2037
2095
  ];
2038
2096
  return accountKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
2039
2097
  };
@@ -2056,17 +2114,17 @@ var AccountEntity = /** @class */ (function () {
2056
2114
  }
2057
2115
  account.environment = env;
2058
2116
  // non AAD scenarios can have empty realm
2059
- account.realm = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.tid) || "";
2117
+ account.realm = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.tid) || Constants.EMPTY_STRING;
2060
2118
  account.oboAssertion = oboAssertion;
2061
2119
  if (idToken) {
2062
2120
  account.idTokenClaims = idToken.claims;
2063
2121
  // How do you account for MSA CID here?
2064
- 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) || "";
2122
+ 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;
2065
2123
  /*
2066
2124
  * 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.
2067
2125
  * This field should not be relied upon if a custom policy is configured to return more than 1 email.
2068
2126
  */
2069
- 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] : "");
2127
+ 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);
2070
2128
  account.name = (_f = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _f === void 0 ? void 0 : _f.name;
2071
2129
  }
2072
2130
  account.cloudGraphHostName = cloudGraphHostName;
@@ -2084,7 +2142,7 @@ var AccountEntity = /** @class */ (function () {
2084
2142
  account.authorityType = (authority && authority.authorityType === exports.AuthorityType.Adfs) ? exports.CacheAccountType.ADFS_ACCOUNT_TYPE : exports.CacheAccountType.GENERIC_ACCOUNT_TYPE;
2085
2143
  account.homeAccountId = homeAccountId;
2086
2144
  // non AAD scenarios can have empty realm
2087
- account.realm = "";
2145
+ account.realm = Constants.EMPTY_STRING;
2088
2146
  account.oboAssertion = oboAssertion;
2089
2147
  var env = environment || authority && authority.getPreferredCache();
2090
2148
  if (!env) {
@@ -2092,10 +2150,10 @@ var AccountEntity = /** @class */ (function () {
2092
2150
  }
2093
2151
  if (idToken) {
2094
2152
  // How do you account for MSA CID here?
2095
- 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) || "";
2153
+ 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;
2096
2154
  // upn claim for most ADFS scenarios
2097
- account.username = ((_c = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _c === void 0 ? void 0 : _c.upn) || "";
2098
- account.name = ((_d = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _d === void 0 ? void 0 : _d.name) || "";
2155
+ account.username = ((_c = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _c === void 0 ? void 0 : _c.upn) || Constants.EMPTY_STRING;
2156
+ account.name = ((_d = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _d === void 0 ? void 0 : _d.name) || Constants.EMPTY_STRING;
2099
2157
  account.idTokenClaims = idToken === null || idToken === void 0 ? void 0 : idToken.claims;
2100
2158
  }
2101
2159
  account.environment = env;
@@ -2300,7 +2358,8 @@ var CacheManager = /** @class */ (function () {
2300
2358
  environment: credential.environment,
2301
2359
  homeAccountId: credential.homeAccountId,
2302
2360
  realm: credential.realm,
2303
- tokenType: credential.tokenType
2361
+ tokenType: credential.tokenType,
2362
+ requestedClaimsHash: credential.requestedClaimsHash
2304
2363
  });
2305
2364
  currentScopes = ScopeSet.fromString(credential.target);
2306
2365
  currentAccessTokens = Object.keys(currentTokenCache.accessTokens).map(function (key) { return currentTokenCache.accessTokens[key]; });
@@ -2331,7 +2390,7 @@ var CacheManager = /** @class */ (function () {
2331
2390
  * @param realm
2332
2391
  */
2333
2392
  CacheManager.prototype.getAccountsFilteredBy = function (accountFilter) {
2334
- return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : "", accountFilter ? accountFilter.environment : "", accountFilter ? accountFilter.realm : "");
2393
+ return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : Constants.EMPTY_STRING, accountFilter ? accountFilter.environment : Constants.EMPTY_STRING, accountFilter ? accountFilter.realm : Constants.EMPTY_STRING);
2335
2394
  };
2336
2395
  /**
2337
2396
  * retrieve accounts matching all provided filters; if no filter is set, get all accounts
@@ -2372,7 +2431,7 @@ var CacheManager = /** @class */ (function () {
2372
2431
  * @param target
2373
2432
  */
2374
2433
  CacheManager.prototype.getCredentialsFilteredBy = function (filter) {
2375
- return this.getCredentialsFilteredByInternal(filter.homeAccountId, filter.environment, filter.credentialType, filter.clientId, filter.familyId, filter.realm, filter.target, filter.oboAssertion, filter.tokenType, filter.keyId);
2434
+ return this.getCredentialsFilteredByInternal(filter.homeAccountId, filter.environment, filter.credentialType, filter.clientId, filter.familyId, filter.realm, filter.target, filter.oboAssertion, filter.tokenType, filter.keyId, filter.requestedClaimsHash);
2376
2435
  };
2377
2436
  /**
2378
2437
  * Support function to help match credentials
@@ -2385,7 +2444,7 @@ var CacheManager = /** @class */ (function () {
2385
2444
  * @param oboAssertion
2386
2445
  * @param tokenType
2387
2446
  */
2388
- CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, oboAssertion, tokenType, keyId) {
2447
+ CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, oboAssertion, tokenType, keyId, requestedClaimsHash) {
2389
2448
  var _this = this;
2390
2449
  var allCacheKeys = this.getKeys();
2391
2450
  var matchingCredentials = {
@@ -2432,38 +2491,37 @@ var CacheManager = /** @class */ (function () {
2432
2491
  if (!!target && !_this.matchTarget(entity, target)) {
2433
2492
  return;
2434
2493
  }
2494
+ // If request OR cached entity has requested Claims Hash, check if they match
2495
+ if (requestedClaimsHash || entity.requestedClaimsHash) {
2496
+ // Don't match if either is undefined or they are different
2497
+ if (entity.requestedClaimsHash !== requestedClaimsHash) {
2498
+ return;
2499
+ }
2500
+ }
2435
2501
  // Access Token with Auth Scheme specific matching
2436
2502
  if (credentialType === exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
2437
2503
  if (!!tokenType && !_this.matchTokenType(entity, tokenType)) {
2438
2504
  return;
2439
2505
  }
2440
- switch (tokenType) {
2441
- case exports.AuthenticationScheme.POP:
2442
- // This check avoids matching outdated POP tokens that don't have the <-scheme> in the cache key
2443
- if (cacheKey.indexOf(exports.AuthenticationScheme.POP) === -1) {
2444
- // AccessToken_With_AuthScheme that doesn't have "-pop" in the key is outdated and needs to be removed
2445
- _this.removeItem(cacheKey, exports.CacheSchemaType.CREDENTIAL);
2446
- return;
2447
- }
2448
- break;
2449
- case exports.AuthenticationScheme.SSH:
2450
- // KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
2451
- if (keyId && !_this.matchKeyId(entity, keyId)) {
2452
- return;
2453
- }
2454
- break;
2506
+ // KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
2507
+ if (tokenType === exports.AuthenticationScheme.SSH) {
2508
+ if (keyId && !_this.matchKeyId(entity, keyId)) {
2509
+ return;
2510
+ }
2455
2511
  }
2456
2512
  }
2513
+ // At this point, the entity matches the request, update cache key if key schema has changed
2514
+ var updatedCacheKey = _this.updateCredentialCacheKey(cacheKey, entity);
2457
2515
  switch (credType) {
2458
2516
  case exports.CredentialType.ID_TOKEN:
2459
- matchingCredentials.idTokens[cacheKey] = entity;
2517
+ matchingCredentials.idTokens[updatedCacheKey] = entity;
2460
2518
  break;
2461
2519
  case exports.CredentialType.ACCESS_TOKEN:
2462
2520
  case exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
2463
- matchingCredentials.accessTokens[cacheKey] = entity;
2521
+ matchingCredentials.accessTokens[updatedCacheKey] = entity;
2464
2522
  break;
2465
2523
  case exports.CredentialType.REFRESH_TOKEN:
2466
- matchingCredentials.refreshTokens[cacheKey] = entity;
2524
+ matchingCredentials.refreshTokens[updatedCacheKey] = entity;
2467
2525
  break;
2468
2526
  }
2469
2527
  });
@@ -2662,10 +2720,10 @@ var CacheManager = /** @class */ (function () {
2662
2720
  * @param environment
2663
2721
  * @param authScheme
2664
2722
  */
2665
- CacheManager.prototype.readCacheRecord = function (account, clientId, scopes, environment, authScheme, keyId) {
2723
+ CacheManager.prototype.readCacheRecord = function (account, clientId, request, environment) {
2666
2724
  var cachedAccount = this.readAccountFromCache(account);
2667
2725
  var cachedIdToken = this.readIdTokenFromCache(clientId, account);
2668
- var cachedAccessToken = this.readAccessTokenFromCache(clientId, account, scopes, authScheme, keyId);
2726
+ var cachedAccessToken = this.readAccessTokenFromCache(clientId, account, request);
2669
2727
  var cachedRefreshToken = this.readRefreshTokenFromCache(clientId, account, false);
2670
2728
  var cachedAppMetadata = this.readAppMetadataFromCache(environment, clientId);
2671
2729
  if (cachedAccount && cachedIdToken) {
@@ -2719,9 +2777,14 @@ var CacheManager = /** @class */ (function () {
2719
2777
  * @param scopes
2720
2778
  * @param authScheme
2721
2779
  */
2722
- CacheManager.prototype.readAccessTokenFromCache = function (clientId, account, scopes, authScheme, keyId) {
2723
- // Distinguish between Bearer and PoP/SSH token cache types
2724
- var credentialType = (authScheme && authScheme !== exports.AuthenticationScheme.BEARER) ? exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : exports.CredentialType.ACCESS_TOKEN;
2780
+ CacheManager.prototype.readAccessTokenFromCache = function (clientId, account, request) {
2781
+ var scopes = new ScopeSet(request.scopes || []);
2782
+ var authScheme = request.authenticationScheme || exports.AuthenticationScheme.BEARER;
2783
+ /*
2784
+ * Distinguish between Bearer and PoP/SSH token cache types
2785
+ * Cast to lowercase to handle "bearer" from ADFS
2786
+ */
2787
+ var credentialType = (authScheme && authScheme.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : exports.CredentialType.ACCESS_TOKEN;
2725
2788
  var accessTokenFilter = {
2726
2789
  homeAccountId: account.homeAccountId,
2727
2790
  environment: account.environment,
@@ -2730,7 +2793,8 @@ var CacheManager = /** @class */ (function () {
2730
2793
  realm: account.tenantId,
2731
2794
  target: scopes.printScopesLowerCase(),
2732
2795
  tokenType: authScheme,
2733
- keyId: keyId
2796
+ keyId: request.sshKid,
2797
+ requestedClaimsHash: request.requestedClaimsHash
2734
2798
  };
2735
2799
  var credentialCache = this.getCredentialsFilteredBy(accessTokenFilter);
2736
2800
  var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
@@ -3039,6 +3103,10 @@ var DefaultStorageClass = /** @class */ (function (_super) {
3039
3103
  });
3040
3104
  });
3041
3105
  };
3106
+ DefaultStorageClass.prototype.updateCredentialCacheKey = function () {
3107
+ var notImplErr = "Storage interface - updateCredentialCacheKey() has not been implemented for the cacheStorage interface.";
3108
+ throw AuthError.createUnexpectedError(notImplErr);
3109
+ };
3042
3110
  return DefaultStorageClass;
3043
3111
  }(CacheManager));
3044
3112
 
@@ -3050,7 +3118,8 @@ var DefaultStorageClass = /** @class */ (function (_super) {
3050
3118
  var DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;
3051
3119
  var DEFAULT_SYSTEM_OPTIONS = {
3052
3120
  tokenRenewalOffsetSeconds: DEFAULT_TOKEN_RENEWAL_OFFSET_SEC,
3053
- preventCorsPreflight: false
3121
+ preventCorsPreflight: false,
3122
+ proxyUrl: Constants.EMPTY_STRING
3054
3123
  };
3055
3124
  var DEFAULT_LOGGER_IMPLEMENTATION = {
3056
3125
  loggerCallback: function () {
@@ -3058,7 +3127,7 @@ var DEFAULT_LOGGER_IMPLEMENTATION = {
3058
3127
  },
3059
3128
  piiLoggingEnabled: false,
3060
3129
  logLevel: exports.LogLevel.Info,
3061
- correlationId: ""
3130
+ correlationId: Constants.EMPTY_STRING
3062
3131
  };
3063
3132
  var DEFAULT_NETWORK_IMPLEMENTATION = {
3064
3133
  sendGetRequestAsync: function () {
@@ -3083,13 +3152,23 @@ var DEFAULT_NETWORK_IMPLEMENTATION = {
3083
3152
  var DEFAULT_LIBRARY_INFO = {
3084
3153
  sku: Constants.SKU,
3085
3154
  version: version,
3086
- cpu: "",
3087
- os: ""
3155
+ cpu: Constants.EMPTY_STRING,
3156
+ os: Constants.EMPTY_STRING
3088
3157
  };
3089
3158
  var DEFAULT_CLIENT_CREDENTIALS = {
3090
- clientSecret: "",
3159
+ clientSecret: Constants.EMPTY_STRING,
3091
3160
  clientAssertion: undefined
3092
3161
  };
3162
+ var DEFAULT_AZURE_CLOUD_OPTIONS = {
3163
+ azureCloudInstance: exports.AzureCloudInstance.None,
3164
+ tenant: "" + Constants.DEFAULT_COMMON_TENANT
3165
+ };
3166
+ var DEFAULT_TELEMETRY_OPTIONS = {
3167
+ application: {
3168
+ appName: "",
3169
+ appVersion: ""
3170
+ }
3171
+ };
3093
3172
  /**
3094
3173
  * Function that sets the default options when not explicitly configured from app developer
3095
3174
  *
@@ -3098,7 +3177,7 @@ var DEFAULT_CLIENT_CREDENTIALS = {
3098
3177
  * @returns Configuration
3099
3178
  */
3100
3179
  function buildClientConfiguration(_a) {
3101
- 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;
3180
+ 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;
3102
3181
  var loggerOptions = __assign(__assign({}, DEFAULT_LOGGER_IMPLEMENTATION), userLoggerOption);
3103
3182
  return {
3104
3183
  authOptions: buildAuthOptions(userAuthOptions),
@@ -3109,6 +3188,7 @@ function buildClientConfiguration(_a) {
3109
3188
  cryptoInterface: cryptoImplementation || DEFAULT_CRYPTO_IMPLEMENTATION,
3110
3189
  clientCredentials: clientCredentials || DEFAULT_CLIENT_CREDENTIALS,
3111
3190
  libraryInfo: __assign(__assign({}, DEFAULT_LIBRARY_INFO), libraryInfo),
3191
+ telemetry: __assign(__assign({}, DEFAULT_TELEMETRY_OPTIONS), telemetry),
3112
3192
  serverTelemetryManager: serverTelemetryManager || null,
3113
3193
  persistencePlugin: persistencePlugin || null,
3114
3194
  serializableCache: serializableCache || null
@@ -3119,7 +3199,7 @@ function buildClientConfiguration(_a) {
3119
3199
  * @param authOptions
3120
3200
  */
3121
3201
  function buildAuthOptions(authOptions) {
3122
- return __assign({ clientCapabilities: [] }, authOptions);
3202
+ return __assign({ clientCapabilities: [], azureCloudOptions: DEFAULT_AZURE_CLOUD_OPTIONS }, authOptions);
3123
3203
  }
3124
3204
 
3125
3205
  /*
@@ -3221,11 +3301,11 @@ var ThrottlingUtils = /** @class */ (function () {
3221
3301
  authority: request.authority,
3222
3302
  scopes: request.scopes,
3223
3303
  homeAccountIdentifier: homeAccountIdentifier,
3304
+ claims: request.claims,
3224
3305
  authenticationScheme: request.authenticationScheme,
3225
3306
  resourceRequestMethod: request.resourceRequestMethod,
3226
3307
  resourceRequestUri: request.resourceRequestUri,
3227
3308
  shrClaims: request.shrClaims,
3228
- sshJwk: request.sshJwk,
3229
3309
  sshKid: request.sshKid
3230
3310
  };
3231
3311
  var key = this.generateThrottlingStorageKey(thumbprint);
@@ -3353,7 +3433,7 @@ var BaseClient = /** @class */ (function () {
3353
3433
  var response;
3354
3434
  return __generator(this, function (_a) {
3355
3435
  switch (_a.label) {
3356
- case 0: return [4 /*yield*/, this.networkManager.sendPostRequest(thumbprint, tokenEndpoint, { body: queryString, headers: headers })];
3436
+ case 0: return [4 /*yield*/, this.networkManager.sendPostRequest(thumbprint, tokenEndpoint, { body: queryString, headers: headers, proxyUrl: this.config.systemOptions.proxyUrl })];
3357
3437
  case 1:
3358
3438
  response = _a.sent();
3359
3439
  if (this.config.serverTelemetryManager && response.status < 500 && response.status !== 429) {
@@ -3583,8 +3663,24 @@ var RequestParameterBuilder = /** @class */ (function () {
3583
3663
  // Telemetry Info
3584
3664
  this.parameters.set(AADServerParamKeys.X_CLIENT_SKU, libraryInfo.sku);
3585
3665
  this.parameters.set(AADServerParamKeys.X_CLIENT_VER, libraryInfo.version);
3586
- this.parameters.set(AADServerParamKeys.X_CLIENT_OS, libraryInfo.os);
3587
- this.parameters.set(AADServerParamKeys.X_CLIENT_CPU, libraryInfo.cpu);
3666
+ if (libraryInfo.os) {
3667
+ this.parameters.set(AADServerParamKeys.X_CLIENT_OS, libraryInfo.os);
3668
+ }
3669
+ if (libraryInfo.cpu) {
3670
+ this.parameters.set(AADServerParamKeys.X_CLIENT_CPU, libraryInfo.cpu);
3671
+ }
3672
+ };
3673
+ /**
3674
+ * Add client telemetry parameters
3675
+ * @param appTelemetry
3676
+ */
3677
+ RequestParameterBuilder.prototype.addApplicationTelemetry = function (appTelemetry) {
3678
+ if (appTelemetry === null || appTelemetry === void 0 ? void 0 : appTelemetry.appName) {
3679
+ this.parameters.set(AADServerParamKeys.X_APP_NAME, appTelemetry.appName);
3680
+ }
3681
+ if (appTelemetry === null || appTelemetry === void 0 ? void 0 : appTelemetry.appVersion) {
3682
+ this.parameters.set(AADServerParamKeys.X_APP_VER, appTelemetry.appVersion);
3683
+ }
3588
3684
  };
3589
3685
  /**
3590
3686
  * add prompt
@@ -3787,6 +3883,12 @@ var RequestParameterBuilder = /** @class */ (function () {
3787
3883
  RequestParameterBuilder.prototype.addThrottling = function () {
3788
3884
  this.parameters.set(AADServerParamKeys.X_MS_LIB_CAPABILITY, ThrottlingConstants.X_MS_LIB_CAPABILITY_VALUE);
3789
3885
  };
3886
+ /**
3887
+ * Adds logout_hint parameter for "silent" logout which prevent server account picker
3888
+ */
3889
+ RequestParameterBuilder.prototype.addLogoutHint = function (logoutHint) {
3890
+ this.parameters.set(AADServerParamKeys.LOGOUT_HINT, encodeURIComponent(logoutHint));
3891
+ };
3790
3892
  /**
3791
3893
  * Utility to create a URL from the params map
3792
3894
  */
@@ -3956,8 +4058,8 @@ var AccessTokenEntity = /** @class */ (function (_super) {
3956
4058
  * @param expiresOn
3957
4059
  * @param extExpiresOn
3958
4060
  */
3959
- AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion, keyId) {
3960
- var _a;
4061
+ AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion, keyId, requestedClaims, requestedClaimsHash) {
4062
+ var _a, _b;
3961
4063
  var atEntity = new AccessTokenEntity();
3962
4064
  atEntity.homeAccountId = homeAccountId;
3963
4065
  atEntity.credentialType = exports.CredentialType.ACCESS_TOKEN;
@@ -3979,14 +4081,21 @@ var AccessTokenEntity = /** @class */ (function (_super) {
3979
4081
  atEntity.target = scopes;
3980
4082
  atEntity.oboAssertion = oboAssertion;
3981
4083
  atEntity.tokenType = StringUtils.isEmpty(tokenType) ? exports.AuthenticationScheme.BEARER : tokenType;
3982
- // Create Access Token With Auth Scheme instead of regular access token
3983
- if (atEntity.tokenType !== exports.AuthenticationScheme.BEARER) {
4084
+ if (requestedClaims) {
4085
+ atEntity.requestedClaims = requestedClaims;
4086
+ atEntity.requestedClaimsHash = requestedClaimsHash;
4087
+ }
4088
+ /*
4089
+ * Create Access Token With Auth Scheme instead of regular access token
4090
+ * Cast to lower to handle "bearer" from ADFS
4091
+ */
4092
+ if (((_a = atEntity.tokenType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== exports.AuthenticationScheme.BEARER.toLowerCase()) {
3984
4093
  atEntity.credentialType = exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;
3985
4094
  switch (atEntity.tokenType) {
3986
4095
  case exports.AuthenticationScheme.POP:
3987
4096
  // Make sure keyId is present and add it to credential
3988
4097
  var tokenClaims = AuthToken.extractTokenClaims(accessToken, cryptoUtils);
3989
- if (!((_a = tokenClaims === null || tokenClaims === void 0 ? void 0 : tokenClaims.cnf) === null || _a === void 0 ? void 0 : _a.kid)) {
4098
+ if (!((_b = tokenClaims === null || tokenClaims === void 0 ? void 0 : tokenClaims.cnf) === null || _b === void 0 ? void 0 : _b.kid)) {
3990
4099
  throw ClientAuthError.createTokenClaimsRequiredError();
3991
4100
  }
3992
4101
  atEntity.keyId = tokenClaims.cnf.kid;
@@ -4213,11 +4322,11 @@ var ProtocolUtils = /** @class */ (function () {
4213
4322
  // Split the state between library state and user passed state and decode them separately
4214
4323
  var splitState = state.split(Constants.RESOURCE_DELIM);
4215
4324
  var libraryState = splitState[0];
4216
- var userState = splitState.length > 1 ? splitState.slice(1).join(Constants.RESOURCE_DELIM) : "";
4325
+ var userState = splitState.length > 1 ? splitState.slice(1).join(Constants.RESOURCE_DELIM) : Constants.EMPTY_STRING;
4217
4326
  var libraryStateString = cryptoObj.base64Decode(libraryState);
4218
4327
  var libraryStateObj = JSON.parse(libraryStateString);
4219
4328
  return {
4220
- userRequestState: !StringUtils.isEmpty(userState) ? userState : "",
4329
+ userRequestState: !StringUtils.isEmpty(userState) ? userState : Constants.EMPTY_STRING,
4221
4330
  libraryState: libraryStateObj
4222
4331
  };
4223
4332
  }
@@ -4387,7 +4496,7 @@ var UrlString = /** @class */ (function () {
4387
4496
  else if (hashIndex1 > -1) {
4388
4497
  return hashString.substring(hashIndex1 + 1);
4389
4498
  }
4390
- return "";
4499
+ return Constants.EMPTY_STRING;
4391
4500
  };
4392
4501
  UrlString.constructAuthorityUriFromObject = function (urlObject) {
4393
4502
  return new UrlString(urlObject.Protocol + "//" + urlObject.HostNameAndPort + "/" + urlObject.PathSegments.join("/"));
@@ -4491,7 +4600,7 @@ var PopTokenGenerator = /** @class */ (function () {
4491
4600
  resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims, shrNonce = request.shrNonce;
4492
4601
  resourceUrlString = (resourceRequestUri) ? new UrlString(resourceRequestUri) : undefined;
4493
4602
  resourceUrlComponents = resourceUrlString === null || resourceUrlString === void 0 ? void 0 : resourceUrlString.getUrlComponents();
4494
- 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)];
4603
+ 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)];
4495
4604
  case 1: return [2 /*return*/, _a.sent()];
4496
4605
  }
4497
4606
  });
@@ -4684,7 +4793,7 @@ var ResponseHandler = /** @class */ (function () {
4684
4793
  }
4685
4794
  // Add keyId from request to serverTokenResponse if defined
4686
4795
  serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;
4687
- cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, idTokenObj, request.scopes, oboAssertion, authCodePayload);
4796
+ cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload);
4688
4797
  _a.label = 1;
4689
4798
  case 1:
4690
4799
  _a.trys.push([1, , 5, 8]);
@@ -4732,7 +4841,7 @@ var ResponseHandler = /** @class */ (function () {
4732
4841
  * @param idTokenObj
4733
4842
  * @param authority
4734
4843
  */
4735
- ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, idTokenObj, requestScopes, oboAssertion, authCodePayload) {
4844
+ ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload) {
4736
4845
  var env = authority.getPreferredCache();
4737
4846
  if (StringUtils.isEmpty(env)) {
4738
4847
  throw ClientAuthError.createInvalidCacheEnvironmentError();
@@ -4748,7 +4857,7 @@ var ResponseHandler = /** @class */ (function () {
4748
4857
  var cachedAccessToken = null;
4749
4858
  if (!StringUtils.isEmpty(serverTokenResponse.access_token)) {
4750
4859
  // If scopes not returned in server response, use request scopes
4751
- var responseScopes = serverTokenResponse.scope ? ScopeSet.fromString(serverTokenResponse.scope) : new ScopeSet(requestScopes || []);
4860
+ var responseScopes = serverTokenResponse.scope ? ScopeSet.fromString(serverTokenResponse.scope) : new ScopeSet(request.scopes || []);
4752
4861
  /*
4753
4862
  * Use timestamp calculated before request
4754
4863
  * Server may return timestamps as strings, parse to numbers if so.
@@ -4760,7 +4869,7 @@ var ResponseHandler = /** @class */ (function () {
4760
4869
  var extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;
4761
4870
  var refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;
4762
4871
  // non AAD scenarios can have empty realm
4763
- cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.access_token || Constants.EMPTY_STRING, this.clientId, idTokenObj ? idTokenObj.claims.tid || Constants.EMPTY_STRING : authority.tenant, responseScopes.printScopes(), tokenExpirationSeconds, extendedTokenExpirationSeconds, this.cryptoObj, refreshOnSeconds, serverTokenResponse.token_type, oboAssertion, serverTokenResponse.key_id);
4872
+ cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.access_token || Constants.EMPTY_STRING, this.clientId, idTokenObj ? idTokenObj.claims.tid || Constants.EMPTY_STRING : authority.tenant, responseScopes.printScopes(), tokenExpirationSeconds, extendedTokenExpirationSeconds, this.cryptoObj, refreshOnSeconds, serverTokenResponse.token_type, oboAssertion, serverTokenResponse.key_id, request.claims, request.requestedClaimsHash);
4764
4873
  }
4765
4874
  // refreshToken
4766
4875
  var cachedRefreshToken = null;
@@ -4782,8 +4891,8 @@ var ResponseHandler = /** @class */ (function () {
4782
4891
  */
4783
4892
  ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, oboAssertion, authCodePayload) {
4784
4893
  var authorityType = authority.authorityType;
4785
- var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : "";
4786
- var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : "";
4894
+ var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : Constants.EMPTY_STRING;
4895
+ var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : Constants.EMPTY_STRING;
4787
4896
  // ADFS does not require client_info in the response
4788
4897
  if (authorityType === exports.AuthorityType.Adfs) {
4789
4898
  this.logger.verbose("Authority type is ADFS, creating ADFS account");
@@ -4814,7 +4923,7 @@ var ResponseHandler = /** @class */ (function () {
4814
4923
  return __generator(this, function (_d) {
4815
4924
  switch (_d.label) {
4816
4925
  case 0:
4817
- accessToken = "";
4926
+ accessToken = Constants.EMPTY_STRING;
4818
4927
  responseScopes = [];
4819
4928
  expiresOn = null;
4820
4929
  familyId = Constants.EMPTY_STRING;
@@ -4979,11 +5088,11 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
4979
5088
  clientId: this.config.authOptions.clientId,
4980
5089
  authority: authority.canonicalAuthority,
4981
5090
  scopes: request.scopes,
5091
+ claims: request.claims,
4982
5092
  authenticationScheme: request.authenticationScheme,
4983
5093
  resourceRequestMethod: request.resourceRequestMethod,
4984
5094
  resourceRequestUri: request.resourceRequestUri,
4985
5095
  shrClaims: request.shrClaims,
4986
- sshJwk: request.sshJwk,
4987
5096
  sshKid: request.sshKid
4988
5097
  };
4989
5098
  return [4 /*yield*/, this.createTokenRequestBody(request)];
@@ -5052,6 +5161,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5052
5161
  parameterBuilder.addAuthorizationCode(request.code);
5053
5162
  // Add library metadata
5054
5163
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5164
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5055
5165
  parameterBuilder.addThrottling();
5056
5166
  if (this.serverTelemetryManager) {
5057
5167
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -5160,6 +5270,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5160
5270
  parameterBuilder.addResponseTypeCode();
5161
5271
  // add library info parameters
5162
5272
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5273
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5163
5274
  // add client_info=1
5164
5275
  parameterBuilder.addClientInfo();
5165
5276
  if (request.codeChallenge && request.codeChallengeMethod) {
@@ -5253,6 +5364,9 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5253
5364
  if (request.state) {
5254
5365
  parameterBuilder.addState(request.state);
5255
5366
  }
5367
+ if (request.logoutHint) {
5368
+ parameterBuilder.addLogoutHint(request.logoutHint);
5369
+ }
5256
5370
  if (request.extraQueryParameters) {
5257
5371
  parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
5258
5372
  }
@@ -5325,11 +5439,11 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5325
5439
  clientId: this.config.authOptions.clientId,
5326
5440
  authority: request.authority,
5327
5441
  scopes: request.scopes,
5442
+ claims: request.claims,
5328
5443
  authenticationScheme: request.authenticationScheme,
5329
5444
  resourceRequestMethod: request.resourceRequestMethod,
5330
5445
  resourceRequestUri: request.resourceRequestUri,
5331
5446
  shrClaims: request.shrClaims,
5332
- sshJwk: request.sshJwk,
5333
5447
  sshKid: request.sshKid
5334
5448
  };
5335
5449
  return [2 /*return*/, this.executePostRequestToDeviceCodeEndpoint(this.authority.deviceCodeEndpoint, queryString, headers, thumbprint)];
@@ -5349,7 +5463,8 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5349
5463
  switch (_b.label) {
5350
5464
  case 0: return [4 /*yield*/, this.networkManager.sendPostRequest(thumbprint, deviceCodeEndpoint, {
5351
5465
  body: queryString,
5352
- headers: headers
5466
+ headers: headers,
5467
+ proxyUrl: this.config.systemOptions.proxyUrl
5353
5468
  })];
5354
5469
  case 1:
5355
5470
  _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;
@@ -5424,11 +5539,11 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5424
5539
  clientId: this.config.authOptions.clientId,
5425
5540
  authority: request.authority,
5426
5541
  scopes: request.scopes,
5542
+ claims: request.claims,
5427
5543
  authenticationScheme: request.authenticationScheme,
5428
5544
  resourceRequestMethod: request.resourceRequestMethod,
5429
5545
  resourceRequestUri: request.resourceRequestUri,
5430
5546
  shrClaims: request.shrClaims,
5431
- sshJwk: request.sshJwk,
5432
5547
  sshKid: request.sshKid
5433
5548
  };
5434
5549
  return [4 /*yield*/, this.executePostToTokenEndpoint(this.authority.tokenEndpoint, requestBody, headers, thumbprint)];
@@ -5471,6 +5586,7 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5471
5586
  requestParameters.addCorrelationId(correlationId);
5472
5587
  requestParameters.addClientInfo();
5473
5588
  requestParameters.addLibraryInfo(this.config.libraryInfo);
5589
+ requestParameters.addApplicationTelemetry(this.config.telemetry.application);
5474
5590
  requestParameters.addThrottling();
5475
5591
  if (this.serverTelemetryManager) {
5476
5592
  requestParameters.addServerTelemetry(this.serverTelemetryManager);
@@ -5592,11 +5708,11 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5592
5708
  clientId: this.config.authOptions.clientId,
5593
5709
  authority: authority.canonicalAuthority,
5594
5710
  scopes: request.scopes,
5711
+ claims: request.claims,
5595
5712
  authenticationScheme: request.authenticationScheme,
5596
5713
  resourceRequestMethod: request.resourceRequestMethod,
5597
5714
  resourceRequestUri: request.resourceRequestUri,
5598
5715
  shrClaims: request.shrClaims,
5599
- sshJwk: request.sshJwk,
5600
5716
  sshKid: request.sshKid
5601
5717
  };
5602
5718
  endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParameters);
@@ -5632,6 +5748,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5632
5748
  parameterBuilder.addGrantType(GrantType.REFRESH_TOKEN_GRANT);
5633
5749
  parameterBuilder.addClientInfo();
5634
5750
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5751
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5635
5752
  parameterBuilder.addThrottling();
5636
5753
  if (this.serverTelemetryManager) {
5637
5754
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -5766,7 +5883,7 @@ var ClientCredentialClient = /** @class */ (function (_super) {
5766
5883
  */
5767
5884
  ClientCredentialClient.prototype.readAccessTokenFromCache = function () {
5768
5885
  var accessTokenFilter = {
5769
- homeAccountId: "",
5886
+ homeAccountId: Constants.EMPTY_STRING,
5770
5887
  environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
5771
5888
  credentialType: exports.CredentialType.ACCESS_TOKEN,
5772
5889
  clientId: this.config.authOptions.clientId,
@@ -5800,11 +5917,11 @@ var ClientCredentialClient = /** @class */ (function (_super) {
5800
5917
  clientId: this.config.authOptions.clientId,
5801
5918
  authority: request.authority,
5802
5919
  scopes: request.scopes,
5920
+ claims: request.claims,
5803
5921
  authenticationScheme: request.authenticationScheme,
5804
5922
  resourceRequestMethod: request.resourceRequestMethod,
5805
5923
  resourceRequestUri: request.resourceRequestUri,
5806
5924
  shrClaims: request.shrClaims,
5807
- sshJwk: request.sshJwk,
5808
5925
  sshKid: request.sshKid
5809
5926
  };
5810
5927
  reqTimestamp = TimeUtils.nowSeconds();
@@ -5831,6 +5948,7 @@ var ClientCredentialClient = /** @class */ (function (_super) {
5831
5948
  parameterBuilder.addScopes(request.scopes, false);
5832
5949
  parameterBuilder.addGrantType(GrantType.CLIENT_CREDENTIALS_GRANT);
5833
5950
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5951
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5834
5952
  parameterBuilder.addThrottling();
5835
5953
  if (this.serverTelemetryManager) {
5836
5954
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -5918,7 +6036,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
5918
6036
  environment: cachedIdToken.environment,
5919
6037
  tenantId: cachedIdToken.realm,
5920
6038
  username: Constants.EMPTY_STRING,
5921
- localAccountId: localAccountId || ""
6039
+ localAccountId: localAccountId || Constants.EMPTY_STRING
5922
6040
  };
5923
6041
  cachedAccount = this.readAccountFromCache(accountInfo);
5924
6042
  }
@@ -6001,11 +6119,11 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6001
6119
  clientId: this.config.authOptions.clientId,
6002
6120
  authority: request.authority,
6003
6121
  scopes: request.scopes,
6122
+ claims: request.claims,
6004
6123
  authenticationScheme: request.authenticationScheme,
6005
6124
  resourceRequestMethod: request.resourceRequestMethod,
6006
6125
  resourceRequestUri: request.resourceRequestUri,
6007
6126
  shrClaims: request.shrClaims,
6008
- sshJwk: request.sshJwk,
6009
6127
  sshKid: request.sshKid
6010
6128
  };
6011
6129
  reqTimestamp = TimeUtils.nowSeconds();
@@ -6033,6 +6151,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6033
6151
  parameterBuilder.addGrantType(GrantType.JWT_BEARER);
6034
6152
  parameterBuilder.addClientInfo();
6035
6153
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6154
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
6036
6155
  parameterBuilder.addThrottling();
6037
6156
  if (this.serverTelemetryManager) {
6038
6157
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -6098,7 +6217,7 @@ var SilentFlowClient = /** @class */ (function (_super) {
6098
6217
  SilentFlowClient.prototype.acquireCachedToken = function (request) {
6099
6218
  var _a, _b, _c, _d;
6100
6219
  return __awaiter(this, void 0, void 0, function () {
6101
- var requestScopes, environment, authScheme, cacheRecord;
6220
+ var environment, cacheRecord;
6102
6221
  return __generator(this, function (_e) {
6103
6222
  switch (_e.label) {
6104
6223
  case 0:
@@ -6112,19 +6231,12 @@ var SilentFlowClient = /** @class */ (function (_super) {
6112
6231
  this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because forceRefresh is true.");
6113
6232
  throw ClientAuthError.createRefreshRequiredError();
6114
6233
  }
6115
- else if (!StringUtils.isEmptyObj(request.claims)) {
6116
- // Must refresh due to request parameters.
6117
- this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because claims are requested.");
6118
- throw ClientAuthError.createRefreshRequiredError();
6119
- }
6120
6234
  // We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
6121
6235
  if (!request.account) {
6122
6236
  throw ClientAuthError.createNoAccountInSilentRequestError();
6123
6237
  }
6124
- requestScopes = new ScopeSet(request.scopes || []);
6125
6238
  environment = request.authority || this.authority.getPreferredCache();
6126
- authScheme = request.authenticationScheme || exports.AuthenticationScheme.BEARER;
6127
- cacheRecord = this.cacheManager.readCacheRecord(request.account, this.config.authOptions.clientId, requestScopes, environment, authScheme, request.sshKid);
6239
+ cacheRecord = this.cacheManager.readCacheRecord(request.account, this.config.authOptions.clientId, request, environment);
6128
6240
  if (!cacheRecord.accessToken) {
6129
6241
  // Must refresh due to non-existent access_token.
6130
6242
  (_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
@@ -6226,11 +6338,11 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6226
6338
  clientId: this.config.authOptions.clientId,
6227
6339
  authority: authority.canonicalAuthority,
6228
6340
  scopes: request.scopes,
6341
+ claims: request.claims,
6229
6342
  authenticationScheme: request.authenticationScheme,
6230
6343
  resourceRequestMethod: request.resourceRequestMethod,
6231
6344
  resourceRequestUri: request.resourceRequestUri,
6232
6345
  shrClaims: request.shrClaims,
6233
- sshJwk: request.sshJwk,
6234
6346
  sshKid: request.sshKid
6235
6347
  };
6236
6348
  requestBody = this.createTokenRequestBody(request);
@@ -6255,6 +6367,7 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6255
6367
  parameterBuilder.addGrantType(GrantType.RESOURCE_OWNER_PASSWORD_GRANT);
6256
6368
  parameterBuilder.addClientInfo();
6257
6369
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6370
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
6258
6371
  parameterBuilder.addThrottling();
6259
6372
  if (this.serverTelemetryManager) {
6260
6373
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -6398,18 +6511,22 @@ var RegionDiscovery = /** @class */ (function () {
6398
6511
  *
6399
6512
  * @returns Promise<string | null>
6400
6513
  */
6401
- RegionDiscovery.prototype.detectRegion = function (environmentRegion, regionDiscoveryMetadata) {
6514
+ RegionDiscovery.prototype.detectRegion = function (environmentRegion, regionDiscoveryMetadata, proxyUrl) {
6402
6515
  return __awaiter(this, void 0, void 0, function () {
6403
- var autodetectedRegionName, localIMDSVersionResponse, currentIMDSVersion, currentIMDSVersionResponse;
6516
+ var autodetectedRegionName, options, localIMDSVersionResponse, currentIMDSVersion, currentIMDSVersionResponse;
6404
6517
  return __generator(this, function (_a) {
6405
6518
  switch (_a.label) {
6406
6519
  case 0:
6407
6520
  autodetectedRegionName = environmentRegion;
6408
6521
  if (!!autodetectedRegionName) return [3 /*break*/, 8];
6522
+ options = RegionDiscovery.IMDS_OPTIONS;
6523
+ if (proxyUrl) {
6524
+ options.proxyUrl = proxyUrl;
6525
+ }
6409
6526
  _a.label = 1;
6410
6527
  case 1:
6411
6528
  _a.trys.push([1, 6, , 7]);
6412
- return [4 /*yield*/, this.getRegionFromIMDS(Constants.IMDS_VERSION)];
6529
+ return [4 /*yield*/, this.getRegionFromIMDS(Constants.IMDS_VERSION, options)];
6413
6530
  case 2:
6414
6531
  localIMDSVersionResponse = _a.sent();
6415
6532
  if (localIMDSVersionResponse.status === ResponseCodes.httpSuccess) {
@@ -6417,14 +6534,14 @@ var RegionDiscovery = /** @class */ (function () {
6417
6534
  regionDiscoveryMetadata.region_source = RegionDiscoverySources.IMDS;
6418
6535
  }
6419
6536
  if (!(localIMDSVersionResponse.status === ResponseCodes.httpBadRequest)) return [3 /*break*/, 5];
6420
- return [4 /*yield*/, this.getCurrentVersion()];
6537
+ return [4 /*yield*/, this.getCurrentVersion(options)];
6421
6538
  case 3:
6422
6539
  currentIMDSVersion = _a.sent();
6423
6540
  if (!currentIMDSVersion) {
6424
6541
  regionDiscoveryMetadata.region_source = RegionDiscoverySources.FAILED_AUTO_DETECTION;
6425
6542
  return [2 /*return*/, null];
6426
6543
  }
6427
- return [4 /*yield*/, this.getRegionFromIMDS(currentIMDSVersion)];
6544
+ return [4 /*yield*/, this.getRegionFromIMDS(currentIMDSVersion, options)];
6428
6545
  case 4:
6429
6546
  currentIMDSVersionResponse = _a.sent();
6430
6547
  if (currentIMDSVersionResponse.status === ResponseCodes.httpSuccess) {
@@ -6457,10 +6574,10 @@ var RegionDiscovery = /** @class */ (function () {
6457
6574
  * @param imdsEndpointUrl
6458
6575
  * @returns Promise<NetworkResponse<string>>
6459
6576
  */
6460
- RegionDiscovery.prototype.getRegionFromIMDS = function (version) {
6577
+ RegionDiscovery.prototype.getRegionFromIMDS = function (version, options) {
6461
6578
  return __awaiter(this, void 0, void 0, function () {
6462
6579
  return __generator(this, function (_a) {
6463
- return [2 /*return*/, this.networkInterface.sendGetRequestAsync(Constants.IMDS_ENDPOINT + "?api-version=" + version + "&format=text", RegionDiscovery.IMDS_OPTIONS, Constants.IMDS_TIMEOUT)];
6580
+ return [2 /*return*/, this.networkInterface.sendGetRequestAsync(Constants.IMDS_ENDPOINT + "?api-version=" + version + "&format=text", options, Constants.IMDS_TIMEOUT)];
6464
6581
  });
6465
6582
  });
6466
6583
  };
@@ -6469,14 +6586,14 @@ var RegionDiscovery = /** @class */ (function () {
6469
6586
  *
6470
6587
  * @returns Promise<string | null>
6471
6588
  */
6472
- RegionDiscovery.prototype.getCurrentVersion = function () {
6589
+ RegionDiscovery.prototype.getCurrentVersion = function (options) {
6473
6590
  return __awaiter(this, void 0, void 0, function () {
6474
6591
  var response;
6475
6592
  return __generator(this, function (_a) {
6476
6593
  switch (_a.label) {
6477
6594
  case 0:
6478
6595
  _a.trys.push([0, 2, , 3]);
6479
- return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(Constants.IMDS_ENDPOINT + "?format=json", RegionDiscovery.IMDS_OPTIONS)];
6596
+ return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(Constants.IMDS_ENDPOINT + "?format=json", options)];
6480
6597
  case 1:
6481
6598
  response = _a.sent();
6482
6599
  // When IMDS endpoint is called without the api version query param, bad request response comes back with latest version.
@@ -6493,7 +6610,11 @@ var RegionDiscovery = /** @class */ (function () {
6493
6610
  });
6494
6611
  };
6495
6612
  // Options for the IMDS endpoint request
6496
- RegionDiscovery.IMDS_OPTIONS = { headers: { "Metadata": "true" } };
6613
+ RegionDiscovery.IMDS_OPTIONS = {
6614
+ headers: {
6615
+ Metadata: "true",
6616
+ },
6617
+ };
6497
6618
  return RegionDiscovery;
6498
6619
  }());
6499
6620
 
@@ -6506,7 +6627,7 @@ var RegionDiscovery = /** @class */ (function () {
6506
6627
  * endpoint. It will store the pertinent config data in this object for use during token calls.
6507
6628
  */
6508
6629
  var Authority = /** @class */ (function () {
6509
- function Authority(authority, networkInterface, cacheManager, authorityOptions) {
6630
+ function Authority(authority, networkInterface, cacheManager, authorityOptions, proxyUrl) {
6510
6631
  this.canonicalAuthority = authority;
6511
6632
  this._canonicalAuthority.validateAsUri();
6512
6633
  this.networkInterface = networkInterface;
@@ -6514,6 +6635,7 @@ var Authority = /** @class */ (function () {
6514
6635
  this.authorityOptions = authorityOptions;
6515
6636
  this.regionDiscovery = new RegionDiscovery(networkInterface);
6516
6637
  this.regionDiscoveryMetadata = { region_used: undefined, region_source: undefined, region_outcome: undefined };
6638
+ this.proxyUrl = proxyUrl || Constants.EMPTY_STRING;
6517
6639
  }
6518
6640
  Object.defineProperty(Authority.prototype, "authorityType", {
6519
6641
  // See above for AuthorityType
@@ -6782,7 +6904,7 @@ var Authority = /** @class */ (function () {
6782
6904
  metadata = _b.sent();
6783
6905
  if (!metadata) return [3 /*break*/, 4];
6784
6906
  if (!((_a = this.authorityOptions.azureRegionConfiguration) === null || _a === void 0 ? void 0 : _a.azureRegion)) return [3 /*break*/, 3];
6785
- return [4 /*yield*/, this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration.environmentRegion, this.regionDiscoveryMetadata)];
6907
+ return [4 /*yield*/, this.regionDiscovery.detectRegion(this.authorityOptions.azureRegionConfiguration.environmentRegion, this.regionDiscoveryMetadata, this.proxyUrl)];
6786
6908
  case 2:
6787
6909
  autodetectedRegionName = _b.sent();
6788
6910
  azureRegion = this.authorityOptions.azureRegionConfiguration.azureRegion === Constants.AZURE_REGION_AUTO_DISCOVER_FLAG
@@ -6845,19 +6967,25 @@ var Authority = /** @class */ (function () {
6845
6967
  */
6846
6968
  Authority.prototype.getEndpointMetadataFromNetwork = function () {
6847
6969
  return __awaiter(this, void 0, void 0, function () {
6848
- var response;
6970
+ var options, response;
6849
6971
  return __generator(this, function (_a) {
6850
6972
  switch (_a.label) {
6851
6973
  case 0:
6852
- _a.trys.push([0, 2, , 3]);
6853
- return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(this.defaultOpenIdConfigurationEndpoint)];
6974
+ options = {};
6975
+ if (this.proxyUrl) {
6976
+ options.proxyUrl = this.proxyUrl;
6977
+ }
6978
+ _a.label = 1;
6854
6979
  case 1:
6980
+ _a.trys.push([1, 3, , 4]);
6981
+ return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(this.defaultOpenIdConfigurationEndpoint, options)];
6982
+ case 2:
6855
6983
  response = _a.sent();
6856
6984
  return [2 /*return*/, isOpenIdConfigResponse(response.body) ? response.body : null];
6857
- case 2:
6985
+ case 3:
6858
6986
  _a.sent();
6859
6987
  return [2 /*return*/, null];
6860
- case 3: return [2 /*return*/];
6988
+ case 4: return [2 /*return*/];
6861
6989
  }
6862
6990
  });
6863
6991
  });
@@ -6927,16 +7055,20 @@ var Authority = /** @class */ (function () {
6927
7055
  */
6928
7056
  Authority.prototype.getCloudDiscoveryMetadataFromNetwork = function () {
6929
7057
  return __awaiter(this, void 0, void 0, function () {
6930
- var instanceDiscoveryEndpoint, match, response, metadata;
7058
+ var instanceDiscoveryEndpoint, options, match, response, metadata;
6931
7059
  return __generator(this, function (_a) {
6932
7060
  switch (_a.label) {
6933
7061
  case 0:
6934
7062
  instanceDiscoveryEndpoint = "" + Constants.AAD_INSTANCE_DISCOVERY_ENDPT + this.canonicalAuthority + "oauth2/v2.0/authorize";
7063
+ options = {};
7064
+ if (this.proxyUrl) {
7065
+ options.proxyUrl = this.proxyUrl;
7066
+ }
6935
7067
  match = null;
6936
7068
  _a.label = 1;
6937
7069
  case 1:
6938
7070
  _a.trys.push([1, 3, , 4]);
6939
- return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(instanceDiscoveryEndpoint)];
7071
+ return [4 /*yield*/, this.networkInterface.sendGetRequestAsync(instanceDiscoveryEndpoint, options)];
6940
7072
  case 2:
6941
7073
  response = _a.sent();
6942
7074
  metadata = isCloudInstanceDiscoveryResponse(response.body) ? response.body.metadata : [];
@@ -6951,7 +7083,7 @@ var Authority = /** @class */ (function () {
6951
7083
  return [2 /*return*/, null];
6952
7084
  case 4:
6953
7085
  if (!match) {
6954
- // Custom Domain scenario, host is trusted because Instance Discovery call succeeded
7086
+ // Custom Domain scenario, host is trusted because Instance Discovery call succeeded
6955
7087
  match = Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
6956
7088
  }
6957
7089
  return [2 /*return*/, match];
@@ -6969,6 +7101,19 @@ var Authority = /** @class */ (function () {
6969
7101
  });
6970
7102
  return matches.length > 0;
6971
7103
  };
7104
+ /**
7105
+ * helper function to populate the authority based on azureCloudOptions
7106
+ * @param authorityString
7107
+ * @param azureCloudOptions
7108
+ */
7109
+ Authority.generateAuthority = function (authorityString, azureCloudOptions) {
7110
+ var authorityAzureCloudInstance;
7111
+ if (azureCloudOptions && azureCloudOptions.azureCloudInstance !== exports.AzureCloudInstance.None) {
7112
+ var tenant = azureCloudOptions.tenant ? azureCloudOptions.tenant : Constants.DEFAULT_COMMON_TENANT;
7113
+ authorityAzureCloudInstance = azureCloudOptions.azureCloudInstance + "/" + tenant + "/";
7114
+ }
7115
+ return authorityAzureCloudInstance ? authorityAzureCloudInstance : authorityString;
7116
+ };
6972
7117
  /**
6973
7118
  * Creates cloud discovery metadata object from a given host
6974
7119
  * @param host
@@ -7078,13 +7223,13 @@ var AuthorityFactory = /** @class */ (function () {
7078
7223
  * @param networkClient
7079
7224
  * @param protocolMode
7080
7225
  */
7081
- AuthorityFactory.createDiscoveredInstance = function (authorityUri, networkClient, cacheManager, authorityOptions) {
7226
+ AuthorityFactory.createDiscoveredInstance = function (authorityUri, networkClient, cacheManager, authorityOptions, proxyUrl) {
7082
7227
  return __awaiter(this, void 0, void 0, function () {
7083
7228
  var acquireTokenAuthority, e_1;
7084
7229
  return __generator(this, function (_a) {
7085
7230
  switch (_a.label) {
7086
7231
  case 0:
7087
- acquireTokenAuthority = AuthorityFactory.createInstance(authorityUri, networkClient, cacheManager, authorityOptions);
7232
+ acquireTokenAuthority = AuthorityFactory.createInstance(authorityUri, networkClient, cacheManager, authorityOptions, proxyUrl);
7088
7233
  _a.label = 1;
7089
7234
  case 1:
7090
7235
  _a.trys.push([1, 3, , 4]);
@@ -7110,12 +7255,12 @@ var AuthorityFactory = /** @class */ (function () {
7110
7255
  * @param networkInterface
7111
7256
  * @param protocolMode
7112
7257
  */
7113
- AuthorityFactory.createInstance = function (authorityUrl, networkInterface, cacheManager, authorityOptions) {
7258
+ AuthorityFactory.createInstance = function (authorityUrl, networkInterface, cacheManager, authorityOptions, proxyUrl) {
7114
7259
  // Throw error if authority url is empty
7115
7260
  if (StringUtils.isEmpty(authorityUrl)) {
7116
7261
  throw ClientConfigurationError.createUrlEmptyError();
7117
7262
  }
7118
- return new Authority(authorityUrl, networkInterface, cacheManager, authorityOptions);
7263
+ return new Authority(authorityUrl, networkInterface, cacheManager, authorityOptions, proxyUrl);
7119
7264
  };
7120
7265
  return AuthorityFactory;
7121
7266
  }());
@@ -7240,7 +7385,7 @@ var AuthenticationHeaderParser = /** @class */ (function () {
7240
7385
  challenges.forEach(function (challenge) {
7241
7386
  var _a = challenge.split("="), key = _a[0], value = _a[1];
7242
7387
  // Remove escaped quotation marks (', ") from challenge string to keep only the challenge value
7243
- challengeMap[key] = unescape(value.replace(/['"]+/g, ""));
7388
+ challengeMap[key] = unescape(value.replace(/['"]+/g, Constants.EMPTY_STRING));
7244
7389
  });
7245
7390
  return challengeMap;
7246
7391
  };
@@ -7382,9 +7527,9 @@ var ServerTelemetryManager = /** @class */ (function () {
7382
7527
  */
7383
7528
  ServerTelemetryManager.prototype.getRegionDiscoveryFields = function () {
7384
7529
  var regionDiscoveryFields = [];
7385
- regionDiscoveryFields.push(this.regionUsed || "");
7386
- regionDiscoveryFields.push(this.regionSource || "");
7387
- regionDiscoveryFields.push(this.regionOutcome || "");
7530
+ regionDiscoveryFields.push(this.regionUsed || Constants.EMPTY_STRING);
7531
+ regionDiscoveryFields.push(this.regionSource || Constants.EMPTY_STRING);
7532
+ regionDiscoveryFields.push(this.regionOutcome || Constants.EMPTY_STRING);
7388
7533
  return regionDiscoveryFields.join(",");
7389
7534
  };
7390
7535
  /**
@@ -7407,6 +7552,385 @@ var ServerTelemetryManager = /** @class */ (function () {
7407
7552
  return ServerTelemetryManager;
7408
7553
  }());
7409
7554
 
7555
+ /*
7556
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7557
+ * Licensed under the MIT License.
7558
+ */
7559
+ /**
7560
+ * Enumeration of operations that are instrumented by have their performance measured by the PerformanceClient.
7561
+ *
7562
+ * @export
7563
+ * @enum {number}
7564
+ */
7565
+ exports.PerformanceEvents = void 0;
7566
+ (function (PerformanceEvents) {
7567
+ /**
7568
+ * acquireTokenByCode API (msal-browser and msal-node).
7569
+ * Used to acquire tokens by trading an authorization code against the token endpoint.
7570
+ */
7571
+ PerformanceEvents["AcquireTokenByCode"] = "acquireTokenByCode";
7572
+ /**
7573
+ * acquireTokenByRefreshToken API (msal-browser and msal-node).
7574
+ * Used to renew an access token using a refresh token against the token endpoint.
7575
+ */
7576
+ PerformanceEvents["AcquireTokenByRefreshToken"] = "acquireTokenByRefreshToken";
7577
+ /**
7578
+ * acquireTokenSilent API (msal-browser and msal-node).
7579
+ * Used to silently acquire a new access token (from the cache or the network).
7580
+ */
7581
+ PerformanceEvents["AcquireTokenSilent"] = "acquireTokenSilent";
7582
+ /**
7583
+ * acquireTokenSilentAsync (msal-browser).
7584
+ * Internal API for acquireTokenSilent.
7585
+ */
7586
+ PerformanceEvents["AcquireTokenSilentAsync"] = "acquireTokenSilentAsync";
7587
+ /**
7588
+ * getPublicKeyThumbprint API in CryptoOpts class (msal-browser).
7589
+ * Used to generate a public/private keypair and generate a public key thumbprint for pop requests.
7590
+ */
7591
+ PerformanceEvents["CryptoOptsGetPublicKeyThumbprint"] = "cryptoOptsGetPublicKeyThumbprint";
7592
+ /**
7593
+ * signJwt API in CryptoOpts class (msal-browser).
7594
+ * Used to signed a pop token.
7595
+ */
7596
+ PerformanceEvents["CryptoOptsSignJwt"] = "cryptoOptsSignJwt";
7597
+ /**
7598
+ * acquireToken API in the SilentCacheClient class (msal-browser).
7599
+ * Used to read access tokens from the cache.
7600
+ */
7601
+ PerformanceEvents["SilentCacheClientAcquireToken"] = "silentCacheClientAcquireToken";
7602
+ /**
7603
+ * acquireToken API in the SilentIframeClient class (msal-browser).
7604
+ * Used to acquire a new set of tokens from the authorize endpoint in a hidden iframe.
7605
+ */
7606
+ PerformanceEvents["SilentIframeClientAcquireToken"] = "silentIframeClientAcquireToken";
7607
+ /**
7608
+ * acquireToken API in SilentRereshClient (msal-browser).
7609
+ * Used to acquire a new set of tokens from the token endpoint using a refresh token.
7610
+ */
7611
+ PerformanceEvents["SilentRefreshClientAcquireToken"] = "silentRefreshClientAcquireToken";
7612
+ /**
7613
+ * ssoSilent API (msal-browser).
7614
+ * Used to silently acquire an authorization code and set of tokens using a hidden iframe.
7615
+ */
7616
+ PerformanceEvents["SsoSilent"] = "ssoSilent";
7617
+ /**
7618
+ * getDiscoveredAuthority API in StandardInteractionClient class (msal-browser).
7619
+ * Used to load authority metadata for a request.
7620
+ */
7621
+ PerformanceEvents["StandardInteractionClientGetDiscoveredAuthority"] = "standardInteractionClientGetDiscoveredAuthority";
7622
+ })(exports.PerformanceEvents || (exports.PerformanceEvents = {}));
7623
+ /**
7624
+ * State of the performance event.
7625
+ *
7626
+ * @export
7627
+ * @enum {number}
7628
+ */
7629
+ exports.PerformanceEventStatus = void 0;
7630
+ (function (PerformanceEventStatus) {
7631
+ PerformanceEventStatus[PerformanceEventStatus["NotStarted"] = 0] = "NotStarted";
7632
+ PerformanceEventStatus[PerformanceEventStatus["InProgress"] = 1] = "InProgress";
7633
+ PerformanceEventStatus[PerformanceEventStatus["Completed"] = 2] = "Completed";
7634
+ })(exports.PerformanceEventStatus || (exports.PerformanceEventStatus = {}));
7635
+
7636
+ /*
7637
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7638
+ * Licensed under the MIT License.
7639
+ */
7640
+ var PerformanceClient = /** @class */ (function () {
7641
+ /**
7642
+ * Creates an instance of PerformanceClient,
7643
+ * an abstract class containing core performance telemetry logic.
7644
+ *
7645
+ * @constructor
7646
+ * @param {string} clientId Client ID of the application
7647
+ * @param {string} authority Authority used by the application
7648
+ * @param {Logger} logger Logger used by the application
7649
+ * @param {string} libraryName Name of the library
7650
+ * @param {string} libraryVersion Version of the library
7651
+ */
7652
+ function PerformanceClient(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry) {
7653
+ this.authority = authority;
7654
+ this.libraryName = libraryName;
7655
+ this.libraryVersion = libraryVersion;
7656
+ this.applicationTelemetry = applicationTelemetry;
7657
+ this.clientId = clientId;
7658
+ this.logger = logger;
7659
+ this.callbacks = new Map();
7660
+ this.eventsByCorrelationId = new Map();
7661
+ this.measurementsById = new Map();
7662
+ }
7663
+ /**
7664
+ * Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.
7665
+ *
7666
+ * @param {PerformanceEvents} measureName
7667
+ * @param {?string} [correlationId]
7668
+ * @returns {InProgressPerformanceEvent}
7669
+ */
7670
+ PerformanceClient.prototype.startMeasurement = function (measureName, correlationId) {
7671
+ var _this = this;
7672
+ var _a, _b;
7673
+ // Generate a placeholder correlation if the request does not provide one
7674
+ var eventCorrelationId = correlationId || this.generateId();
7675
+ if (!correlationId) {
7676
+ this.logger.info("PerformanceClient: No correlation id provided for " + measureName + ", generating", eventCorrelationId);
7677
+ }
7678
+ this.logger.trace("PerformanceClient: Performance measurement started for " + measureName, eventCorrelationId);
7679
+ var performanceMeasurement = this.startPerformanceMeasuremeant(measureName, eventCorrelationId);
7680
+ performanceMeasurement.startMeasurement();
7681
+ var inProgressEvent = {
7682
+ eventId: this.generateId(),
7683
+ status: exports.PerformanceEventStatus.InProgress,
7684
+ authority: this.authority,
7685
+ libraryName: this.libraryName,
7686
+ libraryVersion: this.libraryVersion,
7687
+ appName: (_a = this.applicationTelemetry) === null || _a === void 0 ? void 0 : _a.appName,
7688
+ appVersion: (_b = this.applicationTelemetry) === null || _b === void 0 ? void 0 : _b.appVersion,
7689
+ clientId: this.clientId,
7690
+ name: measureName,
7691
+ startTimeMs: Date.now(),
7692
+ correlationId: eventCorrelationId
7693
+ };
7694
+ // Store in progress events so they can be discarded if not ended properly
7695
+ this.cacheEventByCorrelationId(inProgressEvent);
7696
+ this.cacheMeasurement(inProgressEvent, performanceMeasurement);
7697
+ // Return the event and functions the caller can use to properly end/flush the measurement
7698
+ return {
7699
+ endMeasurement: function (event) {
7700
+ var completedEvent = _this.endMeasurement(__assign(__assign({}, inProgressEvent), event));
7701
+ if (completedEvent) {
7702
+ // Cache event so that submeasurements can be added downstream
7703
+ _this.cacheEventByCorrelationId(completedEvent);
7704
+ }
7705
+ return completedEvent;
7706
+ },
7707
+ flushMeasurement: function () {
7708
+ return _this.flushMeasurements(inProgressEvent.name, inProgressEvent.correlationId);
7709
+ },
7710
+ discardMeasurement: function () {
7711
+ return _this.discardMeasurements(inProgressEvent.correlationId);
7712
+ },
7713
+ measurement: performanceMeasurement,
7714
+ event: inProgressEvent
7715
+ };
7716
+ };
7717
+ /**
7718
+ * Stops measuring the performance for an operation. Should only be called directly by PerformanceClient classes,
7719
+ * as consumers should instead use the function returned by startMeasurement.
7720
+ *
7721
+ * @param {PerformanceEvent} event
7722
+ * @returns {(PerformanceEvent | null)}
7723
+ */
7724
+ PerformanceClient.prototype.endMeasurement = function (event) {
7725
+ var performanceMeasurement = this.measurementsById.get(event.eventId);
7726
+ if (performanceMeasurement) {
7727
+ // Immediately delete so that the same event isnt ended twice
7728
+ this.measurementsById.delete(event.eventId);
7729
+ performanceMeasurement.endMeasurement();
7730
+ var durationMs = performanceMeasurement.flushMeasurement();
7731
+ // null indicates no measurement was taken (e.g. needed performance APIs not present)
7732
+ if (durationMs !== null) {
7733
+ this.logger.trace("PerformanceClient: Performance measurement ended for " + event.name + ": " + durationMs + " ms", event.correlationId);
7734
+ var completedEvent = __assign(__assign({
7735
+ // Allow duration to be overwritten when event ends (e.g. testing), but not status
7736
+ durationMs: Math.round(durationMs) }, event), { status: exports.PerformanceEventStatus.Completed });
7737
+ return completedEvent;
7738
+ }
7739
+ else {
7740
+ this.logger.trace("PerformanceClient: Performance measurement not taken", event.correlationId);
7741
+ }
7742
+ }
7743
+ else {
7744
+ this.logger.trace("PerformanceClient: Measurement not found for " + event.eventId, event.correlationId);
7745
+ }
7746
+ return null;
7747
+ };
7748
+ /**
7749
+ * Upserts event into event cache.
7750
+ * First key is the correlation id, second key is the event id.
7751
+ * Allows for events to be grouped by correlation id,
7752
+ * and to easily allow for properties on them to be updated.
7753
+ *
7754
+ * @private
7755
+ * @param {PerformanceEvent} event
7756
+ */
7757
+ PerformanceClient.prototype.cacheEventByCorrelationId = function (event) {
7758
+ var existingEvents = this.eventsByCorrelationId.get(event.correlationId);
7759
+ if (existingEvents) {
7760
+ this.logger.trace("PerformanceClient: Performance measurement for " + event.name + " added/updated", event.correlationId);
7761
+ existingEvents.set(event.eventId, event);
7762
+ }
7763
+ else {
7764
+ this.logger.trace("PerformanceClient: Performance measurement for " + event.name + " started", event.correlationId);
7765
+ this.eventsByCorrelationId.set(event.correlationId, new Map().set(event.eventId, event));
7766
+ }
7767
+ };
7768
+ /**
7769
+ * Cache measurements by their id.
7770
+ *
7771
+ * @private
7772
+ * @param {PerformanceEvent} event
7773
+ * @param {IPerformanceMeasurement} measurement
7774
+ */
7775
+ PerformanceClient.prototype.cacheMeasurement = function (event, measurement) {
7776
+ this.measurementsById.set(event.eventId, measurement);
7777
+ };
7778
+ /**
7779
+ * Gathers and emits performance events for measurements taked for the given top-level API and correlation ID.
7780
+ *
7781
+ * @param {PerformanceEvents} measureName
7782
+ * @param {string} correlationId
7783
+ */
7784
+ PerformanceClient.prototype.flushMeasurements = function (measureName, correlationId) {
7785
+ var _this = this;
7786
+ this.logger.trace("PerformanceClient: Performance measurements flushed for " + measureName, correlationId);
7787
+ var eventsForCorrelationId = this.eventsByCorrelationId.get(correlationId);
7788
+ if (eventsForCorrelationId) {
7789
+ this.discardMeasurements(correlationId);
7790
+ /*
7791
+ * Manually end incomplete submeasurements to ensure there arent orphaned/never ending events.
7792
+ * Incomplete submeasurements are likely an instrumentation bug that should be fixed.
7793
+ * IE only supports Map.forEach.
7794
+ */
7795
+ var completedEvents_1 = [];
7796
+ eventsForCorrelationId.forEach(function (event) {
7797
+ if (event.name !== measureName && event.status !== exports.PerformanceEventStatus.Completed) {
7798
+ _this.logger.trace("PerformanceClient: Incomplete submeasurement " + event.name + " found for " + measureName, correlationId);
7799
+ var completedEvent = _this.endMeasurement(event);
7800
+ if (completedEvent) {
7801
+ completedEvents_1.push(completedEvent);
7802
+ }
7803
+ }
7804
+ completedEvents_1.push(event);
7805
+ });
7806
+ // Sort events by start time (earliest first)
7807
+ var sortedCompletedEvents = completedEvents_1.sort(function (eventA, eventB) { return eventA.startTimeMs - eventB.startTimeMs; });
7808
+ // Take completed top level event and add completed submeasurements durations as properties
7809
+ var topLevelEvents = sortedCompletedEvents.filter(function (event) { return event.name === measureName && event.status === exports.PerformanceEventStatus.Completed; });
7810
+ if (topLevelEvents.length > 0) {
7811
+ /*
7812
+ * Only take the first top-level event if there are multiple events with the same correlation id.
7813
+ * This greatly simplifies logic for submeasurements.
7814
+ */
7815
+ if (topLevelEvents.length > 1) {
7816
+ this.logger.verbose("PerformanceClient: Multiple distinct top-level performance events found, using the first", correlationId);
7817
+ }
7818
+ var topLevelEvent = topLevelEvents[0];
7819
+ this.logger.verbose("PerformanceClient: Measurement found for " + measureName, correlationId);
7820
+ // Build event object with top level and sub measurements
7821
+ var eventToEmit = sortedCompletedEvents.reduce(function (previous, current) {
7822
+ if (current.name !== measureName) {
7823
+ _this.logger.trace("PerformanceClient: Complete submeasurement found for " + current.name, correlationId);
7824
+ // TODO: Emit additional properties for each subMeasurement
7825
+ var subMeasurementName = current.name + "DurationMs";
7826
+ /*
7827
+ * Some code paths, such as resolving an authority, can occur multiple times.
7828
+ * Only take the first measurement, since the second could be read from the cache,
7829
+ * or due to the same correlation id being used for two distinct requests.
7830
+ */
7831
+ if (!previous[subMeasurementName]) {
7832
+ previous[subMeasurementName] = current.durationMs;
7833
+ }
7834
+ else {
7835
+ _this.logger.verbose("PerformanceClient: Submeasurement for " + measureName + " already exists for " + current.name + ", ignoring", correlationId);
7836
+ }
7837
+ }
7838
+ return previous;
7839
+ }, topLevelEvent);
7840
+ this.emitEvents([eventToEmit], eventToEmit.correlationId);
7841
+ }
7842
+ else {
7843
+ this.logger.verbose("PerformanceClient: No completed top-level measurements found for " + measureName, correlationId);
7844
+ }
7845
+ }
7846
+ else {
7847
+ this.logger.verbose("PerformanceClient: No measurements found", correlationId);
7848
+ }
7849
+ };
7850
+ /**
7851
+ * Removes measurements for a given correlation id.
7852
+ *
7853
+ * @param {string} correlationId
7854
+ */
7855
+ PerformanceClient.prototype.discardMeasurements = function (correlationId) {
7856
+ this.logger.trace("PerformanceClient: Performance measurements discarded", correlationId);
7857
+ this.eventsByCorrelationId.delete(correlationId);
7858
+ };
7859
+ /**
7860
+ * Registers a callback function to receive performance events.
7861
+ *
7862
+ * @param {PerformanceCallbackFunction} callback
7863
+ * @returns {string}
7864
+ */
7865
+ PerformanceClient.prototype.addPerformanceCallback = function (callback) {
7866
+ var callbackId = this.generateId();
7867
+ this.callbacks.set(callbackId, callback);
7868
+ this.logger.verbose("PerformanceClient: Performance callback registered with id: " + callbackId);
7869
+ return callbackId;
7870
+ };
7871
+ /**
7872
+ * Removes a callback registered with addPerformanceCallback.
7873
+ *
7874
+ * @param {string} callbackId
7875
+ * @returns {boolean}
7876
+ */
7877
+ PerformanceClient.prototype.removePerformanceCallback = function (callbackId) {
7878
+ var result = this.callbacks.delete(callbackId);
7879
+ if (result) {
7880
+ this.logger.verbose("PerformanceClient: Performance callback " + callbackId + " removed.");
7881
+ }
7882
+ else {
7883
+ this.logger.verbose("PerformanceClient: Performance callback " + callbackId + " not removed.");
7884
+ }
7885
+ return result;
7886
+ };
7887
+ /**
7888
+ * Emits events to all registered callbacks.
7889
+ *
7890
+ * @param {PerformanceEvent[]} events
7891
+ * @param {?string} [correlationId]
7892
+ */
7893
+ PerformanceClient.prototype.emitEvents = function (events, correlationId) {
7894
+ var _this = this;
7895
+ this.logger.verbose("PerformanceClient: Emitting performance events", correlationId);
7896
+ this.callbacks.forEach(function (callback, callbackId) {
7897
+ _this.logger.trace("PerformanceClient: Emitting event to callback " + callbackId, correlationId);
7898
+ callback.apply(null, [events]);
7899
+ });
7900
+ };
7901
+ return PerformanceClient;
7902
+ }());
7903
+
7904
+ /*
7905
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7906
+ * Licensed under the MIT License.
7907
+ */
7908
+ var StubPerformanceMeasurement = /** @class */ (function () {
7909
+ function StubPerformanceMeasurement() {
7910
+ }
7911
+ /* eslint-disable-next-line @typescript-eslint/no-empty-function */
7912
+ StubPerformanceMeasurement.prototype.startMeasurement = function () { };
7913
+ /* eslint-disable-next-line @typescript-eslint/no-empty-function */
7914
+ StubPerformanceMeasurement.prototype.endMeasurement = function () { };
7915
+ StubPerformanceMeasurement.prototype.flushMeasurement = function () {
7916
+ return null;
7917
+ };
7918
+ return StubPerformanceMeasurement;
7919
+ }());
7920
+ var StubPerformanceClient = /** @class */ (function (_super) {
7921
+ __extends(StubPerformanceClient, _super);
7922
+ function StubPerformanceClient() {
7923
+ return _super !== null && _super.apply(this, arguments) || this;
7924
+ }
7925
+ StubPerformanceClient.prototype.generateId = function () {
7926
+ return "callback-id";
7927
+ };
7928
+ StubPerformanceClient.prototype.startPerformanceMeasuremeant = function () {
7929
+ return new StubPerformanceMeasurement();
7930
+ };
7931
+ return StubPerformanceClient;
7932
+ }(PerformanceClient));
7933
+
7410
7934
  exports.AccessTokenEntity = AccessTokenEntity;
7411
7935
  exports.AccountEntity = AccountEntity;
7412
7936
  exports.AppMetadataEntity = AppMetadataEntity;
@@ -7438,6 +7962,7 @@ exports.Logger = Logger;
7438
7962
  exports.NetworkManager = NetworkManager;
7439
7963
  exports.OIDC_DEFAULT_SCOPES = OIDC_DEFAULT_SCOPES;
7440
7964
  exports.OnBehalfOfClient = OnBehalfOfClient;
7965
+ exports.PerformanceClient = PerformanceClient;
7441
7966
  exports.PopTokenGenerator = PopTokenGenerator;
7442
7967
  exports.PromptValue = PromptValue;
7443
7968
  exports.ProtocolUtils = ProtocolUtils;
@@ -7449,6 +7974,7 @@ exports.ServerTelemetryEntity = ServerTelemetryEntity;
7449
7974
  exports.ServerTelemetryManager = ServerTelemetryManager;
7450
7975
  exports.SilentFlowClient = SilentFlowClient;
7451
7976
  exports.StringUtils = StringUtils;
7977
+ exports.StubPerformanceClient = StubPerformanceClient;
7452
7978
  exports.StubbedNetworkModule = StubbedNetworkModule;
7453
7979
  exports.ThrottlingEntity = ThrottlingEntity;
7454
7980
  exports.ThrottlingUtils = ThrottlingUtils;