@azure/msal-browser 2.17.0 → 2.21.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 (168) hide show
  1. package/CHANGELOG.json +203 -0
  2. package/{changelog.md → CHANGELOG.md} +506 -445
  3. package/LICENSE +21 -21
  4. package/README.md +14 -6
  5. package/dist/_virtual/_tslib.js +1 -1
  6. package/dist/app/ClientApplication.d.ts +31 -0
  7. package/dist/app/ClientApplication.d.ts.map +1 -1
  8. package/dist/app/ClientApplication.js +96 -3
  9. package/dist/app/ClientApplication.js.map +1 -1
  10. package/dist/app/IPublicClientApplication.d.ts +6 -0
  11. package/dist/app/IPublicClientApplication.d.ts.map +1 -1
  12. package/dist/app/IPublicClientApplication.js +13 -1
  13. package/dist/app/IPublicClientApplication.js.map +1 -1
  14. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  15. package/dist/app/PublicClientApplication.js +31 -24
  16. package/dist/app/PublicClientApplication.js.map +1 -1
  17. package/dist/cache/AsyncMemoryStorage.d.ts +46 -0
  18. package/dist/cache/AsyncMemoryStorage.d.ts.map +1 -0
  19. package/dist/cache/AsyncMemoryStorage.js +195 -0
  20. package/dist/cache/AsyncMemoryStorage.js.map +1 -0
  21. package/dist/cache/BrowserCacheManager.d.ts +9 -1
  22. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  23. package/dist/cache/BrowserCacheManager.js +55 -2
  24. package/dist/cache/BrowserCacheManager.js.map +1 -1
  25. package/dist/cache/BrowserStorage.d.ts +1 -1
  26. package/dist/cache/BrowserStorage.d.ts.map +1 -1
  27. package/dist/cache/BrowserStorage.js +1 -1
  28. package/dist/cache/BrowserStorage.js.map +1 -1
  29. package/dist/cache/DatabaseStorage.d.ts +25 -6
  30. package/dist/cache/DatabaseStorage.d.ts.map +1 -1
  31. package/dist/cache/DatabaseStorage.js +127 -81
  32. package/dist/cache/DatabaseStorage.js.map +1 -1
  33. package/dist/cache/IAsyncMemoryStorage.d.ts +28 -0
  34. package/dist/cache/IAsyncMemoryStorage.d.ts.map +1 -0
  35. package/dist/cache/IWindowStorage.d.ts +3 -3
  36. package/dist/cache/IWindowStorage.d.ts.map +1 -1
  37. package/dist/cache/MemoryStorage.d.ts +3 -3
  38. package/dist/cache/MemoryStorage.d.ts.map +1 -1
  39. package/dist/cache/MemoryStorage.js +1 -1
  40. package/dist/cache/MemoryStorage.js.map +1 -1
  41. package/dist/cache/TokenCache.js +1 -1
  42. package/dist/cache/TokenCache.js.map +1 -1
  43. package/dist/config/Configuration.js +1 -1
  44. package/dist/config/Configuration.js.map +1 -1
  45. package/dist/crypto/BrowserCrypto.d.ts +3 -1
  46. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  47. package/dist/crypto/BrowserCrypto.js +3 -2
  48. package/dist/crypto/BrowserCrypto.js.map +1 -1
  49. package/dist/crypto/CryptoOps.d.ts +16 -5
  50. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  51. package/dist/crypto/CryptoOps.js +58 -17
  52. package/dist/crypto/CryptoOps.js.map +1 -1
  53. package/dist/crypto/GuidGenerator.js +1 -1
  54. package/dist/crypto/GuidGenerator.js.map +1 -1
  55. package/dist/crypto/PkceGenerator.js +1 -1
  56. package/dist/crypto/PkceGenerator.js.map +1 -1
  57. package/dist/crypto/SignedHttpRequest.d.ts +6 -2
  58. package/dist/crypto/SignedHttpRequest.d.ts.map +1 -1
  59. package/dist/crypto/SignedHttpRequest.js +11 -5
  60. package/dist/crypto/SignedHttpRequest.js.map +1 -1
  61. package/dist/encode/Base64Decode.js +1 -1
  62. package/dist/encode/Base64Decode.js.map +1 -1
  63. package/dist/encode/Base64Encode.js +1 -1
  64. package/dist/encode/Base64Encode.js.map +1 -1
  65. package/dist/error/BrowserAuthError.d.ts +16 -8
  66. package/dist/error/BrowserAuthError.d.ts.map +1 -1
  67. package/dist/error/BrowserAuthError.js +22 -12
  68. package/dist/error/BrowserAuthError.js.map +1 -1
  69. package/dist/error/BrowserConfigurationAuthError.js +1 -1
  70. package/dist/error/BrowserConfigurationAuthError.js.map +1 -1
  71. package/dist/event/EventHandler.d.ts +13 -0
  72. package/dist/event/EventHandler.d.ts.map +1 -1
  73. package/dist/event/EventHandler.js +66 -1
  74. package/dist/event/EventHandler.js.map +1 -1
  75. package/dist/event/EventMessage.d.ts +2 -2
  76. package/dist/event/EventMessage.d.ts.map +1 -1
  77. package/dist/event/EventMessage.js +1 -1
  78. package/dist/event/EventMessage.js.map +1 -1
  79. package/dist/event/EventType.d.ts +5 -0
  80. package/dist/event/EventType.d.ts.map +1 -1
  81. package/dist/event/EventType.js +6 -1
  82. package/dist/event/EventType.js.map +1 -1
  83. package/dist/index.cjs.js +1465 -520
  84. package/dist/index.cjs.js.map +1 -1
  85. package/dist/index.d.ts +5 -3
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +3 -2
  88. package/dist/index.js.map +1 -1
  89. package/dist/interaction_client/BaseInteractionClient.d.ts +21 -1
  90. package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
  91. package/dist/interaction_client/BaseInteractionClient.js +77 -3
  92. package/dist/interaction_client/BaseInteractionClient.js.map +1 -1
  93. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.d.ts +5 -0
  94. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.d.ts.map +1 -0
  95. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.js +21 -0
  96. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.js.map +1 -0
  97. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  98. package/dist/interaction_client/PopupClient.js +47 -37
  99. package/dist/interaction_client/PopupClient.js.map +1 -1
  100. package/dist/interaction_client/RedirectClient.js +16 -15
  101. package/dist/interaction_client/RedirectClient.js.map +1 -1
  102. package/dist/interaction_client/SilentAuthCodeClient.d.ts +22 -0
  103. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -0
  104. package/dist/interaction_client/SilentAuthCodeClient.js +82 -0
  105. package/dist/interaction_client/SilentAuthCodeClient.js.map +1 -0
  106. package/dist/interaction_client/SilentCacheClient.d.ts +1 -1
  107. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  108. package/dist/interaction_client/SilentCacheClient.js +12 -2
  109. package/dist/interaction_client/SilentCacheClient.js.map +1 -1
  110. package/dist/interaction_client/SilentIframeClient.js +15 -13
  111. package/dist/interaction_client/SilentIframeClient.js.map +1 -1
  112. package/dist/interaction_client/SilentRefreshClient.js +10 -7
  113. package/dist/interaction_client/SilentRefreshClient.js.map +1 -1
  114. package/dist/interaction_client/StandardInteractionClient.d.ts +3 -23
  115. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  116. package/dist/interaction_client/StandardInteractionClient.js +51 -105
  117. package/dist/interaction_client/StandardInteractionClient.js.map +1 -1
  118. package/dist/interaction_handler/InteractionHandler.d.ts +11 -2
  119. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  120. package/dist/interaction_handler/InteractionHandler.js +36 -10
  121. package/dist/interaction_handler/InteractionHandler.js.map +1 -1
  122. package/dist/interaction_handler/PopupHandler.js +1 -1
  123. package/dist/interaction_handler/PopupHandler.js.map +1 -1
  124. package/dist/interaction_handler/RedirectHandler.d.ts +1 -1
  125. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  126. package/dist/interaction_handler/RedirectHandler.js +2 -2
  127. package/dist/interaction_handler/RedirectHandler.js.map +1 -1
  128. package/dist/interaction_handler/SilentHandler.js +1 -1
  129. package/dist/interaction_handler/SilentHandler.js.map +1 -1
  130. package/dist/navigation/NavigationClient.js +1 -1
  131. package/dist/navigation/NavigationClient.js.map +1 -1
  132. package/dist/network/FetchClient.js +1 -1
  133. package/dist/network/FetchClient.js.map +1 -1
  134. package/dist/network/XhrClient.js +1 -1
  135. package/dist/network/XhrClient.js.map +1 -1
  136. package/dist/packageMetadata.d.ts +1 -1
  137. package/dist/packageMetadata.js +2 -2
  138. package/dist/packageMetadata.js.map +1 -1
  139. package/dist/request/AuthorizationCodeRequest.d.ts +8 -0
  140. package/dist/request/AuthorizationCodeRequest.d.ts.map +1 -0
  141. package/dist/request/AuthorizationUrlRequest.d.ts +1 -1
  142. package/dist/request/AuthorizationUrlRequest.d.ts.map +1 -1
  143. package/dist/request/PopupRequest.d.ts +1 -1
  144. package/dist/request/PopupRequest.d.ts.map +1 -1
  145. package/dist/request/RedirectRequest.d.ts +1 -1
  146. package/dist/request/RedirectRequest.d.ts.map +1 -1
  147. package/dist/request/SilentRequest.d.ts +1 -1
  148. package/dist/request/SilentRequest.d.ts.map +1 -1
  149. package/dist/request/SsoSilentRequest.d.ts +1 -1
  150. package/dist/request/SsoSilentRequest.d.ts.map +1 -1
  151. package/dist/utils/BrowserConstants.d.ts +4 -0
  152. package/dist/utils/BrowserConstants.d.ts.map +1 -1
  153. package/dist/utils/BrowserConstants.js +8 -3
  154. package/dist/utils/BrowserConstants.js.map +1 -1
  155. package/dist/utils/BrowserProtocolUtils.js +1 -1
  156. package/dist/utils/BrowserProtocolUtils.js.map +1 -1
  157. package/dist/utils/BrowserStringUtils.js +1 -1
  158. package/dist/utils/BrowserStringUtils.js.map +1 -1
  159. package/dist/utils/BrowserUtils.js +1 -1
  160. package/dist/utils/BrowserUtils.js.map +1 -1
  161. package/dist/utils/MathUtils.js +1 -1
  162. package/dist/utils/MathUtils.js.map +1 -1
  163. package/dist/utils/PopupUtils.js +1 -1
  164. package/dist/utils/PopupUtils.js.map +1 -1
  165. package/lib/msal-browser.js +1465 -520
  166. package/lib/msal-browser.js.map +1 -1
  167. package/lib/msal-browser.min.js +30 -30
  168. package/package.json +9 -2
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-browser v2.17.0 2021-09-08 */
1
+ /*! @azure/msal-browser v2.21.0 2022-01-04 */
2
2
  'use strict';
3
3
  (function (global, factory) {
4
4
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
@@ -107,7 +107,7 @@
107
107
  return ar;
108
108
  }
109
109
 
110
- /*! @azure/msal-common v5.0.0 2021-09-08 */
110
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
111
111
  /*! *****************************************************************************
112
112
  Copyright (c) Microsoft Corporation.
113
113
 
@@ -194,7 +194,7 @@
194
194
  return r;
195
195
  }
196
196
 
197
- /*! @azure/msal-common v5.0.0 2021-09-08 */
197
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
198
198
 
199
199
  /*
200
200
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -259,6 +259,8 @@
259
259
  HeaderNames["CONTENT_TYPE"] = "Content-Type";
260
260
  HeaderNames["RETRY_AFTER"] = "Retry-After";
261
261
  HeaderNames["CCS_HEADER"] = "X-AnchorMailbox";
262
+ HeaderNames["WWWAuthenticate"] = "WWW-Authenticate";
263
+ HeaderNames["AuthenticationInfo"] = "Authentication-Info";
262
264
  })(HeaderNames || (HeaderNames = {}));
263
265
  /**
264
266
  * Persistent cache keys MSAL which stay while user is logged in.
@@ -329,6 +331,7 @@
329
331
  AADServerParamKeys["ON_BEHALF_OF"] = "on_behalf_of";
330
332
  AADServerParamKeys["FOCI"] = "foci";
331
333
  AADServerParamKeys["CCS_HEADER"] = "X-AnchorMailbox";
334
+ AADServerParamKeys["RETURN_SPA_CODE"] = "return_spa_code";
332
335
  })(AADServerParamKeys || (AADServerParamKeys = {}));
333
336
  /**
334
337
  * Claims request keys
@@ -486,8 +489,9 @@
486
489
  */
487
490
  exports.AuthenticationScheme = void 0;
488
491
  (function (AuthenticationScheme) {
489
- AuthenticationScheme["POP"] = "pop";
490
492
  AuthenticationScheme["BEARER"] = "Bearer";
493
+ AuthenticationScheme["POP"] = "pop";
494
+ AuthenticationScheme["SSH"] = "ssh-cert";
491
495
  })(exports.AuthenticationScheme || (exports.AuthenticationScheme = {}));
492
496
  /**
493
497
  * Constants related to throttling
@@ -552,7 +556,7 @@
552
556
  CacheOutcome["REFRESH_CACHED_ACCESS_TOKEN"] = "4";
553
557
  })(CacheOutcome || (CacheOutcome = {}));
554
558
 
555
- /*! @azure/msal-common v5.0.0 2021-09-08 */
559
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
556
560
 
557
561
  /*
558
562
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -596,7 +600,7 @@
596
600
  return AuthError;
597
601
  }(Error));
598
602
 
599
- /*! @azure/msal-common v5.0.0 2021-09-08 */
603
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
600
604
 
601
605
  /*
602
606
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -659,10 +663,19 @@
659
663
  throw AuthError.createUnexpectedError(notImplErr);
660
664
  });
661
665
  });
666
+ },
667
+ hashString: function () {
668
+ return __awaiter(this, void 0, void 0, function () {
669
+ var notImplErr;
670
+ return __generator(this, function (_a) {
671
+ notImplErr = "Crypto interface - hashString() has not been implemented";
672
+ throw AuthError.createUnexpectedError(notImplErr);
673
+ });
674
+ });
662
675
  }
663
676
  };
664
677
 
665
- /*! @azure/msal-common v5.0.0 2021-09-08 */
678
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
666
679
 
667
680
  /*
668
681
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -848,6 +861,10 @@
848
861
  bindingKeyNotRemovedError: {
849
862
  code: "binding_key_not_removed",
850
863
  desc: "Could not remove the credential's binding key from storage."
864
+ },
865
+ logoutNotSupported: {
866
+ code: "end_session_endpoint_not_supported",
867
+ desc: "Provided authority does not support logout."
851
868
  }
852
869
  };
853
870
  /**
@@ -947,12 +964,6 @@
947
964
  ClientAuthError.createNonceNotFoundError = function (missingNonce) {
948
965
  return new ClientAuthError(ClientAuthErrorMessage.nonceNotFoundError.code, ClientAuthErrorMessage.nonceNotFoundError.desc + ": " + missingNonce);
949
966
  };
950
- /**
951
- * Creates an error thrown when the authorization code required for a token request is null or empty.
952
- */
953
- ClientAuthError.createNoTokensFoundError = function () {
954
- return new ClientAuthError(ClientAuthErrorMessage.noTokensFoundError.code, ClientAuthErrorMessage.noTokensFoundError.desc);
955
- };
956
967
  /**
957
968
  * Throws error when multiple tokens are in cache.
958
969
  */
@@ -1117,10 +1128,16 @@
1117
1128
  ClientAuthError.createBindingKeyNotRemovedError = function () {
1118
1129
  return new ClientAuthError(ClientAuthErrorMessage.bindingKeyNotRemovedError.code, ClientAuthErrorMessage.bindingKeyNotRemovedError.desc);
1119
1130
  };
1131
+ /**
1132
+ * Thrown when logout is attempted for an authority that doesnt have an end_session_endpoint
1133
+ */
1134
+ ClientAuthError.createLogoutNotSupportedError = function () {
1135
+ return new ClientAuthError(ClientAuthErrorMessage.logoutNotSupported.code, ClientAuthErrorMessage.logoutNotSupported.desc);
1136
+ };
1120
1137
  return ClientAuthError;
1121
1138
  }(AuthError));
1122
1139
 
1123
- /*! @azure/msal-common v5.0.0 2021-09-08 */
1140
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
1124
1141
 
1125
1142
  /*
1126
1143
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1245,7 +1262,7 @@
1245
1262
  return StringUtils;
1246
1263
  }());
1247
1264
 
1248
- /*! @azure/msal-common v5.0.0 2021-09-08 */
1265
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
1249
1266
 
1250
1267
  /*
1251
1268
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1425,12 +1442,12 @@
1425
1442
  return Logger;
1426
1443
  }());
1427
1444
 
1428
- /*! @azure/msal-common v5.0.0 2021-09-08 */
1445
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
1429
1446
  /* eslint-disable header/header */
1430
1447
  var name$1 = "@azure/msal-common";
1431
- var version$1 = "5.0.0";
1448
+ var version$1 = "6.0.0";
1432
1449
 
1433
- /*! @azure/msal-common v5.0.0 2021-09-08 */
1450
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
1434
1451
 
1435
1452
  /*
1436
1453
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1441,7 +1458,7 @@
1441
1458
  *
1442
1459
  * Key:Value Schema:
1443
1460
  *
1444
- * Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<scheme>
1461
+ * Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<requestedClaims*>-<scheme*>
1445
1462
  *
1446
1463
  * Value Schema:
1447
1464
  * {
@@ -1455,6 +1472,7 @@
1455
1472
  * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
1456
1473
  * oboAssertion: access token passed in as part of OBO request
1457
1474
  * tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
1475
+ * requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request
1458
1476
  * }
1459
1477
  */
1460
1478
  var CredentialEntity = /** @class */ (function () {
@@ -1482,7 +1500,7 @@
1482
1500
  * generates credential key
1483
1501
  */
1484
1502
  CredentialEntity.prototype.generateCredentialKey = function () {
1485
- return CredentialEntity.generateCredentialCacheKey(this.homeAccountId, this.environment, this.credentialType, this.clientId, this.realm, this.target, this.familyId, this.tokenType);
1503
+ return CredentialEntity.generateCredentialCacheKey(this.homeAccountId, this.environment, this.credentialType, this.clientId, this.realm, this.target, this.familyId, this.tokenType, this.requestedClaimsHash);
1486
1504
  };
1487
1505
  /**
1488
1506
  * returns the type of the cache (in this case credential)
@@ -1526,16 +1544,14 @@
1526
1544
  * generates credential key
1527
1545
  * <home_account_id*>-\<environment>-<credential_type>-<client_id>-<realm\*>-<target\*>-<scheme\*>
1528
1546
  */
1529
- CredentialEntity.generateCredentialCacheKey = function (homeAccountId, environment, credentialType, clientId, realm, target, familyId, tokenType) {
1547
+ CredentialEntity.generateCredentialCacheKey = function (homeAccountId, environment, credentialType, clientId, realm, target, familyId, tokenType, requestedClaimsHash) {
1530
1548
  var credentialKey = [
1531
1549
  this.generateAccountIdForCacheKey(homeAccountId, environment),
1532
1550
  this.generateCredentialIdForCacheKey(credentialType, clientId, realm, familyId),
1533
- this.generateTargetForCacheKey(target)
1551
+ this.generateTargetForCacheKey(target),
1552
+ this.generateClaimsHashForCacheKey(requestedClaimsHash),
1553
+ this.generateSchemeForCacheKey(tokenType)
1534
1554
  ];
1535
- // PoP Tokens include scheme in cache key
1536
- if (tokenType === exports.AuthenticationScheme.POP) {
1537
- credentialKey.push(tokenType.toLowerCase());
1538
- }
1539
1555
  return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
1540
1556
  };
1541
1557
  /**
@@ -1571,10 +1587,26 @@
1571
1587
  CredentialEntity.generateTargetForCacheKey = function (scopes) {
1572
1588
  return (scopes || "").toLowerCase();
1573
1589
  };
1590
+ /**
1591
+ * Generate requested claims key component as per schema: <requestedClaims>
1592
+ */
1593
+ CredentialEntity.generateClaimsHashForCacheKey = function (requestedClaimsHash) {
1594
+ return (requestedClaimsHash || "").toLowerCase();
1595
+ };
1596
+ /**
1597
+ * Generate scheme key componenet as per schema: <scheme>
1598
+ */
1599
+ CredentialEntity.generateSchemeForCacheKey = function (tokenType) {
1600
+ /*
1601
+ * PoP Tokens and SSH certs include scheme in cache key
1602
+ * Cast to lowercase to handle "bearer" from ADFS
1603
+ */
1604
+ return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : "";
1605
+ };
1574
1606
  return CredentialEntity;
1575
1607
  }());
1576
1608
 
1577
- /*! @azure/msal-common v5.0.0 2021-09-08 */
1609
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
1578
1610
 
1579
1611
  /*
1580
1612
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1646,15 +1678,31 @@
1646
1678
  },
1647
1679
  invalidCloudDiscoveryMetadata: {
1648
1680
  code: "invalid_cloud_discovery_metadata",
1649
- desc: "Invalid cloudDiscoveryMetadata provided. Must be a JSON object containing tenant_discovery_endpoint and metadata fields"
1681
+ desc: "Invalid cloudDiscoveryMetadata provided. Must be a stringified JSON object containing tenant_discovery_endpoint and metadata fields"
1650
1682
  },
1651
1683
  invalidAuthorityMetadata: {
1652
1684
  code: "invalid_authority_metadata",
1653
- desc: "Invalid authorityMetadata provided. Must by a JSON object containing authorization_endpoint, token_endpoint, end_session_endpoint, issuer fields."
1685
+ desc: "Invalid authorityMetadata provided. Must by a stringified JSON object containing authorization_endpoint, token_endpoint, issuer fields."
1654
1686
  },
1655
1687
  untrustedAuthority: {
1656
1688
  code: "untrusted_authority",
1657
1689
  desc: "The provided authority is not a trusted authority. Please include this authority in the knownAuthorities config parameter."
1690
+ },
1691
+ missingSshJwk: {
1692
+ code: "missing_ssh_jwk",
1693
+ desc: "Missing sshJwk in SSH certificate request. A stringified JSON Web Key is required when using the SSH authentication scheme."
1694
+ },
1695
+ missingSshKid: {
1696
+ code: "missing_ssh_kid",
1697
+ desc: "Missing sshKid in SSH certificate request. A string that uniquely identifies the public SSH key is required when using the SSH authentication scheme."
1698
+ },
1699
+ missingNonceAuthenticationHeader: {
1700
+ code: "missing_nonce_authentication_header",
1701
+ desc: "Unable to find an authentication header containing server nonce. Either the Authentication-Info or WWW-Authenticate headers must be present in order to obtain a server nonce."
1702
+ },
1703
+ invalidAuthenticationHeader: {
1704
+ code: "invalid_authentication_header",
1705
+ desc: "Invalid authentication header provided"
1658
1706
  }
1659
1707
  };
1660
1708
  /**
@@ -1776,10 +1824,34 @@
1776
1824
  ClientConfigurationError.createUntrustedAuthorityError = function () {
1777
1825
  return new ClientConfigurationError(ClientConfigurationErrorMessage.untrustedAuthority.code, ClientConfigurationErrorMessage.untrustedAuthority.desc);
1778
1826
  };
1827
+ /*
1828
+ * Throws an error when the authentication scheme is set to SSH but the SSH public key is omitted from the request
1829
+ */
1830
+ ClientConfigurationError.createMissingSshJwkError = function () {
1831
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.missingSshJwk.code, ClientConfigurationErrorMessage.missingSshJwk.desc);
1832
+ };
1833
+ /**
1834
+ * Throws an error when the authentication scheme is set to SSH but the SSH public key ID is omitted from the request
1835
+ */
1836
+ ClientConfigurationError.createMissingSshKidError = function () {
1837
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.missingSshKid.code, ClientConfigurationErrorMessage.missingSshKid.desc);
1838
+ };
1839
+ /**
1840
+ * Throws error when provided headers don't contain a header that a server nonce can be extracted from
1841
+ */
1842
+ ClientConfigurationError.createMissingNonceAuthenticationHeadersError = function () {
1843
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.missingNonceAuthenticationHeader.code, ClientConfigurationErrorMessage.missingNonceAuthenticationHeader.desc);
1844
+ };
1845
+ /**
1846
+ * Throws error when a provided header is invalid in any way
1847
+ */
1848
+ ClientConfigurationError.createInvalidAuthenticationHeaderError = function (invalidHeaderName, details) {
1849
+ return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidAuthenticationHeader.code, ClientConfigurationErrorMessage.invalidAuthenticationHeader.desc + ". Invalid header: " + invalidHeaderName + ". Details: " + details);
1850
+ };
1779
1851
  return ClientConfigurationError;
1780
1852
  }(ClientAuthError));
1781
1853
 
1782
- /*! @azure/msal-common v5.0.0 2021-09-08 */
1854
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
1783
1855
 
1784
1856
  /*
1785
1857
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1963,7 +2035,7 @@
1963
2035
  return ScopeSet;
1964
2036
  }());
1965
2037
 
1966
- /*! @azure/msal-common v5.0.0 2021-09-08 */
2038
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
1967
2039
 
1968
2040
  /*
1969
2041
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2001,7 +2073,7 @@
2001
2073
  };
2002
2074
  }
2003
2075
 
2004
- /*! @azure/msal-common v5.0.0 2021-09-08 */
2076
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
2005
2077
  /*
2006
2078
  * Copyright (c) Microsoft Corporation. All rights reserved.
2007
2079
  * Licensed under the MIT License.
@@ -2015,7 +2087,7 @@
2015
2087
  AuthorityType[AuthorityType["Adfs"] = 1] = "Adfs";
2016
2088
  })(AuthorityType || (AuthorityType = {}));
2017
2089
 
2018
- /*! @azure/msal-common v5.0.0 2021-09-08 */
2090
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
2019
2091
 
2020
2092
  /*
2021
2093
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2249,7 +2321,7 @@
2249
2321
  return AccountEntity;
2250
2322
  }());
2251
2323
 
2252
- /*! @azure/msal-common v5.0.0 2021-09-08 */
2324
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
2253
2325
 
2254
2326
  /*
2255
2327
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2287,7 +2359,7 @@
2287
2359
  return AuthToken;
2288
2360
  }());
2289
2361
 
2290
- /*! @azure/msal-common v5.0.0 2021-09-08 */
2362
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
2291
2363
 
2292
2364
  /*
2293
2365
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2377,7 +2449,8 @@
2377
2449
  environment: credential.environment,
2378
2450
  homeAccountId: credential.homeAccountId,
2379
2451
  realm: credential.realm,
2380
- tokenType: credential.tokenType
2452
+ tokenType: credential.tokenType,
2453
+ requestedClaimsHash: credential.requestedClaimsHash
2381
2454
  });
2382
2455
  currentScopes = ScopeSet.fromString(credential.target);
2383
2456
  currentAccessTokens = Object.keys(currentTokenCache.accessTokens).map(function (key) { return currentTokenCache.accessTokens[key]; });
@@ -2449,7 +2522,7 @@
2449
2522
  * @param target
2450
2523
  */
2451
2524
  CacheManager.prototype.getCredentialsFilteredBy = function (filter) {
2452
- return this.getCredentialsFilteredByInternal(filter.homeAccountId, filter.environment, filter.credentialType, filter.clientId, filter.familyId, filter.realm, filter.target, filter.oboAssertion, filter.tokenType);
2525
+ 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);
2453
2526
  };
2454
2527
  /**
2455
2528
  * Support function to help match credentials
@@ -2462,7 +2535,7 @@
2462
2535
  * @param oboAssertion
2463
2536
  * @param tokenType
2464
2537
  */
2465
- CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, oboAssertion, tokenType) {
2538
+ CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, oboAssertion, tokenType, keyId, requestedClaimsHash) {
2466
2539
  var _this = this;
2467
2540
  var allCacheKeys = this.getKeys();
2468
2541
  var matchingCredentials = {
@@ -2509,27 +2582,37 @@
2509
2582
  if (!!target && !_this.matchTarget(entity, target)) {
2510
2583
  return;
2511
2584
  }
2585
+ // If request OR cached entity has requested Claims Hash, check if they match
2586
+ if (requestedClaimsHash || entity.requestedClaimsHash) {
2587
+ // Don't match if either is undefined or they are different
2588
+ if (entity.requestedClaimsHash !== requestedClaimsHash) {
2589
+ return;
2590
+ }
2591
+ }
2592
+ // Access Token with Auth Scheme specific matching
2512
2593
  if (credentialType === CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
2513
2594
  if (!!tokenType && !_this.matchTokenType(entity, tokenType)) {
2514
2595
  return;
2515
2596
  }
2516
- // This check avoids matching outdated POP tokens that don't have the <-scheme> in the cache key
2517
- if (cacheKey.indexOf(exports.AuthenticationScheme.POP) === -1) {
2518
- // AccessToken_With_AuthScheme that doesn't have pop in the key is outdated
2519
- _this.removeItem(cacheKey, CacheSchemaType.CREDENTIAL);
2520
- return;
2597
+ // KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
2598
+ if (tokenType === exports.AuthenticationScheme.SSH) {
2599
+ if (keyId && !_this.matchKeyId(entity, keyId)) {
2600
+ return;
2601
+ }
2521
2602
  }
2522
2603
  }
2604
+ // At this point, the entity matches the request, update cache key if key schema has changed
2605
+ var updatedCacheKey = _this.updateCredentialCacheKey(cacheKey, entity);
2523
2606
  switch (credType) {
2524
2607
  case CredentialType.ID_TOKEN:
2525
- matchingCredentials.idTokens[cacheKey] = entity;
2608
+ matchingCredentials.idTokens[updatedCacheKey] = entity;
2526
2609
  break;
2527
2610
  case CredentialType.ACCESS_TOKEN:
2528
2611
  case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
2529
- matchingCredentials.accessTokens[cacheKey] = entity;
2612
+ matchingCredentials.accessTokens[updatedCacheKey] = entity;
2530
2613
  break;
2531
2614
  case CredentialType.REFRESH_TOKEN:
2532
- matchingCredentials.refreshTokens[cacheKey] = entity;
2615
+ matchingCredentials.refreshTokens[updatedCacheKey] = entity;
2533
2616
  break;
2534
2617
  }
2535
2618
  });
@@ -2688,6 +2771,7 @@
2688
2771
  case 0:
2689
2772
  key = credential.generateCredentialKey();
2690
2773
  if (!(credential.credentialType.toLowerCase() === CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase())) return [3 /*break*/, 4];
2774
+ if (!(credential.tokenType === exports.AuthenticationScheme.POP)) return [3 /*break*/, 4];
2691
2775
  accessTokenWithAuthSchemeEntity = credential;
2692
2776
  kid = accessTokenWithAuthSchemeEntity.keyId;
2693
2777
  if (!kid) return [3 /*break*/, 4];
@@ -2727,10 +2811,10 @@
2727
2811
  * @param environment
2728
2812
  * @param authScheme
2729
2813
  */
2730
- CacheManager.prototype.readCacheRecord = function (account, clientId, scopes, environment, authScheme) {
2814
+ CacheManager.prototype.readCacheRecord = function (account, clientId, request, environment) {
2731
2815
  var cachedAccount = this.readAccountFromCache(account);
2732
2816
  var cachedIdToken = this.readIdTokenFromCache(clientId, account);
2733
- var cachedAccessToken = this.readAccessTokenFromCache(clientId, account, scopes, authScheme);
2817
+ var cachedAccessToken = this.readAccessTokenFromCache(clientId, account, request);
2734
2818
  var cachedRefreshToken = this.readRefreshTokenFromCache(clientId, account, false);
2735
2819
  var cachedAppMetadata = this.readAppMetadataFromCache(environment, clientId);
2736
2820
  if (cachedAccount && cachedIdToken) {
@@ -2784,9 +2868,14 @@
2784
2868
  * @param scopes
2785
2869
  * @param authScheme
2786
2870
  */
2787
- CacheManager.prototype.readAccessTokenFromCache = function (clientId, account, scopes, authScheme) {
2788
- // Distinguish between Bearer and PoP token cache types
2789
- var credentialType = (authScheme === exports.AuthenticationScheme.POP) ? CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : CredentialType.ACCESS_TOKEN;
2871
+ CacheManager.prototype.readAccessTokenFromCache = function (clientId, account, request) {
2872
+ var scopes = new ScopeSet(request.scopes || []);
2873
+ var authScheme = request.authenticationScheme || exports.AuthenticationScheme.BEARER;
2874
+ /*
2875
+ * Distinguish between Bearer and PoP/SSH token cache types
2876
+ * Cast to lowercase to handle "bearer" from ADFS
2877
+ */
2878
+ var credentialType = (authScheme && authScheme.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : CredentialType.ACCESS_TOKEN;
2790
2879
  var accessTokenFilter = {
2791
2880
  homeAccountId: account.homeAccountId,
2792
2881
  environment: account.environment,
@@ -2794,7 +2883,9 @@
2794
2883
  clientId: clientId,
2795
2884
  realm: account.tenantId,
2796
2885
  target: scopes.printScopesLowerCase(),
2797
- tokenType: authScheme
2886
+ tokenType: authScheme,
2887
+ keyId: request.sshKid,
2888
+ requestedClaimsHash: request.requestedClaimsHash
2798
2889
  };
2799
2890
  var credentialCache = this.getCredentialsFilteredBy(accessTokenFilter);
2800
2891
  var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
@@ -2947,6 +3038,14 @@
2947
3038
  CacheManager.prototype.matchTokenType = function (entity, tokenType) {
2948
3039
  return !!(entity.tokenType && entity.tokenType === tokenType);
2949
3040
  };
3041
+ /**
3042
+ * Returns true if the credential's keyId matches the one in the request, false otherwise
3043
+ * @param entity
3044
+ * @param tokenType
3045
+ */
3046
+ CacheManager.prototype.matchKeyId = function (entity, keyId) {
3047
+ return !!(entity.keyId && entity.keyId === keyId);
3048
+ };
2950
3049
  /**
2951
3050
  * returns if a given cache entity is of the type appmetadata
2952
3051
  * @param key
@@ -3095,10 +3194,14 @@
3095
3194
  });
3096
3195
  });
3097
3196
  };
3197
+ DefaultStorageClass.prototype.updateCredentialCacheKey = function () {
3198
+ var notImplErr = "Storage interface - updateCredentialCacheKey() has not been implemented for the cacheStorage interface.";
3199
+ throw AuthError.createUnexpectedError(notImplErr);
3200
+ };
3098
3201
  return DefaultStorageClass;
3099
3202
  }(CacheManager));
3100
3203
 
3101
- /*! @azure/msal-common v5.0.0 2021-09-08 */
3204
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
3102
3205
 
3103
3206
  /*
3104
3207
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3180,7 +3283,7 @@
3180
3283
  return __assign({ clientCapabilities: [] }, authOptions);
3181
3284
  }
3182
3285
 
3183
- /*! @azure/msal-common v5.0.0 2021-09-08 */
3286
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
3184
3287
 
3185
3288
  /*
3186
3289
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3200,7 +3303,7 @@
3200
3303
  return ServerError;
3201
3304
  }(AuthError));
3202
3305
 
3203
- /*! @azure/msal-common v5.0.0 2021-09-08 */
3306
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
3204
3307
 
3205
3308
  /*
3206
3309
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3283,10 +3386,12 @@
3283
3386
  authority: request.authority,
3284
3387
  scopes: request.scopes,
3285
3388
  homeAccountIdentifier: homeAccountIdentifier,
3389
+ claims: request.claims,
3286
3390
  authenticationScheme: request.authenticationScheme,
3287
3391
  resourceRequestMethod: request.resourceRequestMethod,
3288
3392
  resourceRequestUri: request.resourceRequestUri,
3289
- shrClaims: request.shrClaims
3393
+ shrClaims: request.shrClaims,
3394
+ sshKid: request.sshKid
3290
3395
  };
3291
3396
  var key = this.generateThrottlingStorageKey(thumbprint);
3292
3397
  return cacheManager.removeItem(key, CacheSchemaType.THROTTLING);
@@ -3294,7 +3399,7 @@
3294
3399
  return ThrottlingUtils;
3295
3400
  }());
3296
3401
 
3297
- /*! @azure/msal-common v5.0.0 2021-09-08 */
3402
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
3298
3403
 
3299
3404
  /*
3300
3405
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3343,7 +3448,7 @@
3343
3448
  return NetworkManager;
3344
3449
  }());
3345
3450
 
3346
- /*! @azure/msal-common v5.0.0 2021-09-08 */
3451
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
3347
3452
  /*
3348
3453
  * Copyright (c) Microsoft Corporation. All rights reserved.
3349
3454
  * Licensed under the MIT License.
@@ -3354,7 +3459,7 @@
3354
3459
  CcsCredentialType["UPN"] = "UPN";
3355
3460
  })(CcsCredentialType || (CcsCredentialType = {}));
3356
3461
 
3357
- /*! @azure/msal-common v5.0.0 2021-09-08 */
3462
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
3358
3463
 
3359
3464
  /*
3360
3465
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3443,7 +3548,7 @@
3443
3548
  return BaseClient;
3444
3549
  }());
3445
3550
 
3446
- /*! @azure/msal-common v5.0.0 2021-09-08 */
3551
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
3447
3552
 
3448
3553
  /*
3449
3554
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3529,7 +3634,7 @@
3529
3634
  return RequestValidator;
3530
3635
  }());
3531
3636
 
3532
- /*! @azure/msal-common v5.0.0 2021-09-08 */
3637
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
3533
3638
 
3534
3639
  /*
3535
3640
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3833,6 +3938,15 @@
3833
3938
  this.parameters.set(AADServerParamKeys.REQ_CNF, encodeURIComponent(cnfString));
3834
3939
  }
3835
3940
  };
3941
+ /**
3942
+ * add SSH JWK and key ID to query params
3943
+ */
3944
+ RequestParameterBuilder.prototype.addSshJwk = function (sshJwkString) {
3945
+ if (!StringUtils.isEmpty(sshJwkString)) {
3946
+ this.parameters.set(AADServerParamKeys.TOKEN_TYPE, exports.AuthenticationScheme.SSH);
3947
+ this.parameters.set(AADServerParamKeys.REQ_CNF, encodeURIComponent(sshJwkString));
3948
+ }
3949
+ };
3836
3950
  /**
3837
3951
  * add server telemetry fields
3838
3952
  * @param serverTelemetryManager
@@ -3860,7 +3974,7 @@
3860
3974
  return RequestParameterBuilder;
3861
3975
  }());
3862
3976
 
3863
- /*! @azure/msal-common v5.0.0 2021-09-08 */
3977
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
3864
3978
 
3865
3979
  /*
3866
3980
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -3925,7 +4039,7 @@
3925
4039
  return IdTokenEntity;
3926
4040
  }(CredentialEntity));
3927
4041
 
3928
- /*! @azure/msal-common v5.0.0 2021-09-08 */
4042
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
3929
4043
  /*
3930
4044
  * Copyright (c) Microsoft Corporation. All rights reserved.
3931
4045
  * Licensed under the MIT License.
@@ -3975,7 +4089,7 @@
3975
4089
  return TimeUtils;
3976
4090
  }());
3977
4091
 
3978
- /*! @azure/msal-common v5.0.0 2021-09-08 */
4092
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
3979
4093
 
3980
4094
  /*
3981
4095
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4021,8 +4135,8 @@
4021
4135
  * @param expiresOn
4022
4136
  * @param extExpiresOn
4023
4137
  */
4024
- AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion) {
4025
- var _a;
4138
+ AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion, keyId, requestedClaims, requestedClaimsHash) {
4139
+ var _a, _b;
4026
4140
  var atEntity = new AccessTokenEntity();
4027
4141
  atEntity.homeAccountId = homeAccountId;
4028
4142
  atEntity.credentialType = CredentialType.ACCESS_TOKEN;
@@ -4044,15 +4158,28 @@
4044
4158
  atEntity.target = scopes;
4045
4159
  atEntity.oboAssertion = oboAssertion;
4046
4160
  atEntity.tokenType = StringUtils.isEmpty(tokenType) ? exports.AuthenticationScheme.BEARER : tokenType;
4047
- // Create Access Token With AuthScheme instead of regular access token
4048
- if (atEntity.tokenType === exports.AuthenticationScheme.POP) {
4161
+ if (requestedClaims) {
4162
+ atEntity.requestedClaims = requestedClaims;
4163
+ atEntity.requestedClaimsHash = requestedClaimsHash;
4164
+ }
4165
+ /*
4166
+ * Create Access Token With Auth Scheme instead of regular access token
4167
+ * Cast to lower to handle "bearer" from ADFS
4168
+ */
4169
+ if (((_a = atEntity.tokenType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== exports.AuthenticationScheme.BEARER.toLowerCase()) {
4049
4170
  atEntity.credentialType = CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;
4050
- // Make sure keyId is present and add it to credential
4051
- var tokenClaims = AuthToken.extractTokenClaims(accessToken, cryptoUtils);
4052
- if (!((_a = tokenClaims === null || tokenClaims === void 0 ? void 0 : tokenClaims.cnf) === null || _a === void 0 ? void 0 : _a.kid)) {
4053
- throw ClientAuthError.createTokenClaimsRequiredError();
4171
+ switch (atEntity.tokenType) {
4172
+ case exports.AuthenticationScheme.POP:
4173
+ // Make sure keyId is present and add it to credential
4174
+ var tokenClaims = AuthToken.extractTokenClaims(accessToken, cryptoUtils);
4175
+ if (!((_b = tokenClaims === null || tokenClaims === void 0 ? void 0 : tokenClaims.cnf) === null || _b === void 0 ? void 0 : _b.kid)) {
4176
+ throw ClientAuthError.createTokenClaimsRequiredError();
4177
+ }
4178
+ atEntity.keyId = tokenClaims.cnf.kid;
4179
+ break;
4180
+ case exports.AuthenticationScheme.SSH:
4181
+ atEntity.keyId = keyId;
4054
4182
  }
4055
- atEntity.keyId = tokenClaims.cnf.kid;
4056
4183
  }
4057
4184
  return atEntity;
4058
4185
  };
@@ -4076,7 +4203,7 @@
4076
4203
  return AccessTokenEntity;
4077
4204
  }(CredentialEntity));
4078
4205
 
4079
- /*! @azure/msal-common v5.0.0 2021-09-08 */
4206
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
4080
4207
 
4081
4208
  /*
4082
4209
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4143,16 +4270,16 @@
4143
4270
  return RefreshTokenEntity;
4144
4271
  }(CredentialEntity));
4145
4272
 
4146
- /*! @azure/msal-common v5.0.0 2021-09-08 */
4273
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
4147
4274
 
4148
4275
  /*
4149
4276
  * Copyright (c) Microsoft Corporation. All rights reserved.
4150
4277
  * Licensed under the MIT License.
4151
4278
  */
4152
4279
  /**
4153
- * InteractionRequiredAuthErrorMessage class containing string constants used by error codes and messages.
4280
+ * InteractionRequiredServerErrorMessage contains string constants used by error codes and messages returned by the server indicating interaction is required
4154
4281
  */
4155
- var InteractionRequiredAuthErrorMessage = [
4282
+ var InteractionRequiredServerErrorMessage = [
4156
4283
  "interaction_required",
4157
4284
  "consent_required",
4158
4285
  "login_required"
@@ -4165,7 +4292,16 @@
4165
4292
  "consent_required"
4166
4293
  ];
4167
4294
  /**
4168
- * Error thrown when user interaction is required at the auth server.
4295
+ * Interaction required errors defined by the SDK
4296
+ */
4297
+ var InteractionRequiredAuthErrorMessage = {
4298
+ noTokensFoundError: {
4299
+ code: "no_tokens_found",
4300
+ desc: "No refresh token found in the cache. Please sign-in."
4301
+ }
4302
+ };
4303
+ /**
4304
+ * Error thrown when user interaction is required.
4169
4305
  */
4170
4306
  var InteractionRequiredAuthError = /** @class */ (function (_super) {
4171
4307
  __extends(InteractionRequiredAuthError, _super);
@@ -4175,18 +4311,30 @@
4175
4311
  Object.setPrototypeOf(_this, InteractionRequiredAuthError.prototype);
4176
4312
  return _this;
4177
4313
  }
4314
+ /**
4315
+ * Helper function used to determine if an error thrown by the server requires interaction to resolve
4316
+ * @param errorCode
4317
+ * @param errorString
4318
+ * @param subError
4319
+ */
4178
4320
  InteractionRequiredAuthError.isInteractionRequiredError = function (errorCode, errorString, subError) {
4179
- var isInteractionRequiredErrorCode = !!errorCode && InteractionRequiredAuthErrorMessage.indexOf(errorCode) > -1;
4321
+ var isInteractionRequiredErrorCode = !!errorCode && InteractionRequiredServerErrorMessage.indexOf(errorCode) > -1;
4180
4322
  var isInteractionRequiredSubError = !!subError && InteractionRequiredAuthSubErrorMessage.indexOf(subError) > -1;
4181
- var isInteractionRequiredErrorDesc = !!errorString && InteractionRequiredAuthErrorMessage.some(function (irErrorCode) {
4323
+ var isInteractionRequiredErrorDesc = !!errorString && InteractionRequiredServerErrorMessage.some(function (irErrorCode) {
4182
4324
  return errorString.indexOf(irErrorCode) > -1;
4183
4325
  });
4184
4326
  return isInteractionRequiredErrorCode || isInteractionRequiredErrorDesc || isInteractionRequiredSubError;
4185
4327
  };
4328
+ /**
4329
+ * Creates an error thrown when the authorization code required for a token request is null or empty.
4330
+ */
4331
+ InteractionRequiredAuthError.createNoTokensFoundError = function () {
4332
+ return new InteractionRequiredAuthError(InteractionRequiredAuthErrorMessage.noTokensFoundError.code, InteractionRequiredAuthErrorMessage.noTokensFoundError.desc);
4333
+ };
4186
4334
  return InteractionRequiredAuthError;
4187
- }(ServerError));
4335
+ }(AuthError));
4188
4336
 
4189
- /*! @azure/msal-common v5.0.0 2021-09-08 */
4337
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
4190
4338
  /*
4191
4339
  * Copyright (c) Microsoft Corporation. All rights reserved.
4192
4340
  * Licensed under the MIT License.
@@ -4202,7 +4350,7 @@
4202
4350
  return CacheRecord;
4203
4351
  }());
4204
4352
 
4205
- /*! @azure/msal-common v5.0.0 2021-09-08 */
4353
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
4206
4354
 
4207
4355
  /*
4208
4356
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4273,7 +4421,7 @@
4273
4421
  return ProtocolUtils;
4274
4422
  }());
4275
4423
 
4276
- /*! @azure/msal-common v5.0.0 2021-09-08 */
4424
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
4277
4425
 
4278
4426
  /*
4279
4427
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4474,7 +4622,7 @@
4474
4622
  return UrlString;
4475
4623
  }());
4476
4624
 
4477
- /*! @azure/msal-common v5.0.0 2021-09-08 */
4625
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
4478
4626
 
4479
4627
  /*
4480
4628
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4533,14 +4681,14 @@
4533
4681
  };
4534
4682
  PopTokenGenerator.prototype.signPayload = function (payload, kid, request, claims) {
4535
4683
  return __awaiter(this, void 0, void 0, function () {
4536
- var resourceRequestMethod, resourceRequestUri, shrClaims, resourceUrlString, resourceUrlComponents;
4684
+ var resourceRequestMethod, resourceRequestUri, shrClaims, shrNonce, resourceUrlString, resourceUrlComponents;
4537
4685
  return __generator(this, function (_a) {
4538
4686
  switch (_a.label) {
4539
4687
  case 0:
4540
- resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims;
4688
+ resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims, shrNonce = request.shrNonce;
4541
4689
  resourceUrlString = (resourceRequestUri) ? new UrlString(resourceRequestUri) : undefined;
4542
4690
  resourceUrlComponents = resourceUrlString === null || resourceUrlString === void 0 ? void 0 : resourceUrlString.getUrlComponents();
4543
- 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: 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)];
4691
+ 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)];
4544
4692
  case 1: return [2 /*return*/, _a.sent()];
4545
4693
  }
4546
4694
  });
@@ -4549,7 +4697,7 @@
4549
4697
  return PopTokenGenerator;
4550
4698
  }());
4551
4699
 
4552
- /*! @azure/msal-common v5.0.0 2021-09-08 */
4700
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
4553
4701
 
4554
4702
  /*
4555
4703
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4619,7 +4767,7 @@
4619
4767
  return AppMetadataEntity;
4620
4768
  }());
4621
4769
 
4622
- /*! @azure/msal-common v5.0.0 2021-09-08 */
4770
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
4623
4771
  /*
4624
4772
  * Copyright (c) Microsoft Corporation. All rights reserved.
4625
4773
  * Licensed under the MIT License.
@@ -4655,7 +4803,7 @@
4655
4803
  return TokenCacheContext;
4656
4804
  }());
4657
4805
 
4658
- /*! @azure/msal-common v5.0.0 2021-09-08 */
4806
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
4659
4807
 
4660
4808
  /*
4661
4809
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4736,7 +4884,9 @@
4736
4884
  if (!!authCodePayload && !!authCodePayload.state) {
4737
4885
  requestStateObj = ProtocolUtils.parseRequestState(this.cryptoObj, authCodePayload.state);
4738
4886
  }
4739
- cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, idTokenObj, request.scopes, oboAssertion, authCodePayload);
4887
+ // Add keyId from request to serverTokenResponse if defined
4888
+ serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;
4889
+ cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload);
4740
4890
  _a.label = 1;
4741
4891
  case 1:
4742
4892
  _a.trys.push([1, , 5, 8]);
@@ -4773,7 +4923,7 @@
4773
4923
  _a.sent();
4774
4924
  _a.label = 7;
4775
4925
  case 7: return [7 /*endfinally*/];
4776
- case 8: return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj)];
4926
+ case 8: return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj, serverTokenResponse.spa_code)];
4777
4927
  }
4778
4928
  });
4779
4929
  });
@@ -4784,7 +4934,7 @@
4784
4934
  * @param idTokenObj
4785
4935
  * @param authority
4786
4936
  */
4787
- ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, idTokenObj, requestScopes, oboAssertion, authCodePayload) {
4937
+ ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload) {
4788
4938
  var env = authority.getPreferredCache();
4789
4939
  if (StringUtils.isEmpty(env)) {
4790
4940
  throw ClientAuthError.createInvalidCacheEnvironmentError();
@@ -4800,7 +4950,7 @@
4800
4950
  var cachedAccessToken = null;
4801
4951
  if (!StringUtils.isEmpty(serverTokenResponse.access_token)) {
4802
4952
  // If scopes not returned in server response, use request scopes
4803
- var responseScopes = serverTokenResponse.scope ? ScopeSet.fromString(serverTokenResponse.scope) : new ScopeSet(requestScopes || []);
4953
+ var responseScopes = serverTokenResponse.scope ? ScopeSet.fromString(serverTokenResponse.scope) : new ScopeSet(request.scopes || []);
4804
4954
  /*
4805
4955
  * Use timestamp calculated before request
4806
4956
  * Server may return timestamps as strings, parse to numbers if so.
@@ -4812,7 +4962,7 @@
4812
4962
  var extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;
4813
4963
  var refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;
4814
4964
  // non AAD scenarios can have empty realm
4815
- 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);
4965
+ 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);
4816
4966
  }
4817
4967
  // refreshToken
4818
4968
  var cachedRefreshToken = null;
@@ -4859,7 +5009,7 @@
4859
5009
  * @param fromTokenCache
4860
5010
  * @param stateString
4861
5011
  */
4862
- ResponseHandler.generateAuthenticationResult = function (cryptoObj, authority, cacheRecord, fromTokenCache, request, idTokenObj, requestState) {
5012
+ ResponseHandler.generateAuthenticationResult = function (cryptoObj, authority, cacheRecord, fromTokenCache, request, idTokenObj, requestState, code) {
4863
5013
  var _a, _b, _c;
4864
5014
  return __awaiter(this, void 0, void 0, function () {
4865
5015
  var accessToken, responseScopes, expiresOn, extExpiresOn, familyId, popTokenGenerator, uid, tid;
@@ -4908,7 +5058,8 @@
4908
5058
  tokenType: ((_a = cacheRecord.accessToken) === null || _a === void 0 ? void 0 : _a.tokenType) || Constants.EMPTY_STRING,
4909
5059
  state: requestState ? requestState.userRequestState : Constants.EMPTY_STRING,
4910
5060
  cloudGraphHostName: ((_b = cacheRecord.account) === null || _b === void 0 ? void 0 : _b.cloudGraphHostName) || Constants.EMPTY_STRING,
4911
- msGraphHost: ((_c = cacheRecord.account) === null || _c === void 0 ? void 0 : _c.msGraphHost) || Constants.EMPTY_STRING
5061
+ msGraphHost: ((_c = cacheRecord.account) === null || _c === void 0 ? void 0 : _c.msGraphHost) || Constants.EMPTY_STRING,
5062
+ code: code
4912
5063
  }];
4913
5064
  }
4914
5065
  });
@@ -4917,7 +5068,7 @@
4917
5068
  return ResponseHandler;
4918
5069
  }());
4919
5070
 
4920
- /*! @azure/msal-common v5.0.0 2021-09-08 */
5071
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
4921
5072
 
4922
5073
  /*
4923
5074
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -4929,7 +5080,10 @@
4929
5080
  var AuthorizationCodeClient = /** @class */ (function (_super) {
4930
5081
  __extends(AuthorizationCodeClient, _super);
4931
5082
  function AuthorizationCodeClient(configuration) {
4932
- return _super.call(this, configuration) || this;
5083
+ var _this = _super.call(this, configuration) || this;
5084
+ // Flag to indicate if client is for hybrid spa auth code redemption
5085
+ _this.includeRedirectUri = true;
5086
+ return _this;
4933
5087
  }
4934
5088
  /**
4935
5089
  * Creates the URL of the authorization request letting the user input credentials and consent to the
@@ -5029,10 +5183,12 @@
5029
5183
  clientId: this.config.authOptions.clientId,
5030
5184
  authority: authority.canonicalAuthority,
5031
5185
  scopes: request.scopes,
5186
+ claims: request.claims,
5032
5187
  authenticationScheme: request.authenticationScheme,
5033
5188
  resourceRequestMethod: request.resourceRequestMethod,
5034
5189
  resourceRequestUri: request.resourceRequestUri,
5035
- shrClaims: request.shrClaims
5190
+ shrClaims: request.shrClaims,
5191
+ sshKid: request.sshKid
5036
5192
  };
5037
5193
  return [4 /*yield*/, this.createTokenRequestBody(request)];
5038
5194
  case 1:
@@ -5076,13 +5232,24 @@
5076
5232
  AuthorizationCodeClient.prototype.createTokenRequestBody = function (request) {
5077
5233
  return __awaiter(this, void 0, void 0, function () {
5078
5234
  var parameterBuilder, clientAssertion, popTokenGenerator, cnfString, correlationId, ccsCred, clientInfo, clientInfo;
5079
- return __generator(this, function (_a) {
5080
- switch (_a.label) {
5235
+ var _a;
5236
+ return __generator(this, function (_b) {
5237
+ switch (_b.label) {
5081
5238
  case 0:
5082
5239
  parameterBuilder = new RequestParameterBuilder();
5083
5240
  parameterBuilder.addClientId(this.config.authOptions.clientId);
5084
- // validate the redirectUri (to be a non null value)
5085
- parameterBuilder.addRedirectUri(request.redirectUri);
5241
+ /*
5242
+ * For hybrid spa flow, there will be a code but no verifier
5243
+ * In this scenario, don't include redirect uri as auth code will not be bound to redirect URI
5244
+ */
5245
+ if (!this.includeRedirectUri) {
5246
+ // Just validate
5247
+ RequestValidator.validateRedirectUri(request.redirectUri);
5248
+ }
5249
+ else {
5250
+ // Validate and include redirect uri
5251
+ parameterBuilder.addRedirectUri(request.redirectUri);
5252
+ }
5086
5253
  // Add scope array, parameter builder will add default scopes and dedupe
5087
5254
  parameterBuilder.addScopes(request.scopes);
5088
5255
  // add code: user set, not validated
@@ -5111,10 +5278,20 @@
5111
5278
  popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5112
5279
  return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5113
5280
  case 1:
5114
- cnfString = _a.sent();
5281
+ cnfString = _b.sent();
5115
5282
  parameterBuilder.addPopToken(cnfString);
5116
- _a.label = 2;
5283
+ return [3 /*break*/, 3];
5117
5284
  case 2:
5285
+ if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
5286
+ if (request.sshJwk) {
5287
+ parameterBuilder.addSshJwk(request.sshJwk);
5288
+ }
5289
+ else {
5290
+ throw ClientConfigurationError.createMissingSshJwkError();
5291
+ }
5292
+ }
5293
+ _b.label = 3;
5294
+ case 3:
5118
5295
  correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
5119
5296
  parameterBuilder.addCorrelationId(correlationId);
5120
5297
  if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
@@ -5153,6 +5330,15 @@
5153
5330
  break;
5154
5331
  }
5155
5332
  }
5333
+ if (request.tokenBodyParameters) {
5334
+ parameterBuilder.addExtraQueryParameters(request.tokenBodyParameters);
5335
+ }
5336
+ // Add hybrid spa parameters if not already provided
5337
+ if (request.enableSpaAuthorizationCode && (!request.tokenBodyParameters || !request.tokenBodyParameters[AADServerParamKeys.RETURN_SPA_CODE])) {
5338
+ parameterBuilder.addExtraQueryParameters((_a = {},
5339
+ _a[AADServerParamKeys.RETURN_SPA_CODE] = "1",
5340
+ _a));
5341
+ }
5156
5342
  return [2 /*return*/, parameterBuilder.createQueryString()];
5157
5343
  }
5158
5344
  });
@@ -5290,7 +5476,7 @@
5290
5476
  return AuthorizationCodeClient;
5291
5477
  }(BaseClient));
5292
5478
 
5293
- /*! @azure/msal-common v5.0.0 2021-09-08 */
5479
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
5294
5480
 
5295
5481
  /*
5296
5482
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5344,7 +5530,7 @@
5344
5530
  return [2 /*return*/, this.acquireTokenWithCachedRefreshToken(request, true)];
5345
5531
  }
5346
5532
  catch (e) {
5347
- noFamilyRTInCache = e instanceof ClientAuthError && e.errorCode === ClientAuthErrorMessage.noTokensFoundError.code;
5533
+ noFamilyRTInCache = e instanceof InteractionRequiredAuthError && e.errorCode === InteractionRequiredAuthErrorMessage.noTokensFoundError.code;
5348
5534
  clientMismatchErrorWithFamilyRT = e instanceof ServerError && e.errorCode === Errors.INVALID_GRANT_ERROR && e.subError === Errors.CLIENT_MISMATCH_ERROR;
5349
5535
  // if family Refresh Token (FRT) cache acquisition fails or if client_mismatch error is seen with FRT, reattempt with application Refresh Token (ART)
5350
5536
  if (noFamilyRTInCache || clientMismatchErrorWithFamilyRT) {
@@ -5372,7 +5558,7 @@
5372
5558
  refreshToken = this.cacheManager.readRefreshTokenFromCache(this.config.authOptions.clientId, request.account, foci);
5373
5559
  // no refresh Token
5374
5560
  if (!refreshToken) {
5375
- throw ClientAuthError.createNoTokensFoundError();
5561
+ throw InteractionRequiredAuthError.createNoTokensFoundError();
5376
5562
  }
5377
5563
  refreshTokenRequest = __assign(__assign({}, request), { refreshToken: refreshToken.secret, authenticationScheme: request.authenticationScheme || exports.AuthenticationScheme.BEARER, ccsCredential: {
5378
5564
  credential: request.account.homeAccountId,
@@ -5401,10 +5587,12 @@
5401
5587
  clientId: this.config.authOptions.clientId,
5402
5588
  authority: authority.canonicalAuthority,
5403
5589
  scopes: request.scopes,
5590
+ claims: request.claims,
5404
5591
  authenticationScheme: request.authenticationScheme,
5405
5592
  resourceRequestMethod: request.resourceRequestMethod,
5406
5593
  resourceRequestUri: request.resourceRequestUri,
5407
- shrClaims: request.shrClaims
5594
+ shrClaims: request.shrClaims,
5595
+ sshKid: request.sshKid
5408
5596
  };
5409
5597
  endpoint = UrlString.appendQueryString(authority.tokenEndpoint, queryParameters);
5410
5598
  return [2 /*return*/, this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)];
@@ -5429,9 +5617,9 @@
5429
5617
  */
5430
5618
  RefreshTokenClient.prototype.createTokenRequestBody = function (request) {
5431
5619
  return __awaiter(this, void 0, void 0, function () {
5432
- var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, _a, _b, clientInfo;
5433
- return __generator(this, function (_c) {
5434
- switch (_c.label) {
5620
+ var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, cnfString, clientInfo;
5621
+ return __generator(this, function (_a) {
5622
+ switch (_a.label) {
5435
5623
  case 0:
5436
5624
  parameterBuilder = new RequestParameterBuilder();
5437
5625
  parameterBuilder.addClientId(this.config.authOptions.clientId);
@@ -5456,12 +5644,22 @@
5456
5644
  }
5457
5645
  if (!(request.authenticationScheme === exports.AuthenticationScheme.POP)) return [3 /*break*/, 2];
5458
5646
  popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5459
- _b = (_a = parameterBuilder).addPopToken;
5460
5647
  return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5461
5648
  case 1:
5462
- _b.apply(_a, [_c.sent()]);
5463
- _c.label = 2;
5649
+ cnfString = _a.sent();
5650
+ parameterBuilder.addPopToken(cnfString);
5651
+ return [3 /*break*/, 3];
5464
5652
  case 2:
5653
+ if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
5654
+ if (request.sshJwk) {
5655
+ parameterBuilder.addSshJwk(request.sshJwk);
5656
+ }
5657
+ else {
5658
+ throw ClientConfigurationError.createMissingSshJwkError();
5659
+ }
5660
+ }
5661
+ _a.label = 3;
5662
+ case 3:
5465
5663
  if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
5466
5664
  parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
5467
5665
  }
@@ -5489,7 +5687,7 @@
5489
5687
  return RefreshTokenClient;
5490
5688
  }(BaseClient));
5491
5689
 
5492
- /*! @azure/msal-common v5.0.0 2021-09-08 */
5690
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
5493
5691
 
5494
5692
  /*
5495
5693
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5535,7 +5733,7 @@
5535
5733
  SilentFlowClient.prototype.acquireCachedToken = function (request) {
5536
5734
  var _a, _b, _c, _d;
5537
5735
  return __awaiter(this, void 0, void 0, function () {
5538
- var requestScopes, environment, authScheme, cacheRecord;
5736
+ var environment, cacheRecord;
5539
5737
  return __generator(this, function (_e) {
5540
5738
  switch (_e.label) {
5541
5739
  case 0:
@@ -5543,37 +5741,35 @@
5543
5741
  if (!request) {
5544
5742
  throw ClientConfigurationError.createEmptyTokenRequestError();
5545
5743
  }
5546
- // We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
5547
- if (!request.account) {
5548
- throw ClientAuthError.createNoAccountInSilentRequestError();
5549
- }
5550
- requestScopes = new ScopeSet(request.scopes || []);
5551
- environment = request.authority || this.authority.getPreferredCache();
5552
- authScheme = request.authenticationScheme || exports.AuthenticationScheme.BEARER;
5553
- cacheRecord = this.cacheManager.readCacheRecord(request.account, this.config.authOptions.clientId, requestScopes, environment, authScheme);
5554
5744
  if (request.forceRefresh) {
5555
5745
  // Must refresh due to present force_refresh flag.
5556
5746
  (_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(CacheOutcome.FORCE_REFRESH);
5747
+ this.logger.info("SilentFlowClient:acquireCachedToken - Skipping cache because forceRefresh is true.");
5557
5748
  throw ClientAuthError.createRefreshRequiredError();
5558
5749
  }
5559
- else if (!cacheRecord.accessToken) {
5750
+ // We currently do not support silent flow for account === null use cases; This will be revisited for confidential flow usecases
5751
+ if (!request.account) {
5752
+ throw ClientAuthError.createNoAccountInSilentRequestError();
5753
+ }
5754
+ environment = request.authority || this.authority.getPreferredCache();
5755
+ cacheRecord = this.cacheManager.readCacheRecord(request.account, this.config.authOptions.clientId, request, environment);
5756
+ if (!cacheRecord.accessToken) {
5560
5757
  // Must refresh due to non-existent access_token.
5561
5758
  (_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
5759
+ this.logger.info("SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.");
5562
5760
  throw ClientAuthError.createRefreshRequiredError();
5563
5761
  }
5564
5762
  else if (TimeUtils.wasClockTurnedBack(cacheRecord.accessToken.cachedAt) ||
5565
5763
  TimeUtils.isTokenExpired(cacheRecord.accessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
5566
5764
  // Must refresh due to expired access_token.
5567
5765
  (_c = this.serverTelemetryManager) === null || _c === void 0 ? void 0 : _c.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
5766
+ this.logger.info("SilentFlowClient:acquireCachedToken - Cached access token is expired or will expire within " + this.config.systemOptions.tokenRenewalOffsetSeconds + " seconds.");
5568
5767
  throw ClientAuthError.createRefreshRequiredError();
5569
5768
  }
5570
5769
  else if (cacheRecord.accessToken.refreshOn && TimeUtils.isTokenExpired(cacheRecord.accessToken.refreshOn, 0)) {
5571
5770
  // Must refresh due to the refresh_in value.
5572
5771
  (_d = this.serverTelemetryManager) === null || _d === void 0 ? void 0 : _d.setCacheOutcome(CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN);
5573
- throw ClientAuthError.createRefreshRequiredError();
5574
- }
5575
- else if (!StringUtils.isEmptyObj(request.claims)) {
5576
- // Must refresh due to request parameters.
5772
+ this.logger.info("SilentFlowClient:acquireCachedToken - Cached access token's refreshOn property has been exceeded'.");
5577
5773
  throw ClientAuthError.createRefreshRequiredError();
5578
5774
  }
5579
5775
  if (this.config.serverTelemetryManager) {
@@ -5607,7 +5803,7 @@
5607
5803
  return SilentFlowClient;
5608
5804
  }(BaseClient));
5609
5805
 
5610
- /*! @azure/msal-common v5.0.0 2021-09-08 */
5806
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
5611
5807
  /*
5612
5808
  * Copyright (c) Microsoft Corporation. All rights reserved.
5613
5809
  * Licensed under the MIT License.
@@ -5615,11 +5811,10 @@
5615
5811
  function isOpenIdConfigResponse(response) {
5616
5812
  return (response.hasOwnProperty("authorization_endpoint") &&
5617
5813
  response.hasOwnProperty("token_endpoint") &&
5618
- response.hasOwnProperty("end_session_endpoint") &&
5619
5814
  response.hasOwnProperty("issuer"));
5620
5815
  }
5621
5816
 
5622
- /*! @azure/msal-common v5.0.0 2021-09-08 */
5817
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
5623
5818
  /*
5624
5819
  * Copyright (c) Microsoft Corporation. All rights reserved.
5625
5820
  * Licensed under the MIT License.
@@ -5633,7 +5828,7 @@
5633
5828
  ProtocolMode["OIDC"] = "OIDC";
5634
5829
  })(exports.ProtocolMode || (exports.ProtocolMode = {}));
5635
5830
 
5636
- /*! @azure/msal-common v5.0.0 2021-09-08 */
5831
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
5637
5832
 
5638
5833
  /*
5639
5834
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5700,7 +5895,6 @@
5700
5895
  entity.hasOwnProperty("canonical_authority") &&
5701
5896
  entity.hasOwnProperty("authorization_endpoint") &&
5702
5897
  entity.hasOwnProperty("token_endpoint") &&
5703
- entity.hasOwnProperty("end_session_endpoint") &&
5704
5898
  entity.hasOwnProperty("issuer") &&
5705
5899
  entity.hasOwnProperty("aliasesFromNetwork") &&
5706
5900
  entity.hasOwnProperty("endpointsFromNetwork") &&
@@ -5709,7 +5903,7 @@
5709
5903
  return AuthorityMetadataEntity;
5710
5904
  }());
5711
5905
 
5712
- /*! @azure/msal-common v5.0.0 2021-09-08 */
5906
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
5713
5907
  /*
5714
5908
  * Copyright (c) Microsoft Corporation. All rights reserved.
5715
5909
  * Licensed under the MIT License.
@@ -5719,7 +5913,7 @@
5719
5913
  response.hasOwnProperty("metadata"));
5720
5914
  }
5721
5915
 
5722
- /*! @azure/msal-common v5.0.0 2021-09-08 */
5916
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
5723
5917
 
5724
5918
  /*
5725
5919
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5833,7 +6027,7 @@
5833
6027
  return RegionDiscovery;
5834
6028
  }());
5835
6029
 
5836
- /*! @azure/msal-common v5.0.0 2021-09-08 */
6030
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
5837
6031
 
5838
6032
  /*
5839
6033
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -5987,6 +6181,10 @@
5987
6181
  */
5988
6182
  get: function () {
5989
6183
  if (this.discoveryComplete()) {
6184
+ // ROPC policies may not have end_session_endpoint set
6185
+ if (!this.metadata.end_session_endpoint) {
6186
+ throw ClientAuthError.createLogoutNotSupportedError();
6187
+ }
5990
6188
  var endpoint = this.replacePath(this.metadata.end_session_endpoint);
5991
6189
  return this.replaceTenant(endpoint);
5992
6190
  }
@@ -6387,13 +6585,15 @@
6387
6585
  metadata.authorization_endpoint = Authority.buildRegionalAuthorityString(metadata.authorization_endpoint, azureRegion);
6388
6586
  // TODO: Enquire on whether we should leave the query string or remove it before releasing the feature
6389
6587
  metadata.token_endpoint = Authority.buildRegionalAuthorityString(metadata.token_endpoint, azureRegion, "allowestsrnonmsi=true");
6390
- metadata.end_session_endpoint = Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
6588
+ if (metadata.end_session_endpoint) {
6589
+ metadata.end_session_endpoint = Authority.buildRegionalAuthorityString(metadata.end_session_endpoint, azureRegion);
6590
+ }
6391
6591
  return metadata;
6392
6592
  };
6393
6593
  return Authority;
6394
6594
  }());
6395
6595
 
6396
- /*! @azure/msal-common v5.0.0 2021-09-08 */
6596
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
6397
6597
 
6398
6598
  /*
6399
6599
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -6454,7 +6654,7 @@
6454
6654
  return AuthorityFactory;
6455
6655
  }());
6456
6656
 
6457
- /*! @azure/msal-common v5.0.0 2021-09-08 */
6657
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
6458
6658
 
6459
6659
  /*
6460
6660
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -6485,7 +6685,7 @@
6485
6685
  return ServerTelemetryEntity;
6486
6686
  }());
6487
6687
 
6488
- /*! @azure/msal-common v5.0.0 2021-09-08 */
6688
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
6489
6689
 
6490
6690
  /*
6491
6691
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -6513,7 +6713,7 @@
6513
6713
  return ThrottlingEntity;
6514
6714
  }());
6515
6715
 
6516
- /*! @azure/msal-common v5.0.0 2021-09-08 */
6716
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
6517
6717
 
6518
6718
  /*
6519
6719
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -6530,7 +6730,66 @@
6530
6730
  }
6531
6731
  };
6532
6732
 
6533
- /*! @azure/msal-common v5.0.0 2021-09-08 */
6733
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
6734
+
6735
+ /*
6736
+ * Copyright (c) Microsoft Corporation. All rights reserved.
6737
+ * Licensed under the MIT License.
6738
+ */
6739
+ /**
6740
+ * This is a helper class that parses supported HTTP response authentication headers to extract and return
6741
+ * header challenge values that can be used outside the basic authorization flows.
6742
+ */
6743
+ var AuthenticationHeaderParser = /** @class */ (function () {
6744
+ function AuthenticationHeaderParser(headers) {
6745
+ this.headers = headers;
6746
+ }
6747
+ /**
6748
+ * This method parses the SHR nonce value out of either the Authentication-Info or WWW-Authenticate authentication headers.
6749
+ * @returns
6750
+ */
6751
+ AuthenticationHeaderParser.prototype.getShrNonce = function () {
6752
+ // Attempt to parse nonce from Authentiacation-Info
6753
+ var authenticationInfo = this.headers[HeaderNames.AuthenticationInfo];
6754
+ if (authenticationInfo) {
6755
+ var authenticationInfoChallenges = this.parseChallenges(authenticationInfo);
6756
+ if (authenticationInfoChallenges.nextnonce) {
6757
+ return authenticationInfoChallenges.nextnonce;
6758
+ }
6759
+ throw ClientConfigurationError.createInvalidAuthenticationHeaderError(HeaderNames.AuthenticationInfo, "nextnonce challenge is missing.");
6760
+ }
6761
+ // Attempt to parse nonce from WWW-Authenticate
6762
+ var wwwAuthenticate = this.headers[HeaderNames.WWWAuthenticate];
6763
+ if (wwwAuthenticate) {
6764
+ var wwwAuthenticateChallenges = this.parseChallenges(wwwAuthenticate);
6765
+ if (wwwAuthenticateChallenges.nonce) {
6766
+ return wwwAuthenticateChallenges.nonce;
6767
+ }
6768
+ throw ClientConfigurationError.createInvalidAuthenticationHeaderError(HeaderNames.WWWAuthenticate, "nonce challenge is missing.");
6769
+ }
6770
+ // If neither header is present, throw missing headers error
6771
+ throw ClientConfigurationError.createMissingNonceAuthenticationHeadersError();
6772
+ };
6773
+ /**
6774
+ * Parses an HTTP header's challenge set into a key/value map.
6775
+ * @param header
6776
+ * @returns
6777
+ */
6778
+ AuthenticationHeaderParser.prototype.parseChallenges = function (header) {
6779
+ var schemeSeparator = header.indexOf(" ");
6780
+ var challenges = header.substr(schemeSeparator + 1).split(",");
6781
+ var challengeMap = {};
6782
+ challenges.forEach(function (challenge) {
6783
+ var _a = challenge.split("="), key = _a[0], value = _a[1];
6784
+ // Remove escaped quotation marks (', ") from challenge string to keep only the challenge value
6785
+ challengeMap[key] = unescape(value.replace(/['"]+/g, ""));
6786
+ });
6787
+ return challengeMap;
6788
+ };
6789
+ return AuthenticationHeaderParser;
6790
+ }());
6791
+
6792
+ /*! @azure/msal-common v6.0.0 2022-01-04 */
6534
6793
 
6535
6794
  /*
6536
6795
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -6783,6 +7042,7 @@
6783
7042
  ApiId[ApiId["ssoSilent"] = 863] = "ssoSilent";
6784
7043
  ApiId[ApiId["acquireTokenSilent_authCode"] = 864] = "acquireTokenSilent_authCode";
6785
7044
  ApiId[ApiId["handleRedirectPromise"] = 865] = "handleRedirectPromise";
7045
+ ApiId[ApiId["acquireTokenByCode"] = 866] = "acquireTokenByCode";
6786
7046
  ApiId[ApiId["acquireTokenSilent_silentFlow"] = 61] = "acquireTokenSilent_silentFlow";
6787
7047
  ApiId[ApiId["logout"] = 961] = "logout";
6788
7048
  ApiId[ApiId["logoutPopup"] = 962] = "logoutPopup";
@@ -6843,7 +7103,11 @@
6843
7103
  (function (WrapperSKU) {
6844
7104
  WrapperSKU["React"] = "@azure/msal-react";
6845
7105
  WrapperSKU["Angular"] = "@azure/msal-angular";
6846
- })(exports.WrapperSKU || (exports.WrapperSKU = {}));
7106
+ })(exports.WrapperSKU || (exports.WrapperSKU = {}));
7107
+ // DatabaseStorage Constants
7108
+ var DB_NAME = "msal.db";
7109
+ var DB_VERSION = 1;
7110
+ var DB_TABLE_NAME = DB_NAME + ".keys";
6847
7111
 
6848
7112
  /*
6849
7113
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -7305,10 +7569,6 @@
7305
7569
  code: "iframe_closed_prematurely",
7306
7570
  desc: "The iframe being monitored was closed prematurely."
7307
7571
  },
7308
- silentSSOInsufficientInfoError: {
7309
- code: "silent_sso_error",
7310
- desc: "Silent SSO could not be completed - insufficient information was provided. Please provide either a loginHint or sid."
7311
- },
7312
7572
  silentLogoutUnsupportedError: {
7313
7573
  code: "silent_logout_unsupported",
7314
7574
  desc: "Silent logout not supported. Please call logoutRedirect or logoutPopup instead."
@@ -7323,7 +7583,7 @@
7323
7583
  },
7324
7584
  noTokenRequestCacheError: {
7325
7585
  code: "no_token_request_cache_error",
7326
- desc: "No token request in found in cache."
7586
+ desc: "No token request found in cache."
7327
7587
  },
7328
7588
  unableToParseTokenRequestCacheError: {
7329
7589
  code: "unable_to_parse_token_request_cache_error",
@@ -7372,6 +7632,14 @@
7372
7632
  signingKeyNotFoundInStorage: {
7373
7633
  code: "crypto_key_not_found",
7374
7634
  desc: "Cryptographic Key or Keypair not found in browser storage."
7635
+ },
7636
+ authCodeRequired: {
7637
+ code: "auth_code_required",
7638
+ desc: "An authorization code must be provided (as the `code` property on the request) to this flow."
7639
+ },
7640
+ databaseUnavailable: {
7641
+ code: "database_unavailable",
7642
+ desc: "IndexedDB, which is required for persistent cryptographic key storage, is unavailable. This may be caused by browser privacy features which block persistent storage in third-party contexts."
7375
7643
  }
7376
7644
  };
7377
7645
  /**
@@ -7509,12 +7777,6 @@
7509
7777
  BrowserAuthError.createIframeClosedPrematurelyError = function () {
7510
7778
  return new BrowserAuthError(BrowserAuthErrorMessage.iframeClosedPrematurelyError.code, BrowserAuthErrorMessage.iframeClosedPrematurelyError.desc);
7511
7779
  };
7512
- /**
7513
- * Creates an error thrown when the login_hint, sid or account object is not provided in the ssoSilent API.
7514
- */
7515
- BrowserAuthError.createSilentSSOInsufficientInfoError = function () {
7516
- return new BrowserAuthError(BrowserAuthErrorMessage.silentSSOInsufficientInfoError.code, BrowserAuthErrorMessage.silentSSOInsufficientInfoError.desc);
7517
- };
7518
7780
  /**
7519
7781
  * Creates an error thrown when the logout API is called on any of the silent interaction clients
7520
7782
  */
@@ -7611,6 +7873,18 @@
7611
7873
  BrowserAuthError.createSigningKeyNotFoundInStorageError = function (keyId) {
7612
7874
  return new BrowserAuthError(BrowserAuthErrorMessage.signingKeyNotFoundInStorage.code, BrowserAuthErrorMessage.signingKeyNotFoundInStorage.desc + " | No match found for KeyId: " + keyId);
7613
7875
  };
7876
+ /**
7877
+ * Create an error when an authorization code is required but not provided
7878
+ */
7879
+ BrowserAuthError.createAuthCodeRequiredError = function () {
7880
+ return new BrowserAuthError(BrowserAuthErrorMessage.authCodeRequired.code, BrowserAuthErrorMessage.authCodeRequired.desc);
7881
+ };
7882
+ /**
7883
+ * Create an error when IndexedDB is unavailable
7884
+ */
7885
+ BrowserAuthError.createDatabaseUnavailableError = function () {
7886
+ return new BrowserAuthError(BrowserAuthErrorMessage.databaseUnavailable.code, BrowserAuthErrorMessage.databaseUnavailable.desc);
7887
+ };
7614
7888
  return BrowserAuthError;
7615
7889
  }(AuthError));
7616
7890
 
@@ -7713,7 +7987,8 @@
7713
7987
  * hashing and encoding. It also has helper functions to validate the availability of specific APIs.
7714
7988
  */
7715
7989
  var BrowserCrypto = /** @class */ (function () {
7716
- function BrowserCrypto() {
7990
+ function BrowserCrypto(logger) {
7991
+ this.logger = logger;
7717
7992
  if (!(this.hasCryptoAPI())) {
7718
7993
  throw BrowserAuthError.createCryptoNotAvailableError("Browser crypto or msCrypto object not available.");
7719
7994
  }
@@ -7972,10 +8247,10 @@
7972
8247
  * Storage wrapper for IndexedDB storage in browsers: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
7973
8248
  */
7974
8249
  var DatabaseStorage = /** @class */ (function () {
7975
- function DatabaseStorage(dbName, tableName, version) {
7976
- this.dbName = dbName;
7977
- this.tableName = tableName;
7978
- this.version = version;
8250
+ function DatabaseStorage() {
8251
+ this.dbName = DB_NAME;
8252
+ this.version = DB_VERSION;
8253
+ this.tableName = DB_TABLE_NAME;
7979
8254
  this.dbOpen = false;
7980
8255
  }
7981
8256
  /**
@@ -7986,7 +8261,6 @@
7986
8261
  var _this = this;
7987
8262
  return __generator$1(this, function (_a) {
7988
8263
  return [2 /*return*/, new Promise(function (resolve, reject) {
7989
- // TODO: Add timeouts?
7990
8264
  var openDB = window.indexedDB.open(_this.dbName, _this.version);
7991
8265
  openDB.addEventListener("upgradeneeded", function (e) {
7992
8266
  var event = e;
@@ -7998,40 +8272,53 @@
7998
8272
  _this.dbOpen = true;
7999
8273
  resolve();
8000
8274
  });
8001
- openDB.addEventListener("error", function (error) { return reject(error); });
8275
+ openDB.addEventListener("error", function () { return reject(BrowserAuthError.createDatabaseUnavailableError()); });
8002
8276
  })];
8003
8277
  });
8004
8278
  });
8005
8279
  };
8006
8280
  /**
8007
- * Retrieves item from IndexedDB instance.
8008
- * @param key
8281
+ * Opens database if it's not already open
8009
8282
  */
8010
- DatabaseStorage.prototype.get = function (key) {
8283
+ DatabaseStorage.prototype.validateDbIsOpen = function () {
8011
8284
  return __awaiter$1(this, void 0, void 0, function () {
8012
- var _this = this;
8013
8285
  return __generator$1(this, function (_a) {
8014
8286
  switch (_a.label) {
8015
8287
  case 0:
8016
8288
  if (!!this.dbOpen) return [3 /*break*/, 2];
8017
8289
  return [4 /*yield*/, this.open()];
8290
+ case 1: return [2 /*return*/, _a.sent()];
8291
+ case 2: return [2 /*return*/];
8292
+ }
8293
+ });
8294
+ });
8295
+ };
8296
+ /**
8297
+ * Retrieves item from IndexedDB instance.
8298
+ * @param key
8299
+ */
8300
+ DatabaseStorage.prototype.getItem = function (key) {
8301
+ return __awaiter$1(this, void 0, void 0, function () {
8302
+ var _this = this;
8303
+ return __generator$1(this, function (_a) {
8304
+ switch (_a.label) {
8305
+ case 0: return [4 /*yield*/, this.validateDbIsOpen()];
8018
8306
  case 1:
8019
8307
  _a.sent();
8020
- _a.label = 2;
8021
- case 2: return [2 /*return*/, new Promise(function (resolve, reject) {
8022
- // TODO: Add timeouts?
8023
- if (!_this.db) {
8024
- return reject(BrowserAuthError.createDatabaseNotOpenError());
8025
- }
8026
- var transaction = _this.db.transaction([_this.tableName], "readonly");
8027
- var objectStore = transaction.objectStore(_this.tableName);
8028
- var dbGet = objectStore.get(key);
8029
- dbGet.addEventListener("success", function (e) {
8030
- var event = e;
8031
- resolve(event.target.result);
8032
- });
8033
- dbGet.addEventListener("error", function (e) { return reject(e); });
8034
- })];
8308
+ return [2 /*return*/, new Promise(function (resolve, reject) {
8309
+ // TODO: Add timeouts?
8310
+ if (!_this.db) {
8311
+ return reject(BrowserAuthError.createDatabaseNotOpenError());
8312
+ }
8313
+ var transaction = _this.db.transaction([_this.tableName], "readonly");
8314
+ var objectStore = transaction.objectStore(_this.tableName);
8315
+ var dbGet = objectStore.get(key);
8316
+ dbGet.addEventListener("success", function (e) {
8317
+ var event = e;
8318
+ resolve(event.target.result);
8319
+ });
8320
+ dbGet.addEventListener("error", function (e) { return reject(e); });
8321
+ })];
8035
8322
  }
8036
8323
  });
8037
8324
  });
@@ -8041,31 +8328,25 @@
8041
8328
  * @param key
8042
8329
  * @param payload
8043
8330
  */
8044
- DatabaseStorage.prototype.put = function (key, payload) {
8331
+ DatabaseStorage.prototype.setItem = function (key, payload) {
8045
8332
  return __awaiter$1(this, void 0, void 0, function () {
8046
8333
  var _this = this;
8047
8334
  return __generator$1(this, function (_a) {
8048
8335
  switch (_a.label) {
8049
- case 0:
8050
- if (!!this.dbOpen) return [3 /*break*/, 2];
8051
- return [4 /*yield*/, this.open()];
8336
+ case 0: return [4 /*yield*/, this.validateDbIsOpen()];
8052
8337
  case 1:
8053
8338
  _a.sent();
8054
- _a.label = 2;
8055
- case 2: return [2 /*return*/, new Promise(function (resolve, reject) {
8056
- // TODO: Add timeouts?
8057
- if (!_this.db) {
8058
- return reject(BrowserAuthError.createDatabaseNotOpenError());
8059
- }
8060
- var transaction = _this.db.transaction([_this.tableName], "readwrite");
8061
- var objectStore = transaction.objectStore(_this.tableName);
8062
- var dbPut = objectStore.put(payload, key);
8063
- dbPut.addEventListener("success", function (e) {
8064
- var event = e;
8065
- resolve(event.target.result);
8066
- });
8067
- dbPut.addEventListener("error", function (e) { return reject(e); });
8068
- })];
8339
+ return [2 /*return*/, new Promise(function (resolve, reject) {
8340
+ // TODO: Add timeouts?
8341
+ if (!_this.db) {
8342
+ return reject(BrowserAuthError.createDatabaseNotOpenError());
8343
+ }
8344
+ var transaction = _this.db.transaction([_this.tableName], "readwrite");
8345
+ var objectStore = transaction.objectStore(_this.tableName);
8346
+ var dbPut = objectStore.put(payload, key);
8347
+ dbPut.addEventListener("success", function () { return resolve(); });
8348
+ dbPut.addEventListener("error", function (e) { return reject(e); });
8349
+ })];
8069
8350
  }
8070
8351
  });
8071
8352
  });
@@ -8074,62 +8355,101 @@
8074
8355
  * Removes item from IndexedDB under given key
8075
8356
  * @param key
8076
8357
  */
8077
- DatabaseStorage.prototype.delete = function (key) {
8358
+ DatabaseStorage.prototype.removeItem = function (key) {
8078
8359
  return __awaiter$1(this, void 0, void 0, function () {
8079
8360
  var _this = this;
8080
8361
  return __generator$1(this, function (_a) {
8081
8362
  switch (_a.label) {
8082
- case 0:
8083
- if (!!this.dbOpen) return [3 /*break*/, 2];
8084
- return [4 /*yield*/, this.open()];
8363
+ case 0: return [4 /*yield*/, this.validateDbIsOpen()];
8085
8364
  case 1:
8086
8365
  _a.sent();
8087
- _a.label = 2;
8088
- case 2: return [2 /*return*/, new Promise(function (resolve, reject) {
8089
- if (!_this.db) {
8090
- return reject(BrowserAuthError.createDatabaseNotOpenError());
8091
- }
8092
- var transaction = _this.db.transaction([_this.tableName], "readwrite");
8093
- var objectStore = transaction.objectStore(_this.tableName);
8094
- var dbDelete = objectStore.delete(key);
8095
- dbDelete.addEventListener("success", function (e) {
8096
- var event = e;
8097
- resolve(event.target.result === undefined);
8098
- });
8099
- dbDelete.addEventListener("error", function (e) { return reject(e); });
8100
- })];
8366
+ return [2 /*return*/, new Promise(function (resolve, reject) {
8367
+ if (!_this.db) {
8368
+ return reject(BrowserAuthError.createDatabaseNotOpenError());
8369
+ }
8370
+ var transaction = _this.db.transaction([_this.tableName], "readwrite");
8371
+ var objectStore = transaction.objectStore(_this.tableName);
8372
+ var dbDelete = objectStore.delete(key);
8373
+ dbDelete.addEventListener("success", function () { return resolve(); });
8374
+ dbDelete.addEventListener("error", function (e) { return reject(e); });
8375
+ })];
8101
8376
  }
8102
8377
  });
8103
8378
  });
8104
8379
  };
8105
- DatabaseStorage.prototype.clear = function () {
8380
+ /**
8381
+ * Get all the keys from the storage object as an iterable array of strings.
8382
+ */
8383
+ DatabaseStorage.prototype.getKeys = function () {
8106
8384
  return __awaiter$1(this, void 0, void 0, function () {
8107
8385
  var _this = this;
8108
8386
  return __generator$1(this, function (_a) {
8109
8387
  switch (_a.label) {
8110
- case 0:
8111
- if (!!this.dbOpen) return [3 /*break*/, 2];
8112
- return [4 /*yield*/, this.open()];
8388
+ case 0: return [4 /*yield*/, this.validateDbIsOpen()];
8113
8389
  case 1:
8114
8390
  _a.sent();
8115
- _a.label = 2;
8116
- case 2: return [2 /*return*/, new Promise(function (resolve, reject) {
8117
- if (!_this.db) {
8118
- return reject(BrowserAuthError.createDatabaseNotOpenError());
8119
- }
8120
- var transaction = _this.db.transaction([_this.tableName], "readwrite");
8121
- var objectStore = transaction.objectStore(_this.tableName);
8122
- var dbDelete = objectStore.clear();
8123
- dbDelete.addEventListener("success", function (e) {
8124
- var event = e;
8125
- resolve(event.target.result === undefined);
8126
- });
8127
- dbDelete.addEventListener("error", function (e) { return reject(e); });
8128
- })];
8391
+ return [2 /*return*/, new Promise(function (resolve, reject) {
8392
+ if (!_this.db) {
8393
+ return reject(BrowserAuthError.createDatabaseNotOpenError());
8394
+ }
8395
+ var transaction = _this.db.transaction([_this.tableName], "readonly");
8396
+ var objectStore = transaction.objectStore(_this.tableName);
8397
+ var dbGetKeys = objectStore.getAllKeys();
8398
+ dbGetKeys.addEventListener("success", function (e) {
8399
+ var event = e;
8400
+ resolve(event.target.result);
8401
+ });
8402
+ dbGetKeys.addEventListener("error", function (e) { return reject(e); });
8403
+ })];
8404
+ }
8405
+ });
8406
+ });
8407
+ };
8408
+ /**
8409
+ *
8410
+ * Checks whether there is an object under the search key in the object store
8411
+ */
8412
+ DatabaseStorage.prototype.containsKey = function (key) {
8413
+ return __awaiter$1(this, void 0, void 0, function () {
8414
+ var _this = this;
8415
+ return __generator$1(this, function (_a) {
8416
+ switch (_a.label) {
8417
+ case 0: return [4 /*yield*/, this.validateDbIsOpen()];
8418
+ case 1:
8419
+ _a.sent();
8420
+ return [2 /*return*/, new Promise(function (resolve, reject) {
8421
+ if (!_this.db) {
8422
+ return reject(BrowserAuthError.createDatabaseNotOpenError());
8423
+ }
8424
+ var transaction = _this.db.transaction([_this.tableName], "readonly");
8425
+ var objectStore = transaction.objectStore(_this.tableName);
8426
+ var dbContainsKey = objectStore.count(key);
8427
+ dbContainsKey.addEventListener("success", function (e) {
8428
+ var event = e;
8429
+ resolve(event.target.result === 1);
8430
+ });
8431
+ dbContainsKey.addEventListener("error", function (e) { return reject(e); });
8432
+ })];
8129
8433
  }
8130
8434
  });
8131
8435
  });
8132
8436
  };
8437
+ /**
8438
+ * Deletes the MSAL database. The database is deleted rather than cleared to make it possible
8439
+ * for client applications to downgrade to a previous MSAL version without worrying about forward compatibility issues
8440
+ * with IndexedDB database versions.
8441
+ */
8442
+ DatabaseStorage.prototype.deleteDatabase = function () {
8443
+ return __awaiter$1(this, void 0, void 0, function () {
8444
+ return __generator$1(this, function (_a) {
8445
+ return [2 /*return*/, new Promise(function (resolve, reject) {
8446
+ var deleteDbRequest = window.indexedDB.deleteDatabase(DB_NAME);
8447
+ deleteDbRequest.addEventListener("success", function () { return resolve(true); });
8448
+ deleteDbRequest.addEventListener("error", function () { return reject(false); });
8449
+ })];
8450
+ });
8451
+ });
8452
+ };
8133
8453
  return DatabaseStorage;
8134
8454
  }());
8135
8455
 
@@ -8137,31 +8457,254 @@
8137
8457
  * Copyright (c) Microsoft Corporation. All rights reserved.
8138
8458
  * Licensed under the MIT License.
8139
8459
  */
8140
- /**
8141
- * This class implements MSAL's crypto interface, which allows it to perform base64 encoding and decoding, generating cryptographically random GUIDs and
8142
- * implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
8143
- */
8144
- var CryptoOps = /** @class */ (function () {
8145
- function CryptoOps() {
8146
- // Browser crypto needs to be validated first before any other classes can be set.
8147
- this.browserCrypto = new BrowserCrypto();
8148
- this.b64Encode = new Base64Encode();
8149
- this.b64Decode = new Base64Decode();
8150
- this.guidGenerator = new GuidGenerator(this.browserCrypto);
8151
- this.pkceGenerator = new PkceGenerator(this.browserCrypto);
8152
- this.cache = new DatabaseStorage(CryptoOps.DB_NAME, CryptoOps.TABLE_NAME, CryptoOps.DB_VERSION);
8460
+ var MemoryStorage = /** @class */ (function () {
8461
+ function MemoryStorage() {
8462
+ this.cache = new Map();
8153
8463
  }
8154
- /**
8155
- * Creates a new random GUID - used to populate state and nonce.
8156
- * @returns string (GUID)
8157
- */
8158
- CryptoOps.prototype.createNewGuid = function () {
8159
- return this.guidGenerator.generateGuid();
8464
+ MemoryStorage.prototype.getItem = function (key) {
8465
+ return this.cache.get(key) || null;
8160
8466
  };
8161
- /**
8162
- * Encodes input string to base64.
8163
- * @param input
8164
- */
8467
+ MemoryStorage.prototype.setItem = function (key, value) {
8468
+ this.cache.set(key, value);
8469
+ };
8470
+ MemoryStorage.prototype.removeItem = function (key) {
8471
+ this.cache.delete(key);
8472
+ };
8473
+ MemoryStorage.prototype.getKeys = function () {
8474
+ var cacheKeys = [];
8475
+ this.cache.forEach(function (value, key) {
8476
+ cacheKeys.push(key);
8477
+ });
8478
+ return cacheKeys;
8479
+ };
8480
+ MemoryStorage.prototype.containsKey = function (key) {
8481
+ return this.cache.has(key);
8482
+ };
8483
+ MemoryStorage.prototype.clear = function () {
8484
+ this.cache.clear();
8485
+ };
8486
+ return MemoryStorage;
8487
+ }());
8488
+
8489
+ /*
8490
+ * Copyright (c) Microsoft Corporation. All rights reserved.
8491
+ * Licensed under the MIT License.
8492
+ */
8493
+ /**
8494
+ * This class allows MSAL to store artifacts asynchronously using the DatabaseStorage IndexedDB wrapper,
8495
+ * backed up with the more volatile MemoryStorage object for cases in which IndexedDB may be unavailable.
8496
+ */
8497
+ var AsyncMemoryStorage = /** @class */ (function () {
8498
+ function AsyncMemoryStorage(logger) {
8499
+ this.inMemoryCache = new MemoryStorage();
8500
+ this.indexedDBCache = new DatabaseStorage();
8501
+ this.logger = logger;
8502
+ }
8503
+ AsyncMemoryStorage.prototype.handleDatabaseAccessError = function (error) {
8504
+ if (error instanceof BrowserAuthError && error.errorCode === BrowserAuthErrorMessage.databaseUnavailable.code) {
8505
+ this.logger.error("Could not access persistent storage. This may be caused by browser privacy features which block persistent storage in third-party contexts.");
8506
+ }
8507
+ };
8508
+ /**
8509
+ * Get the item matching the given key. Tries in-memory cache first, then in the asynchronous
8510
+ * storage object if item isn't found in-memory.
8511
+ * @param key
8512
+ */
8513
+ AsyncMemoryStorage.prototype.getItem = function (key) {
8514
+ return __awaiter$1(this, void 0, void 0, function () {
8515
+ var item, e_1;
8516
+ return __generator$1(this, function (_a) {
8517
+ switch (_a.label) {
8518
+ case 0:
8519
+ item = this.inMemoryCache.getItem(key);
8520
+ if (!!item) return [3 /*break*/, 4];
8521
+ _a.label = 1;
8522
+ case 1:
8523
+ _a.trys.push([1, 3, , 4]);
8524
+ this.logger.verbose("Queried item not found in in-memory cache, now querying persistent storage.");
8525
+ return [4 /*yield*/, this.indexedDBCache.getItem(key)];
8526
+ case 2: return [2 /*return*/, _a.sent()];
8527
+ case 3:
8528
+ e_1 = _a.sent();
8529
+ this.handleDatabaseAccessError(e_1);
8530
+ return [3 /*break*/, 4];
8531
+ case 4: return [2 /*return*/, item];
8532
+ }
8533
+ });
8534
+ });
8535
+ };
8536
+ /**
8537
+ * Sets the item in the in-memory cache and then tries to set it in the asynchronous
8538
+ * storage object with the given key.
8539
+ * @param key
8540
+ * @param value
8541
+ */
8542
+ AsyncMemoryStorage.prototype.setItem = function (key, value) {
8543
+ return __awaiter$1(this, void 0, void 0, function () {
8544
+ var e_2;
8545
+ return __generator$1(this, function (_a) {
8546
+ switch (_a.label) {
8547
+ case 0:
8548
+ this.inMemoryCache.setItem(key, value);
8549
+ _a.label = 1;
8550
+ case 1:
8551
+ _a.trys.push([1, 3, , 4]);
8552
+ return [4 /*yield*/, this.indexedDBCache.setItem(key, value)];
8553
+ case 2:
8554
+ _a.sent();
8555
+ return [3 /*break*/, 4];
8556
+ case 3:
8557
+ e_2 = _a.sent();
8558
+ this.handleDatabaseAccessError(e_2);
8559
+ return [3 /*break*/, 4];
8560
+ case 4: return [2 /*return*/];
8561
+ }
8562
+ });
8563
+ });
8564
+ };
8565
+ /**
8566
+ * Removes the item matching the key from the in-memory cache, then tries to remove it from the asynchronous storage object.
8567
+ * @param key
8568
+ */
8569
+ AsyncMemoryStorage.prototype.removeItem = function (key) {
8570
+ return __awaiter$1(this, void 0, void 0, function () {
8571
+ var e_3;
8572
+ return __generator$1(this, function (_a) {
8573
+ switch (_a.label) {
8574
+ case 0:
8575
+ this.inMemoryCache.removeItem(key);
8576
+ _a.label = 1;
8577
+ case 1:
8578
+ _a.trys.push([1, 3, , 4]);
8579
+ return [4 /*yield*/, this.indexedDBCache.removeItem(key)];
8580
+ case 2:
8581
+ _a.sent();
8582
+ return [3 /*break*/, 4];
8583
+ case 3:
8584
+ e_3 = _a.sent();
8585
+ this.handleDatabaseAccessError(e_3);
8586
+ return [3 /*break*/, 4];
8587
+ case 4: return [2 /*return*/];
8588
+ }
8589
+ });
8590
+ });
8591
+ };
8592
+ /**
8593
+ * Get all the keys from the in-memory cache as an iterable array of strings. If no keys are found, query the keys in the
8594
+ * asynchronous storage object.
8595
+ */
8596
+ AsyncMemoryStorage.prototype.getKeys = function () {
8597
+ return __awaiter$1(this, void 0, void 0, function () {
8598
+ var cacheKeys, e_4;
8599
+ return __generator$1(this, function (_a) {
8600
+ switch (_a.label) {
8601
+ case 0:
8602
+ cacheKeys = this.inMemoryCache.getKeys();
8603
+ if (!(cacheKeys.length === 0)) return [3 /*break*/, 4];
8604
+ _a.label = 1;
8605
+ case 1:
8606
+ _a.trys.push([1, 3, , 4]);
8607
+ this.logger.verbose("In-memory cache is empty, now querying persistent storage.");
8608
+ return [4 /*yield*/, this.indexedDBCache.getKeys()];
8609
+ case 2: return [2 /*return*/, _a.sent()];
8610
+ case 3:
8611
+ e_4 = _a.sent();
8612
+ this.handleDatabaseAccessError(e_4);
8613
+ return [3 /*break*/, 4];
8614
+ case 4: return [2 /*return*/, cacheKeys];
8615
+ }
8616
+ });
8617
+ });
8618
+ };
8619
+ /**
8620
+ * Returns true or false if the given key is present in the cache.
8621
+ * @param key
8622
+ */
8623
+ AsyncMemoryStorage.prototype.containsKey = function (key) {
8624
+ return __awaiter$1(this, void 0, void 0, function () {
8625
+ var containsKey, e_5;
8626
+ return __generator$1(this, function (_a) {
8627
+ switch (_a.label) {
8628
+ case 0:
8629
+ containsKey = this.inMemoryCache.containsKey(key);
8630
+ if (!!containsKey) return [3 /*break*/, 4];
8631
+ _a.label = 1;
8632
+ case 1:
8633
+ _a.trys.push([1, 3, , 4]);
8634
+ this.logger.verbose("Key not found in in-memory cache, now querying persistent storage.");
8635
+ return [4 /*yield*/, this.indexedDBCache.containsKey(key)];
8636
+ case 2: return [2 /*return*/, _a.sent()];
8637
+ case 3:
8638
+ e_5 = _a.sent();
8639
+ this.handleDatabaseAccessError(e_5);
8640
+ return [3 /*break*/, 4];
8641
+ case 4: return [2 /*return*/, containsKey];
8642
+ }
8643
+ });
8644
+ });
8645
+ };
8646
+ /**
8647
+ * Clears in-memory Map and tries to delete the IndexedDB database.
8648
+ */
8649
+ AsyncMemoryStorage.prototype.clear = function () {
8650
+ return __awaiter$1(this, void 0, void 0, function () {
8651
+ var e_6;
8652
+ return __generator$1(this, function (_a) {
8653
+ switch (_a.label) {
8654
+ case 0:
8655
+ this.inMemoryCache.clear();
8656
+ _a.label = 1;
8657
+ case 1:
8658
+ _a.trys.push([1, 3, , 4]);
8659
+ return [4 /*yield*/, this.indexedDBCache.deleteDatabase()];
8660
+ case 2:
8661
+ _a.sent();
8662
+ return [3 /*break*/, 4];
8663
+ case 3:
8664
+ e_6 = _a.sent();
8665
+ this.handleDatabaseAccessError(e_6);
8666
+ return [3 /*break*/, 4];
8667
+ case 4: return [2 /*return*/];
8668
+ }
8669
+ });
8670
+ });
8671
+ };
8672
+ return AsyncMemoryStorage;
8673
+ }());
8674
+
8675
+ /*
8676
+ * Copyright (c) Microsoft Corporation. All rights reserved.
8677
+ * Licensed under the MIT License.
8678
+ */
8679
+ /**
8680
+ * This class implements MSAL's crypto interface, which allows it to perform base64 encoding and decoding, generating cryptographically random GUIDs and
8681
+ * implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
8682
+ */
8683
+ var CryptoOps = /** @class */ (function () {
8684
+ function CryptoOps(logger) {
8685
+ this.logger = logger;
8686
+ // Browser crypto needs to be validated first before any other classes can be set.
8687
+ this.browserCrypto = new BrowserCrypto(this.logger);
8688
+ this.b64Encode = new Base64Encode();
8689
+ this.b64Decode = new Base64Decode();
8690
+ this.guidGenerator = new GuidGenerator(this.browserCrypto);
8691
+ this.pkceGenerator = new PkceGenerator(this.browserCrypto);
8692
+ this.cache = {
8693
+ asymmetricKeys: new AsyncMemoryStorage(this.logger),
8694
+ symmetricKeys: new AsyncMemoryStorage(this.logger)
8695
+ };
8696
+ }
8697
+ /**
8698
+ * Creates a new random GUID - used to populate state and nonce.
8699
+ * @returns string (GUID)
8700
+ */
8701
+ CryptoOps.prototype.createNewGuid = function () {
8702
+ return this.guidGenerator.generateGuid();
8703
+ };
8704
+ /**
8705
+ * Encodes input string to base64.
8706
+ * @param input
8707
+ */
8165
8708
  CryptoOps.prototype.base64Encode = function (input) {
8166
8709
  return this.b64Encode.encode(input);
8167
8710
  };
@@ -8188,7 +8731,7 @@
8188
8731
  */
8189
8732
  CryptoOps.prototype.getPublicKeyThumbprint = function (request) {
8190
8733
  return __awaiter$1(this, void 0, void 0, function () {
8191
- var keyPair, publicKeyJwk, pubKeyThumprintObj, publicJwkString, publicJwkBuffer, publicJwkHash, privateKeyJwk, unextractablePrivateKey;
8734
+ var keyPair, publicKeyJwk, pubKeyThumprintObj, publicJwkString, publicJwkHash, privateKeyJwk, unextractablePrivateKey;
8192
8735
  return __generator$1(this, function (_a) {
8193
8736
  switch (_a.label) {
8194
8737
  case 0: return [4 /*yield*/, this.browserCrypto.generateKeyPair(CryptoOps.EXTRACTABLE, CryptoOps.POP_KEY_USAGES)];
@@ -8203,10 +8746,9 @@
8203
8746
  n: publicKeyJwk.n
8204
8747
  };
8205
8748
  publicJwkString = BrowserCrypto.getJwkString(pubKeyThumprintObj);
8206
- return [4 /*yield*/, this.browserCrypto.sha256Digest(publicJwkString)];
8749
+ return [4 /*yield*/, this.hashString(publicJwkString)];
8207
8750
  case 3:
8208
- publicJwkBuffer = _a.sent();
8209
- publicJwkHash = this.b64Encode.urlEncodeArr(new Uint8Array(publicJwkBuffer));
8751
+ publicJwkHash = _a.sent();
8210
8752
  return [4 /*yield*/, this.browserCrypto.exportJwk(keyPair.privateKey)];
8211
8753
  case 4:
8212
8754
  privateKeyJwk = _a.sent();
@@ -8214,7 +8756,7 @@
8214
8756
  case 5:
8215
8757
  unextractablePrivateKey = _a.sent();
8216
8758
  // Store Keypair data in keystore
8217
- return [4 /*yield*/, this.cache.put(publicJwkHash, {
8759
+ return [4 /*yield*/, this.cache.asymmetricKeys.setItem(publicJwkHash, {
8218
8760
  privateKey: unextractablePrivateKey,
8219
8761
  publicKey: keyPair.publicKey,
8220
8762
  requestMethod: request.resourceRequestMethod,
@@ -8234,8 +8776,17 @@
8234
8776
  */
8235
8777
  CryptoOps.prototype.removeTokenBindingKey = function (kid) {
8236
8778
  return __awaiter$1(this, void 0, void 0, function () {
8779
+ var keyFound;
8237
8780
  return __generator$1(this, function (_a) {
8238
- return [2 /*return*/, this.cache.delete(kid)];
8781
+ switch (_a.label) {
8782
+ case 0: return [4 /*yield*/, this.cache.asymmetricKeys.removeItem(kid)];
8783
+ case 1:
8784
+ _a.sent();
8785
+ return [4 /*yield*/, this.cache.asymmetricKeys.containsKey(kid)];
8786
+ case 2:
8787
+ keyFound = _a.sent();
8788
+ return [2 /*return*/, !keyFound];
8789
+ }
8239
8790
  });
8240
8791
  });
8241
8792
  };
@@ -8244,8 +8795,22 @@
8244
8795
  */
8245
8796
  CryptoOps.prototype.clearKeystore = function () {
8246
8797
  return __awaiter$1(this, void 0, void 0, function () {
8247
- return __generator$1(this, function (_a) {
8248
- return [2 /*return*/, this.cache.clear()];
8798
+ var dataStoreNames, databaseStorage, _a;
8799
+ return __generator$1(this, function (_b) {
8800
+ switch (_b.label) {
8801
+ case 0:
8802
+ dataStoreNames = Object.keys(this.cache);
8803
+ databaseStorage = this.cache[dataStoreNames[0]];
8804
+ if (!databaseStorage) return [3 /*break*/, 2];
8805
+ return [4 /*yield*/, databaseStorage.deleteDatabase()];
8806
+ case 1:
8807
+ _a = _b.sent();
8808
+ return [3 /*break*/, 3];
8809
+ case 2:
8810
+ _a = false;
8811
+ _b.label = 3;
8812
+ case 3: return [2 /*return*/, _a];
8813
+ }
8249
8814
  });
8250
8815
  });
8251
8816
  };
@@ -8259,7 +8824,7 @@
8259
8824
  var cachedKeyPair, publicKeyJwk, publicKeyJwkString, header, encodedHeader, encodedPayload, tokenString, tokenBuffer, signatureBuffer, encodedSignature;
8260
8825
  return __generator$1(this, function (_a) {
8261
8826
  switch (_a.label) {
8262
- case 0: return [4 /*yield*/, this.cache.get(kid)];
8827
+ case 0: return [4 /*yield*/, this.cache.asymmetricKeys.getItem(kid)];
8263
8828
  case 1:
8264
8829
  cachedKeyPair = _a.sent();
8265
8830
  if (!cachedKeyPair) {
@@ -8290,11 +8855,26 @@
8290
8855
  });
8291
8856
  });
8292
8857
  };
8858
+ /**
8859
+ * Returns the SHA-256 hash of an input string
8860
+ * @param plainText
8861
+ */
8862
+ CryptoOps.prototype.hashString = function (plainText) {
8863
+ return __awaiter$1(this, void 0, void 0, function () {
8864
+ var hashBuffer, hashBytes;
8865
+ return __generator$1(this, function (_a) {
8866
+ switch (_a.label) {
8867
+ case 0: return [4 /*yield*/, this.browserCrypto.sha256Digest(plainText)];
8868
+ case 1:
8869
+ hashBuffer = _a.sent();
8870
+ hashBytes = new Uint8Array(hashBuffer);
8871
+ return [2 /*return*/, this.b64Encode.urlEncodeArr(hashBytes)];
8872
+ }
8873
+ });
8874
+ });
8875
+ };
8293
8876
  CryptoOps.POP_KEY_USAGES = ["sign", "verify"];
8294
8877
  CryptoOps.EXTRACTABLE = true;
8295
- CryptoOps.DB_VERSION = 1;
8296
- CryptoOps.DB_NAME = "msal.db";
8297
- CryptoOps.TABLE_NAME = CryptoOps.DB_NAME + ".keys";
8298
8878
  return CryptoOps;
8299
8879
  }());
8300
8880
 
@@ -8424,39 +9004,6 @@
8424
9004
  return BrowserStorage;
8425
9005
  }());
8426
9006
 
8427
- /*
8428
- * Copyright (c) Microsoft Corporation. All rights reserved.
8429
- * Licensed under the MIT License.
8430
- */
8431
- var MemoryStorage = /** @class */ (function () {
8432
- function MemoryStorage() {
8433
- this.cache = new Map();
8434
- }
8435
- MemoryStorage.prototype.getItem = function (key) {
8436
- return this.cache.get(key) || null;
8437
- };
8438
- MemoryStorage.prototype.setItem = function (key, value) {
8439
- this.cache.set(key, value);
8440
- };
8441
- MemoryStorage.prototype.removeItem = function (key) {
8442
- this.cache.delete(key);
8443
- };
8444
- MemoryStorage.prototype.getKeys = function () {
8445
- var cacheKeys = [];
8446
- this.cache.forEach(function (value, key) {
8447
- cacheKeys.push(key);
8448
- });
8449
- return cacheKeys;
8450
- };
8451
- MemoryStorage.prototype.containsKey = function (key) {
8452
- return this.cache.has(key);
8453
- };
8454
- MemoryStorage.prototype.clear = function () {
8455
- this.cache.clear();
8456
- };
8457
- return MemoryStorage;
8458
- }());
8459
-
8460
9007
  /*
8461
9008
  * Copyright (c) Microsoft Corporation. All rights reserved.
8462
9009
  * Licensed under the MIT License.
@@ -9247,6 +9794,7 @@
9247
9794
  }
9248
9795
  });
9249
9796
  this.clearMsalCookies();
9797
+ this.setInteractionInProgress(false);
9250
9798
  };
9251
9799
  BrowserCacheManager.prototype.cacheCodeRequest = function (authCodeRequest, browserCrypto) {
9252
9800
  this.logger.trace("BrowserCacheManager.cacheCodeRequest called");
@@ -9304,6 +9852,58 @@
9304
9852
  this.removeItem(key);
9305
9853
  }
9306
9854
  };
9855
+ /**
9856
+ * Returns username retrieved from ADAL or MSAL v1 idToken
9857
+ */
9858
+ BrowserCacheManager.prototype.getLegacyLoginHint = function () {
9859
+ // Only check for adal/msal token if no SSO params are being used
9860
+ var adalIdTokenString = this.getTemporaryCache(PersistentCacheKeys.ADAL_ID_TOKEN);
9861
+ if (adalIdTokenString) {
9862
+ this.browserStorage.removeItem(PersistentCacheKeys.ADAL_ID_TOKEN);
9863
+ this.logger.verbose("Cached ADAL id token retrieved.");
9864
+ }
9865
+ // Check for cached MSAL v1 id token
9866
+ var msalIdTokenString = this.getTemporaryCache(PersistentCacheKeys.ID_TOKEN, true);
9867
+ if (msalIdTokenString) {
9868
+ this.removeItem(this.generateCacheKey(PersistentCacheKeys.ID_TOKEN));
9869
+ this.logger.verbose("Cached MSAL.js v1 id token retrieved");
9870
+ }
9871
+ var cachedIdTokenString = msalIdTokenString || adalIdTokenString;
9872
+ if (cachedIdTokenString) {
9873
+ var cachedIdToken = new AuthToken(cachedIdTokenString, this.cryptoImpl);
9874
+ if (cachedIdToken.claims && cachedIdToken.claims.preferred_username) {
9875
+ this.logger.verbose("No SSO params used and ADAL/MSAL v1 token retrieved, setting ADAL/MSAL v1 preferred_username as loginHint");
9876
+ return cachedIdToken.claims.preferred_username;
9877
+ }
9878
+ else if (cachedIdToken.claims && cachedIdToken.claims.upn) {
9879
+ this.logger.verbose("No SSO params used and ADAL/MSAL v1 token retrieved, setting ADAL/MSAL v1 upn as loginHint");
9880
+ return cachedIdToken.claims.upn;
9881
+ }
9882
+ else {
9883
+ this.logger.verbose("No SSO params used and ADAL/MSAL v1 token retrieved, however, no account hint claim found. Enable preferred_username or upn id token claim to get SSO.");
9884
+ }
9885
+ }
9886
+ return null;
9887
+ };
9888
+ /**
9889
+ * Updates a credential's cache key if the current cache key is outdated
9890
+ */
9891
+ BrowserCacheManager.prototype.updateCredentialCacheKey = function (currentCacheKey, credential) {
9892
+ var updatedCacheKey = credential.generateCredentialKey();
9893
+ if (currentCacheKey !== updatedCacheKey) {
9894
+ var cacheItem = this.getItem(currentCacheKey);
9895
+ if (cacheItem) {
9896
+ this.removeItem(currentCacheKey);
9897
+ this.setItem(updatedCacheKey, cacheItem);
9898
+ this.logger.verbose("Updated an outdated " + credential.credentialType + " cache key");
9899
+ return updatedCacheKey;
9900
+ }
9901
+ else {
9902
+ this.logger.error("Attempted to update an outdated " + credential.credentialType + " cache key but no item matching the outdated key was found in storage");
9903
+ }
9904
+ }
9905
+ return currentCacheKey;
9906
+ };
9307
9907
  return BrowserCacheManager;
9308
9908
  }(CacheManager));
9309
9909
  var DEFAULT_BROWSER_CACHE_MANAGER = function (clientId, logger) {
@@ -9804,7 +10404,7 @@
9804
10404
 
9805
10405
  /* eslint-disable header/header */
9806
10406
  var name = "@azure/msal-browser";
9807
- var version = "2.17.0";
10407
+ var version = "2.21.0";
9808
10408
 
9809
10409
  /*
9810
10410
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -9812,6 +10412,8 @@
9812
10412
  */
9813
10413
  exports.EventType = void 0;
9814
10414
  (function (EventType) {
10415
+ EventType["ACCOUNT_ADDED"] = "msal:accountAdded";
10416
+ EventType["ACCOUNT_REMOVED"] = "msal:accountRemoved";
9815
10417
  EventType["LOGIN_START"] = "msal:loginStart";
9816
10418
  EventType["LOGIN_SUCCESS"] = "msal:loginSuccess";
9817
10419
  EventType["LOGIN_FAILURE"] = "msal:loginFailure";
@@ -9822,6 +10424,9 @@
9822
10424
  EventType["SSO_SILENT_START"] = "msal:ssoSilentStart";
9823
10425
  EventType["SSO_SILENT_SUCCESS"] = "msal:ssoSilentSuccess";
9824
10426
  EventType["SSO_SILENT_FAILURE"] = "msal:ssoSilentFailure";
10427
+ EventType["ACQUIRE_TOKEN_BY_CODE_START"] = "msal:acquireTokenByCodeStart";
10428
+ EventType["ACQUIRE_TOKEN_BY_CODE_SUCCESS"] = "msal:acquireTokenByCodeSuccess";
10429
+ EventType["ACQUIRE_TOKEN_BY_CODE_FAILURE"] = "msal:acquireTokenByCodeFailure";
9825
10430
  EventType["HANDLE_REDIRECT_START"] = "msal:handleRedirectStart";
9826
10431
  EventType["HANDLE_REDIRECT_END"] = "msal:handleRedirectEnd";
9827
10432
  EventType["POPUP_OPENED"] = "msal:popupOpened";
@@ -9840,6 +10445,8 @@
9840
10445
  this.eventCallbacks = new Map();
9841
10446
  this.logger = logger;
9842
10447
  this.browserCrypto = browserCrypto;
10448
+ this.listeningToStorageEvents = false;
10449
+ this.handleAccountCacheChange = this.handleAccountCacheChange.bind(this);
9843
10450
  }
9844
10451
  /**
9845
10452
  * Adds event callbacks to array
@@ -9862,6 +10469,38 @@
9862
10469
  this.eventCallbacks.delete(callbackId);
9863
10470
  this.logger.verbose("Event callback " + callbackId + " removed.");
9864
10471
  };
10472
+ /**
10473
+ * Adds event listener that emits an event when a user account is added or removed from localstorage in a different browser tab or window
10474
+ */
10475
+ EventHandler.prototype.enableAccountStorageEvents = function () {
10476
+ if (typeof window === "undefined") {
10477
+ return;
10478
+ }
10479
+ if (!this.listeningToStorageEvents) {
10480
+ this.logger.verbose("Adding account storage listener.");
10481
+ this.listeningToStorageEvents = true;
10482
+ window.addEventListener("storage", this.handleAccountCacheChange);
10483
+ }
10484
+ else {
10485
+ this.logger.verbose("Account storage listener already registered.");
10486
+ }
10487
+ };
10488
+ /**
10489
+ * Removes event listener that emits an event when a user account is added or removed from localstorage in a different browser tab or window
10490
+ */
10491
+ EventHandler.prototype.disableAccountStorageEvents = function () {
10492
+ if (typeof window === "undefined") {
10493
+ return;
10494
+ }
10495
+ if (this.listeningToStorageEvents) {
10496
+ this.logger.verbose("Removing account storage listener.");
10497
+ window.removeEventListener("storage", this.handleAccountCacheChange);
10498
+ this.listeningToStorageEvents = false;
10499
+ }
10500
+ else {
10501
+ this.logger.verbose("No account storage listener registered.");
10502
+ }
10503
+ };
9865
10504
  /**
9866
10505
  * Emits events by calling callback with event message
9867
10506
  * @param eventType
@@ -9886,6 +10525,34 @@
9886
10525
  });
9887
10526
  }
9888
10527
  };
10528
+ /**
10529
+ * Emit account added/removed events when cached accounts are changed in a different tab or frame
10530
+ */
10531
+ EventHandler.prototype.handleAccountCacheChange = function (e) {
10532
+ try {
10533
+ var cacheValue = e.newValue || e.oldValue;
10534
+ if (!cacheValue) {
10535
+ return;
10536
+ }
10537
+ var parsedValue = JSON.parse(cacheValue);
10538
+ if (typeof parsedValue !== "object" || !AccountEntity.isAccountEntity(parsedValue)) {
10539
+ return;
10540
+ }
10541
+ var accountEntity = CacheManager.toObject(new AccountEntity(), parsedValue);
10542
+ var accountInfo = accountEntity.getAccountInfo();
10543
+ if (!e.oldValue && e.newValue) {
10544
+ this.logger.info("Account was added to cache in a different window");
10545
+ this.emitEvent(exports.EventType.ACCOUNT_ADDED, undefined, accountInfo);
10546
+ }
10547
+ else if (!e.newValue && e.oldValue) {
10548
+ this.logger.info("Account was removed from cache in a different window");
10549
+ this.emitEvent(exports.EventType.ACCOUNT_REMOVED, undefined, accountInfo);
10550
+ }
10551
+ }
10552
+ catch (e) {
10553
+ return;
10554
+ }
10555
+ };
9889
10556
  return EventHandler;
9890
10557
  }());
9891
10558
 
@@ -9949,6 +10616,79 @@
9949
10616
  });
9950
10617
  });
9951
10618
  };
10619
+ /**
10620
+ * Initializer function for all request APIs
10621
+ * @param request
10622
+ */
10623
+ BaseInteractionClient.prototype.initializeBaseRequest = function (request) {
10624
+ return __awaiter$1(this, void 0, void 0, function () {
10625
+ var authority, scopes, _a, validatedRequest;
10626
+ return __generator$1(this, function (_b) {
10627
+ switch (_b.label) {
10628
+ case 0:
10629
+ this.logger.verbose("Initializing BaseAuthRequest");
10630
+ authority = request.authority || this.config.auth.authority;
10631
+ scopes = __spread(((request && request.scopes) || []));
10632
+ // Set authenticationScheme to BEARER if not explicitly set in the request
10633
+ if (!request.authenticationScheme) {
10634
+ request.authenticationScheme = exports.AuthenticationScheme.BEARER;
10635
+ this.logger.verbose("Authentication Scheme wasn't explicitly set in request, defaulting to \"Bearer\" request");
10636
+ }
10637
+ else {
10638
+ if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
10639
+ if (!request.sshJwk) {
10640
+ throw ClientConfigurationError.createMissingSshJwkError();
10641
+ }
10642
+ if (!request.sshKid) {
10643
+ throw ClientConfigurationError.createMissingSshKidError();
10644
+ }
10645
+ }
10646
+ this.logger.verbose("Authentication Scheme set to \"" + request.authenticationScheme + "\" as configured in Auth request");
10647
+ }
10648
+ if (!(request.claims && !StringUtils.isEmpty(request.claims))) return [3 /*break*/, 2];
10649
+ _a = request;
10650
+ return [4 /*yield*/, this.browserCrypto.hashString(request.claims)];
10651
+ case 1:
10652
+ _a.requestedClaimsHash = _b.sent();
10653
+ _b.label = 2;
10654
+ case 2:
10655
+ validatedRequest = __assign$1(__assign$1({}, request), { correlationId: this.correlationId, authority: authority,
10656
+ scopes: scopes });
10657
+ return [2 /*return*/, validatedRequest];
10658
+ }
10659
+ });
10660
+ });
10661
+ };
10662
+ /**
10663
+ *
10664
+ * Use to get the redirect uri configured in MSAL or null.
10665
+ * @param requestRedirectUri
10666
+ * @returns Redirect URL
10667
+ *
10668
+ */
10669
+ BaseInteractionClient.prototype.getRedirectUri = function (requestRedirectUri) {
10670
+ this.logger.verbose("getRedirectUri called");
10671
+ var redirectUri = requestRedirectUri || this.config.auth.redirectUri || BrowserUtils.getCurrentUri();
10672
+ return UrlString.getAbsoluteUrl(redirectUri, BrowserUtils.getCurrentUri());
10673
+ };
10674
+ /**
10675
+ *
10676
+ * @param apiId
10677
+ * @param correlationId
10678
+ * @param forceRefresh
10679
+ */
10680
+ BaseInteractionClient.prototype.initializeServerTelemetryManager = function (apiId, forceRefresh) {
10681
+ this.logger.verbose("initializeServerTelemetryManager called");
10682
+ var telemetryPayload = {
10683
+ clientId: this.config.auth.clientId,
10684
+ correlationId: this.correlationId,
10685
+ apiId: apiId,
10686
+ forceRefresh: forceRefresh || false,
10687
+ wrapperSKU: this.browserStorage.getWrapperMetadata()[0],
10688
+ wrapperVer: this.browserStorage.getWrapperMetadata()[1]
10689
+ };
10690
+ return new ServerTelemetryManager(telemetryPayload, this.browserStorage);
10691
+ };
9952
10692
  return BaseInteractionClient;
9953
10693
  }());
9954
10694
 
@@ -10141,122 +10881,68 @@
10141
10881
  });
10142
10882
  });
10143
10883
  };
10144
- /**
10145
- *
10146
- * @param apiId
10147
- * @param correlationId
10148
- * @param forceRefresh
10149
- */
10150
- StandardInteractionClient.prototype.initializeServerTelemetryManager = function (apiId, forceRefresh) {
10151
- this.logger.verbose("initializeServerTelemetryManager called");
10152
- var telemetryPayload = {
10153
- clientId: this.config.auth.clientId,
10154
- correlationId: this.correlationId,
10155
- apiId: apiId,
10156
- forceRefresh: forceRefresh || false,
10157
- wrapperSKU: this.browserStorage.getWrapperMetadata()[0],
10158
- wrapperVer: this.browserStorage.getWrapperMetadata()[1]
10159
- };
10160
- return new ServerTelemetryManager(telemetryPayload, this.browserStorage);
10161
- };
10162
10884
  /**
10163
10885
  * Helper to validate app environment before making a request.
10164
10886
  * @param request
10165
10887
  * @param interactionType
10166
10888
  */
10167
10889
  StandardInteractionClient.prototype.preflightInteractiveRequest = function (request, interactionType) {
10168
- this.logger.verbose("preflightInteractiveRequest called, validating app environment", request === null || request === void 0 ? void 0 : request.correlationId);
10169
- // block the reload if it occurred inside a hidden iframe
10170
- BrowserUtils.blockReloadInHiddenIframes();
10171
- // Check if interaction is in progress. Throw error if true.
10172
- if (this.browserStorage.isInteractionInProgress(false)) {
10173
- throw BrowserAuthError.createInteractionInProgressError();
10174
- }
10175
- return this.initializeAuthorizationRequest(request, interactionType);
10176
- };
10177
- /**
10178
- * Helper to initialize required request parameters for interactive APIs and ssoSilent()
10179
- * @param request
10180
- * @param interactionType
10181
- */
10182
- StandardInteractionClient.prototype.initializeAuthorizationRequest = function (request, interactionType) {
10183
- this.logger.verbose("initializeAuthorizationRequest called");
10184
- var redirectUri = this.getRedirectUri(request.redirectUri);
10185
- var browserState = {
10186
- interactionType: interactionType
10187
- };
10188
- var state = ProtocolUtils.setRequestState(this.browserCrypto, (request && request.state) || "", browserState);
10189
- var validatedRequest = __assign$1(__assign$1({}, this.initializeBaseRequest(request)), { redirectUri: redirectUri, state: state, nonce: request.nonce || this.browserCrypto.createNewGuid(), responseMode: ResponseMode.FRAGMENT });
10190
- var account = request.account || this.browserStorage.getActiveAccount();
10191
- if (account) {
10192
- this.logger.verbose("Setting validated request account");
10193
- this.logger.verbosePii("Setting validated request account: " + account);
10194
- validatedRequest.account = account;
10195
- }
10196
- // Check for ADAL/MSAL v1 SSO
10197
- if (StringUtils.isEmpty(validatedRequest.loginHint) && !account) {
10198
- // Only check for adal/msal token if no SSO params are being used
10199
- var adalIdTokenString = this.browserStorage.getTemporaryCache(PersistentCacheKeys.ADAL_ID_TOKEN);
10200
- if (adalIdTokenString) {
10201
- this.browserStorage.removeItem(PersistentCacheKeys.ADAL_ID_TOKEN);
10202
- this.logger.verbose("Cached ADAL id token retrieved.");
10203
- }
10204
- // Check for cached MSAL v1 id token
10205
- var msalIdTokenString = this.browserStorage.getTemporaryCache(PersistentCacheKeys.ID_TOKEN, true);
10206
- if (msalIdTokenString) {
10207
- this.browserStorage.removeItem(this.browserStorage.generateCacheKey(PersistentCacheKeys.ID_TOKEN));
10208
- this.logger.verbose("Cached MSAL.js v1 id token retrieved");
10209
- }
10210
- var cachedIdTokenString = msalIdTokenString || adalIdTokenString;
10211
- if (cachedIdTokenString) {
10212
- var cachedIdToken = new AuthToken(cachedIdTokenString, this.browserCrypto);
10213
- if (cachedIdToken.claims && cachedIdToken.claims.preferred_username) {
10214
- this.logger.verbose("No SSO params used and ADAL/MSAL v1 token retrieved, setting ADAL/MSAL v1 preferred_username as loginHint");
10215
- validatedRequest.loginHint = cachedIdToken.claims.preferred_username;
10216
- }
10217
- else if (cachedIdToken.claims && cachedIdToken.claims.upn) {
10218
- this.logger.verbose("No SSO params used and ADAL/MSAL v1 token retrieved, setting ADAL/MSAL v1 upn as loginHint");
10219
- validatedRequest.loginHint = cachedIdToken.claims.upn;
10220
- }
10221
- else {
10222
- this.logger.verbose("No SSO params used and ADAL/MSAL v1 token retrieved, however, no account hint claim found. Enable preferred_username or upn id token claim to get SSO.");
10890
+ return __awaiter$1(this, void 0, void 0, function () {
10891
+ return __generator$1(this, function (_a) {
10892
+ switch (_a.label) {
10893
+ case 0:
10894
+ this.logger.verbose("preflightInteractiveRequest called, validating app environment", request === null || request === void 0 ? void 0 : request.correlationId);
10895
+ // block the reload if it occurred inside a hidden iframe
10896
+ BrowserUtils.blockReloadInHiddenIframes();
10897
+ // Check if interaction is in progress. Throw error if true.
10898
+ if (this.browserStorage.isInteractionInProgress(false)) {
10899
+ throw BrowserAuthError.createInteractionInProgressError();
10900
+ }
10901
+ return [4 /*yield*/, this.initializeAuthorizationRequest(request, interactionType)];
10902
+ case 1: return [2 /*return*/, _a.sent()];
10223
10903
  }
10224
- }
10225
- }
10226
- this.browserStorage.updateCacheEntries(validatedRequest.state, validatedRequest.nonce, validatedRequest.authority, validatedRequest.loginHint || "", validatedRequest.account || null);
10227
- return validatedRequest;
10228
- };
10229
- /**
10230
- * Initializer function for all request APIs
10231
- * @param request
10232
- */
10233
- StandardInteractionClient.prototype.initializeBaseRequest = function (request) {
10234
- this.logger.verbose("Initializing BaseAuthRequest");
10235
- var authority = request.authority || this.config.auth.authority;
10236
- var scopes = __spread(((request && request.scopes) || []));
10237
- // Set authenticationScheme to BEARER if not explicitly set in the request
10238
- if (!request.authenticationScheme) {
10239
- request.authenticationScheme = exports.AuthenticationScheme.BEARER;
10240
- this.logger.verbose("Authentication Scheme wasn't explicitly set in request, defaulting to \"Bearer\" request");
10241
- }
10242
- else {
10243
- this.logger.verbose("Authentication Scheme set to \"" + request.authenticationScheme + "\" as configured in Auth request");
10244
- }
10245
- var validatedRequest = __assign$1(__assign$1({}, request), { correlationId: this.correlationId, authority: authority,
10246
- scopes: scopes });
10247
- return validatedRequest;
10904
+ });
10905
+ });
10248
10906
  };
10249
10907
  /**
10250
- *
10251
- * Use to get the redirect uri configured in MSAL or null.
10252
- * @param requestRedirectUri
10253
- * @returns Redirect URL
10254
- *
10908
+ * Helper to initialize required request parameters for interactive APIs and ssoSilent()
10909
+ * @param request
10910
+ * @param interactionType
10255
10911
  */
10256
- StandardInteractionClient.prototype.getRedirectUri = function (requestRedirectUri) {
10257
- this.logger.verbose("getRedirectUri called");
10258
- var redirectUri = requestRedirectUri || this.config.auth.redirectUri || BrowserUtils.getCurrentUri();
10259
- return UrlString.getAbsoluteUrl(redirectUri, BrowserUtils.getCurrentUri());
10912
+ StandardInteractionClient.prototype.initializeAuthorizationRequest = function (request, interactionType) {
10913
+ return __awaiter$1(this, void 0, void 0, function () {
10914
+ var redirectUri, browserState, state, validatedRequest, _a, account, legacyLoginHint;
10915
+ return __generator$1(this, function (_b) {
10916
+ switch (_b.label) {
10917
+ case 0:
10918
+ this.logger.verbose("initializeAuthorizationRequest called");
10919
+ redirectUri = this.getRedirectUri(request.redirectUri);
10920
+ browserState = {
10921
+ interactionType: interactionType
10922
+ };
10923
+ state = ProtocolUtils.setRequestState(this.browserCrypto, (request && request.state) || "", browserState);
10924
+ _a = [{}];
10925
+ return [4 /*yield*/, this.initializeBaseRequest(request)];
10926
+ case 1:
10927
+ validatedRequest = __assign$1.apply(void 0, [__assign$1.apply(void 0, _a.concat([_b.sent()])), { redirectUri: redirectUri, state: state, nonce: request.nonce || this.browserCrypto.createNewGuid(), responseMode: ResponseMode.FRAGMENT }]);
10928
+ account = request.account || this.browserStorage.getActiveAccount();
10929
+ if (account) {
10930
+ this.logger.verbose("Setting validated request account");
10931
+ this.logger.verbosePii("Setting validated request account: " + account);
10932
+ validatedRequest.account = account;
10933
+ }
10934
+ // Check for ADAL/MSAL v1 SSO
10935
+ if (StringUtils.isEmpty(validatedRequest.loginHint) && !account) {
10936
+ legacyLoginHint = this.browserStorage.getLegacyLoginHint();
10937
+ if (legacyLoginHint) {
10938
+ validatedRequest.loginHint = legacyLoginHint;
10939
+ }
10940
+ }
10941
+ this.browserStorage.updateCacheEntries(validatedRequest.state, validatedRequest.nonce, validatedRequest.authority, validatedRequest.loginHint || "", validatedRequest.account || null);
10942
+ return [2 /*return*/, validatedRequest];
10943
+ }
10944
+ });
10945
+ });
10260
10946
  };
10261
10947
  return StandardInteractionClient;
10262
10948
  }(BaseInteractionClient));
@@ -10456,23 +11142,46 @@
10456
11142
  * Function to handle response parameters from hash.
10457
11143
  * @param locationHash
10458
11144
  */
10459
- InteractionHandler.prototype.handleCodeResponse = function (locationHash, state, authority, networkModule) {
11145
+ InteractionHandler.prototype.handleCodeResponseFromHash = function (locationHash, state, authority, networkModule) {
10460
11146
  return __awaiter$1(this, void 0, void 0, function () {
10461
- var stateKey, requestState, authCodeResponse, nonceKey, cachedNonce, cachedCcsCred, tokenResponse;
11147
+ var stateKey, requestState, authCodeResponse;
11148
+ return __generator$1(this, function (_a) {
11149
+ this.browserRequestLogger.verbose("InteractionHandler.handleCodeResponse called");
11150
+ // Check that location hash isn't empty.
11151
+ if (StringUtils.isEmpty(locationHash)) {
11152
+ throw BrowserAuthError.createEmptyHashError(locationHash);
11153
+ }
11154
+ stateKey = this.browserStorage.generateStateKey(state);
11155
+ requestState = this.browserStorage.getTemporaryCache(stateKey);
11156
+ if (!requestState) {
11157
+ throw ClientAuthError.createStateNotFoundError("Cached State");
11158
+ }
11159
+ authCodeResponse = this.authModule.handleFragmentResponse(locationHash, requestState);
11160
+ return [2 /*return*/, this.handleCodeResponseFromServer(authCodeResponse, state, authority, networkModule)];
11161
+ });
11162
+ });
11163
+ };
11164
+ /**
11165
+ * Process auth code response from AAD
11166
+ * @param authCodeResponse
11167
+ * @param state
11168
+ * @param authority
11169
+ * @param networkModule
11170
+ * @returns
11171
+ */
11172
+ InteractionHandler.prototype.handleCodeResponseFromServer = function (authCodeResponse, state, authority, networkModule, validateNonce) {
11173
+ if (validateNonce === void 0) { validateNonce = true; }
11174
+ return __awaiter$1(this, void 0, void 0, function () {
11175
+ var stateKey, requestState, nonceKey, cachedNonce, cachedCcsCred, tokenResponse;
10462
11176
  return __generator$1(this, function (_a) {
10463
11177
  switch (_a.label) {
10464
11178
  case 0:
10465
- this.browserRequestLogger.verbose("InteractionHandler.handleCodeResponse called");
10466
- // Check that location hash isn't empty.
10467
- if (StringUtils.isEmpty(locationHash)) {
10468
- throw BrowserAuthError.createEmptyHashError(locationHash);
10469
- }
11179
+ this.browserRequestLogger.trace("InteractionHandler.handleCodeResponseFromServer called");
10470
11180
  stateKey = this.browserStorage.generateStateKey(state);
10471
11181
  requestState = this.browserStorage.getTemporaryCache(stateKey);
10472
11182
  if (!requestState) {
10473
11183
  throw ClientAuthError.createStateNotFoundError("Cached State");
10474
11184
  }
10475
- authCodeResponse = this.authModule.handleFragmentResponse(locationHash, requestState);
10476
11185
  nonceKey = this.browserStorage.generateNonceKey(requestState);
10477
11186
  cachedNonce = this.browserStorage.getTemporaryCache(nonceKey);
10478
11187
  // Assign code to request
@@ -10483,7 +11192,10 @@
10483
11192
  _a.sent();
10484
11193
  _a.label = 2;
10485
11194
  case 2:
10486
- authCodeResponse.nonce = cachedNonce || undefined;
11195
+ // Nonce validation not needed when redirect not involved (e.g. hybrid spa, renewing token via rt)
11196
+ if (validateNonce) {
11197
+ authCodeResponse.nonce = cachedNonce || undefined;
11198
+ }
10487
11199
  authCodeResponse.state = requestState;
10488
11200
  // Add CCS parameters if available
10489
11201
  if (authCodeResponse.client_info) {
@@ -10620,26 +11332,36 @@
10620
11332
  * @param request
10621
11333
  */
10622
11334
  PopupClient.prototype.acquireToken = function (request) {
10623
- try {
10624
- var validRequest = this.preflightInteractiveRequest(request, exports.InteractionType.Popup);
10625
- var popupName = PopupUtils.generatePopupName(this.config.auth.clientId, validRequest);
10626
- var popupWindowAttributes = request.popupWindowAttributes || {};
10627
- // asyncPopups flag is true. Acquires token without first opening popup. Popup will be opened later asynchronously.
10628
- if (this.config.system.asyncPopups) {
10629
- this.logger.verbose("asyncPopups set to true, acquiring token");
10630
- // Passes on popup position and dimensions if in request
10631
- return this.acquireTokenPopupAsync(validRequest, popupName, popupWindowAttributes);
10632
- }
10633
- else {
10634
- // asyncPopups flag is set to false. Opens popup before acquiring token.
10635
- this.logger.verbose("asyncPopup set to false, opening popup before acquiring token");
10636
- var popup = PopupUtils.openSizedPopup("about:blank", popupName, popupWindowAttributes, this.logger);
10637
- return this.acquireTokenPopupAsync(validRequest, popupName, popupWindowAttributes, popup);
10638
- }
10639
- }
10640
- catch (e) {
10641
- return Promise.reject(e);
10642
- }
11335
+ return __awaiter$1(this, void 0, void 0, function () {
11336
+ var validRequest, popupName, popupWindowAttributes, popup, e_1;
11337
+ return __generator$1(this, function (_a) {
11338
+ switch (_a.label) {
11339
+ case 0:
11340
+ _a.trys.push([0, 2, , 3]);
11341
+ return [4 /*yield*/, this.preflightInteractiveRequest(request, exports.InteractionType.Popup)];
11342
+ case 1:
11343
+ validRequest = _a.sent();
11344
+ popupName = PopupUtils.generatePopupName(this.config.auth.clientId, validRequest);
11345
+ popupWindowAttributes = request.popupWindowAttributes || {};
11346
+ // asyncPopups flag is true. Acquires token without first opening popup. Popup will be opened later asynchronously.
11347
+ if (this.config.system.asyncPopups) {
11348
+ this.logger.verbose("asyncPopups set to true, acquiring token");
11349
+ // Passes on popup position and dimensions if in request
11350
+ return [2 /*return*/, this.acquireTokenPopupAsync(validRequest, popupName, popupWindowAttributes)];
11351
+ }
11352
+ else {
11353
+ // asyncPopups flag is set to false. Opens popup before acquiring token.
11354
+ this.logger.verbose("asyncPopup set to false, opening popup before acquiring token");
11355
+ popup = PopupUtils.openSizedPopup("about:blank", popupName, popupWindowAttributes, this.logger);
11356
+ return [2 /*return*/, this.acquireTokenPopupAsync(validRequest, popupName, popupWindowAttributes, popup)];
11357
+ }
11358
+ case 2:
11359
+ e_1 = _a.sent();
11360
+ return [2 /*return*/, Promise.reject(e_1)];
11361
+ case 3: return [2 /*return*/];
11362
+ }
11363
+ });
11364
+ });
10643
11365
  };
10644
11366
  /**
10645
11367
  * Clears local cache for the current user then opens a popup window prompting the user to sign-out of the server
@@ -10682,7 +11404,7 @@
10682
11404
  */
10683
11405
  PopupClient.prototype.acquireTokenPopupAsync = function (validRequest, popupName, popupWindowAttributes, popup) {
10684
11406
  return __awaiter$1(this, void 0, void 0, function () {
10685
- var serverTelemetryManager, authCodeRequest, authClient, navigateUrl, interactionHandler, popupParameters, popupWindow, hash, state, result, e_1;
11407
+ var serverTelemetryManager, authCodeRequest, authClient, navigateUrl, interactionHandler, popupParameters, popupWindow, hash, state, result, e_2;
10686
11408
  return __generator$1(this, function (_a) {
10687
11409
  switch (_a.label) {
10688
11410
  case 0:
@@ -10715,22 +11437,22 @@
10715
11437
  state = this.validateAndExtractStateFromHash(hash, exports.InteractionType.Popup, validRequest.correlationId);
10716
11438
  // Remove throttle if it exists
10717
11439
  ThrottlingUtils.removeThrottle(this.browserStorage, this.config.auth.clientId, authCodeRequest);
10718
- return [4 /*yield*/, interactionHandler.handleCodeResponse(hash, state, authClient.authority, this.networkClient)];
11440
+ return [4 /*yield*/, interactionHandler.handleCodeResponseFromHash(hash, state, authClient.authority, this.networkClient)];
10719
11441
  case 6:
10720
11442
  result = _a.sent();
10721
11443
  return [2 /*return*/, result];
10722
11444
  case 7:
10723
- e_1 = _a.sent();
11445
+ e_2 = _a.sent();
10724
11446
  if (popup) {
10725
11447
  // Close the synchronous popup if an error is thrown before the window unload event is registered
10726
11448
  popup.close();
10727
11449
  }
10728
- if (e_1 instanceof AuthError) {
10729
- e_1.setCorrelationId(this.correlationId);
11450
+ if (e_2 instanceof AuthError) {
11451
+ e_2.setCorrelationId(this.correlationId);
10730
11452
  }
10731
- serverTelemetryManager.cacheFailedRequest(e_1);
11453
+ serverTelemetryManager.cacheFailedRequest(e_2);
10732
11454
  this.browserStorage.cleanRequestByState(validRequest.state);
10733
- throw e_1;
11455
+ throw e_2;
10734
11456
  case 8: return [2 /*return*/];
10735
11457
  }
10736
11458
  });
@@ -10747,7 +11469,7 @@
10747
11469
  */
10748
11470
  PopupClient.prototype.logoutPopupAsync = function (validRequest, popupName, popupWindowAttributes, requestAuthority, popup, mainWindowRedirectUri) {
10749
11471
  return __awaiter$1(this, void 0, void 0, function () {
10750
- var serverTelemetryManager, authClient, logoutUri, popupUtils, popupWindow, e_2, navigationOptions, absoluteUrl, e_3;
11472
+ var serverTelemetryManager, authClient, logoutUri, popupUtils, popupWindow, e_3, navigationOptions, absoluteUrl, e_4;
10751
11473
  return __generator$1(this, function (_a) {
10752
11474
  switch (_a.label) {
10753
11475
  case 0:
@@ -10783,8 +11505,8 @@
10783
11505
  this.logger.verbose("Popup successfully redirected to postLogoutRedirectUri");
10784
11506
  return [3 /*break*/, 7];
10785
11507
  case 6:
10786
- e_2 = _a.sent();
10787
- this.logger.verbose("Error occurred while monitoring popup for same origin. Session on server may remain active. Error: " + e_2);
11508
+ e_3 = _a.sent();
11509
+ this.logger.verbose("Error occurred while monitoring popup for same origin. Session on server may remain active. Error: " + e_3);
10788
11510
  return [3 /*break*/, 7];
10789
11511
  case 7:
10790
11512
  popupUtils.cleanPopup(popupWindow);
@@ -10804,19 +11526,19 @@
10804
11526
  }
10805
11527
  return [3 /*break*/, 9];
10806
11528
  case 8:
10807
- e_3 = _a.sent();
11529
+ e_4 = _a.sent();
10808
11530
  if (popup) {
10809
11531
  // Close the synchronous popup if an error is thrown before the window unload event is registered
10810
11532
  popup.close();
10811
11533
  }
10812
- if (e_3 instanceof AuthError) {
10813
- e_3.setCorrelationId(this.correlationId);
11534
+ if (e_4 instanceof AuthError) {
11535
+ e_4.setCorrelationId(this.correlationId);
10814
11536
  }
10815
11537
  this.browserStorage.setInteractionInProgress(false);
10816
- this.eventHandler.emitEvent(exports.EventType.LOGOUT_FAILURE, exports.InteractionType.Popup, null, e_3);
11538
+ this.eventHandler.emitEvent(exports.EventType.LOGOUT_FAILURE, exports.InteractionType.Popup, null, e_4);
10817
11539
  this.eventHandler.emitEvent(exports.EventType.LOGOUT_END, exports.InteractionType.Popup);
10818
- serverTelemetryManager.cacheFailedRequest(e_3);
10819
- throw e_3;
11540
+ serverTelemetryManager.cacheFailedRequest(e_4);
11541
+ throw e_4;
10820
11542
  case 9:
10821
11543
  this.eventHandler.emitEvent(exports.EventType.LOGOUT_END, exports.InteractionType.Popup);
10822
11544
  return [2 /*return*/];
@@ -10899,7 +11621,7 @@
10899
11621
  * Handle authorization code response in the window.
10900
11622
  * @param hash
10901
11623
  */
10902
- RedirectHandler.prototype.handleCodeResponse = function (locationHash, state, authority, networkModule, clientId) {
11624
+ RedirectHandler.prototype.handleCodeResponseFromHash = function (locationHash, state, authority, networkModule, clientId) {
10903
11625
  return __awaiter$1(this, void 0, void 0, function () {
10904
11626
  var stateKey, requestState, authCodeResponse, nonceKey, cachedNonce, cachedCcsCred, tokenResponse;
10905
11627
  return __generator$1(this, function (_a) {
@@ -10974,22 +11696,23 @@
10974
11696
  var validRequest, serverTelemetryManager, authCodeRequest, authClient, interactionHandler, navigateUrl, redirectStartPage, e_1;
10975
11697
  return __generator$1(this, function (_a) {
10976
11698
  switch (_a.label) {
10977
- case 0:
10978
- validRequest = this.preflightInteractiveRequest(request, exports.InteractionType.Redirect);
10979
- serverTelemetryManager = this.initializeServerTelemetryManager(exports.ApiId.acquireTokenRedirect);
10980
- _a.label = 1;
11699
+ case 0: return [4 /*yield*/, this.preflightInteractiveRequest(request, exports.InteractionType.Redirect)];
10981
11700
  case 1:
10982
- _a.trys.push([1, 6, , 7]);
10983
- return [4 /*yield*/, this.initializeAuthorizationCodeRequest(validRequest)];
11701
+ validRequest = _a.sent();
11702
+ serverTelemetryManager = this.initializeServerTelemetryManager(exports.ApiId.acquireTokenRedirect);
11703
+ _a.label = 2;
10984
11704
  case 2:
11705
+ _a.trys.push([2, 7, , 8]);
11706
+ return [4 /*yield*/, this.initializeAuthorizationCodeRequest(validRequest)];
11707
+ case 3:
10985
11708
  authCodeRequest = _a.sent();
10986
11709
  return [4 /*yield*/, this.createAuthCodeClient(serverTelemetryManager, validRequest.authority)];
10987
- case 3:
11710
+ case 4:
10988
11711
  authClient = _a.sent();
10989
11712
  this.logger.verbose("Auth code client created");
10990
11713
  interactionHandler = new RedirectHandler(authClient, this.browserStorage, authCodeRequest, this.logger, this.browserCrypto);
10991
11714
  return [4 /*yield*/, authClient.getAuthCodeUrl(validRequest)];
10992
- case 4:
11715
+ case 5:
10993
11716
  navigateUrl = _a.sent();
10994
11717
  redirectStartPage = this.getRedirectStartPage(request.redirectStartPage);
10995
11718
  this.logger.verbosePii("Redirect start page: " + redirectStartPage);
@@ -10999,10 +11722,10 @@
10999
11722
  redirectStartPage: redirectStartPage,
11000
11723
  onRedirectNavigate: request.onRedirectNavigate
11001
11724
  })];
11002
- case 5:
11725
+ case 6:
11003
11726
  // Show the UI once the url has been created. Response will come back in the hash, which will be handled in the handleRedirectCallback function.
11004
11727
  return [2 /*return*/, _a.sent()];
11005
- case 6:
11728
+ case 7:
11006
11729
  e_1 = _a.sent();
11007
11730
  if (e_1 instanceof AuthError) {
11008
11731
  e_1.setCorrelationId(this.correlationId);
@@ -11010,7 +11733,7 @@
11010
11733
  serverTelemetryManager.cacheFailedRequest(e_1);
11011
11734
  this.browserStorage.cleanRequestByState(validRequest.state);
11012
11735
  throw e_1;
11013
- case 7: return [2 /*return*/];
11736
+ case 8: return [2 /*return*/];
11014
11737
  }
11015
11738
  });
11016
11739
  });
@@ -11072,7 +11795,7 @@
11072
11795
  this.logger.verbose("NavigateToLoginRequestUrl set to false, handling hash");
11073
11796
  return [2 /*return*/, this.handleHash(responseHash, state, serverTelemetryManager)];
11074
11797
  case 4:
11075
- if (!!BrowserUtils.isInIframe()) return [3 /*break*/, 9];
11798
+ if (!(!BrowserUtils.isInIframe() || this.config.system.allowRedirectInIframe)) return [3 /*break*/, 9];
11076
11799
  /*
11077
11800
  * Returned from authority using redirect - need to perform navigation before processing response
11078
11801
  * Cache the hash to be retrieved after the next redirect
@@ -11160,7 +11883,7 @@
11160
11883
  authClient = _a.sent();
11161
11884
  this.logger.verbose("Auth code client created");
11162
11885
  interactionHandler = new RedirectHandler(authClient, this.browserStorage, cachedRequest, this.logger, this.browserCrypto);
11163
- return [4 /*yield*/, interactionHandler.handleCodeResponse(hash, state, authClient.authority, this.networkClient, this.config.auth.clientId)];
11886
+ return [4 /*yield*/, interactionHandler.handleCodeResponseFromHash(hash, state, authClient.authority, this.networkClient, this.config.auth.clientId)];
11164
11887
  case 2: return [2 /*return*/, _a.sent()];
11165
11888
  }
11166
11889
  });
@@ -11420,30 +12143,32 @@
11420
12143
  this.logger.verbose("acquireTokenByIframe called");
11421
12144
  // Check that we have some SSO data
11422
12145
  if (StringUtils.isEmpty(request.loginHint) && StringUtils.isEmpty(request.sid) && (!request.account || StringUtils.isEmpty(request.account.username))) {
11423
- throw BrowserAuthError.createSilentSSOInsufficientInfoError();
12146
+ this.logger.warning("No user hint provided. The authorization server may need more information to complete this request.");
11424
12147
  }
11425
12148
  // Check that prompt is set to none, throw error if it is set to anything else.
11426
12149
  if (request.prompt && request.prompt !== PromptValue.NONE) {
11427
12150
  throw BrowserAuthError.createSilentPromptValueError(request.prompt);
11428
12151
  }
11429
- silentRequest = this.initializeAuthorizationRequest(__assign$1(__assign$1({}, request), { prompt: PromptValue.NONE }), exports.InteractionType.Silent);
11430
- serverTelemetryManager = this.initializeServerTelemetryManager(this.apiId);
11431
- _a.label = 1;
12152
+ return [4 /*yield*/, this.initializeAuthorizationRequest(__assign$1(__assign$1({}, request), { prompt: PromptValue.NONE }), exports.InteractionType.Silent)];
11432
12153
  case 1:
11433
- _a.trys.push([1, 6, , 7]);
11434
- return [4 /*yield*/, this.initializeAuthorizationCodeRequest(silentRequest)];
12154
+ silentRequest = _a.sent();
12155
+ serverTelemetryManager = this.initializeServerTelemetryManager(this.apiId);
12156
+ _a.label = 2;
11435
12157
  case 2:
12158
+ _a.trys.push([2, 7, , 8]);
12159
+ return [4 /*yield*/, this.initializeAuthorizationCodeRequest(silentRequest)];
12160
+ case 3:
11436
12161
  authCodeRequest = _a.sent();
11437
12162
  return [4 /*yield*/, this.createAuthCodeClient(serverTelemetryManager, silentRequest.authority)];
11438
- case 3:
12163
+ case 4:
11439
12164
  authClient = _a.sent();
11440
12165
  this.logger.verbose("Auth code client created");
11441
12166
  return [4 /*yield*/, authClient.getAuthCodeUrl(silentRequest)];
11442
- case 4:
12167
+ case 5:
11443
12168
  navigateUrl = _a.sent();
11444
12169
  return [4 /*yield*/, this.silentTokenHelper(navigateUrl, authCodeRequest, authClient, this.logger)];
11445
- case 5: return [2 /*return*/, _a.sent()];
11446
- case 6:
12170
+ case 6: return [2 /*return*/, _a.sent()];
12171
+ case 7:
11447
12172
  e_1 = _a.sent();
11448
12173
  if (e_1 instanceof AuthError) {
11449
12174
  e_1.setCorrelationId(this.correlationId);
@@ -11451,7 +12176,7 @@
11451
12176
  serverTelemetryManager.cacheFailedRequest(e_1);
11452
12177
  this.browserStorage.cleanRequestByState(silentRequest.state);
11453
12178
  throw e_1;
11454
- case 7: return [2 /*return*/];
12179
+ case 8: return [2 /*return*/];
11455
12180
  }
11456
12181
  });
11457
12182
  });
@@ -11484,7 +12209,7 @@
11484
12209
  hash = _a.sent();
11485
12210
  state = this.validateAndExtractStateFromHash(hash, exports.InteractionType.Silent, authCodeRequest.correlationId);
11486
12211
  // Handle response from hash string
11487
- return [2 /*return*/, silentHandler.handleCodeResponse(hash, state, authClient.authority, this.networkClient)];
12212
+ return [2 /*return*/, silentHandler.handleCodeResponseFromHash(hash, state, authClient.authority, this.networkClient)];
11488
12213
  }
11489
12214
  });
11490
12215
  });
@@ -11507,16 +12232,19 @@
11507
12232
  */
11508
12233
  SilentRefreshClient.prototype.acquireToken = function (request) {
11509
12234
  return __awaiter$1(this, void 0, void 0, function () {
11510
- var silentRequest, serverTelemetryManager, refreshTokenClient;
12235
+ var silentRequest, _a, serverTelemetryManager, refreshTokenClient;
11511
12236
  var _this = this;
11512
- return __generator$1(this, function (_a) {
11513
- switch (_a.label) {
12237
+ return __generator$1(this, function (_b) {
12238
+ switch (_b.label) {
11514
12239
  case 0:
11515
- silentRequest = __assign$1(__assign$1({}, request), this.initializeBaseRequest(request));
12240
+ _a = [__assign$1({}, request)];
12241
+ return [4 /*yield*/, this.initializeBaseRequest(request)];
12242
+ case 1:
12243
+ silentRequest = __assign$1.apply(void 0, _a.concat([_b.sent()]));
11516
12244
  serverTelemetryManager = this.initializeServerTelemetryManager(exports.ApiId.acquireTokenSilent_silentFlow);
11517
12245
  return [4 /*yield*/, this.createRefreshTokenClient(serverTelemetryManager, silentRequest.authority)];
11518
- case 1:
11519
- refreshTokenClient = _a.sent();
12246
+ case 2:
12247
+ refreshTokenClient = _b.sent();
11520
12248
  this.logger.verbose("Refresh token client created");
11521
12249
  // Send request to renew token. Auth module will throw errors if token cannot be renewed.
11522
12250
  return [2 /*return*/, refreshTokenClient.acquireTokenByRefreshToken(silentRequest).catch(function (e) {
@@ -11675,6 +12403,90 @@
11675
12403
  return TokenCache;
11676
12404
  }());
11677
12405
 
12406
+ /*
12407
+ * Copyright (c) Microsoft Corporation. All rights reserved.
12408
+ * Licensed under the MIT License.
12409
+ */
12410
+ var HybridSpaAuthorizationCodeClient = /** @class */ (function (_super) {
12411
+ __extends$1(HybridSpaAuthorizationCodeClient, _super);
12412
+ function HybridSpaAuthorizationCodeClient(config) {
12413
+ var _this = _super.call(this, config) || this;
12414
+ _this.includeRedirectUri = false;
12415
+ return _this;
12416
+ }
12417
+ return HybridSpaAuthorizationCodeClient;
12418
+ }(AuthorizationCodeClient));
12419
+
12420
+ /*
12421
+ * Copyright (c) Microsoft Corporation. All rights reserved.
12422
+ * Licensed under the MIT License.
12423
+ */
12424
+ var SilentAuthCodeClient = /** @class */ (function (_super) {
12425
+ __extends$1(SilentAuthCodeClient, _super);
12426
+ function SilentAuthCodeClient(config, storageImpl, browserCrypto, logger, eventHandler, navigationClient, apiId, correlationId) {
12427
+ var _this = _super.call(this, config, storageImpl, browserCrypto, logger, eventHandler, navigationClient, correlationId) || this;
12428
+ _this.apiId = apiId;
12429
+ return _this;
12430
+ }
12431
+ /**
12432
+ * Acquires a token silently by redeeming an authorization code against the /token endpoint
12433
+ * @param request
12434
+ */
12435
+ SilentAuthCodeClient.prototype.acquireToken = function (request) {
12436
+ return __awaiter$1(this, void 0, void 0, function () {
12437
+ var silentRequest, serverTelemetryManager, authCodeRequest, clientConfig, authClient, silentHandler, e_1;
12438
+ return __generator$1(this, function (_a) {
12439
+ switch (_a.label) {
12440
+ case 0:
12441
+ this.logger.trace("SilentAuthCodeClient.acquireToken called");
12442
+ // Auth code payload is required
12443
+ if (!request.code) {
12444
+ throw BrowserAuthError.createAuthCodeRequiredError();
12445
+ }
12446
+ return [4 /*yield*/, this.initializeAuthorizationRequest(request, exports.InteractionType.Silent)];
12447
+ case 1:
12448
+ silentRequest = _a.sent();
12449
+ serverTelemetryManager = this.initializeServerTelemetryManager(this.apiId);
12450
+ _a.label = 2;
12451
+ case 2:
12452
+ _a.trys.push([2, 4, , 5]);
12453
+ authCodeRequest = __assign$1(__assign$1({}, silentRequest), { code: request.code });
12454
+ return [4 /*yield*/, this.getClientConfiguration(serverTelemetryManager, silentRequest.authority)];
12455
+ case 3:
12456
+ clientConfig = _a.sent();
12457
+ authClient = new HybridSpaAuthorizationCodeClient(clientConfig);
12458
+ this.logger.verbose("Auth code client created");
12459
+ silentHandler = new SilentHandler(authClient, this.browserStorage, authCodeRequest, this.logger, this.config.system.navigateFrameWait);
12460
+ // Handle auth code parameters from request
12461
+ return [2 /*return*/, silentHandler.handleCodeResponseFromServer({
12462
+ code: request.code,
12463
+ msgraph_host: request.msGraphHost,
12464
+ cloud_graph_host_name: request.cloudGraphHostName,
12465
+ cloud_instance_host_name: request.cloudInstanceHostName
12466
+ }, silentRequest.state, authClient.authority, this.networkClient, false)];
12467
+ case 4:
12468
+ e_1 = _a.sent();
12469
+ if (e_1 instanceof AuthError) {
12470
+ e_1.setCorrelationId(this.correlationId);
12471
+ }
12472
+ serverTelemetryManager.cacheFailedRequest(e_1);
12473
+ this.browserStorage.cleanRequestByState(silentRequest.state);
12474
+ throw e_1;
12475
+ case 5: return [2 /*return*/];
12476
+ }
12477
+ });
12478
+ });
12479
+ };
12480
+ /**
12481
+ * Currently Unsupported
12482
+ */
12483
+ SilentAuthCodeClient.prototype.logout = function () {
12484
+ // Synchronous so we must reject
12485
+ return Promise.reject(BrowserAuthError.createSilentLogoutUnsupportedError());
12486
+ };
12487
+ return SilentAuthCodeClient;
12488
+ }(StandardInteractionClient));
12489
+
11678
12490
  /*
11679
12491
  * Copyright (c) Microsoft Corporation. All rights reserved.
11680
12492
  * Licensed under the MIT License.
@@ -11718,8 +12530,10 @@
11718
12530
  this.navigationClient = this.config.system.navigationClient;
11719
12531
  // Initialize redirectResponse Map
11720
12532
  this.redirectResponse = new Map();
12533
+ // Initial hybrid spa map
12534
+ this.hybridAuthCodeResponses = new Map();
11721
12535
  // Initialize the crypto class.
11722
- this.browserCrypto = this.isBrowserEnvironment ? new CryptoOps() : DEFAULT_CRYPTO_IMPLEMENTATION;
12536
+ this.browserCrypto = this.isBrowserEnvironment ? new CryptoOps(this.logger) : DEFAULT_CRYPTO_IMPLEMENTATION;
11723
12537
  this.eventHandler = new EventHandler(this.logger, this.browserCrypto);
11724
12538
  // Initialize the browser storage class.
11725
12539
  this.browserStorage = this.isBrowserEnvironment ?
@@ -11922,6 +12736,77 @@
11922
12736
  });
11923
12737
  });
11924
12738
  };
12739
+ /**
12740
+ * This function redeems an authorization code (passed as code) from the eSTS token endpoint.
12741
+ * This authorization code should be acquired server-side using a confidential client to acquire a spa_code.
12742
+ * This API is not indended for normal authorization code acquisition and redemption.
12743
+ *
12744
+ * Redemption of this authorization code will not require PKCE, as it was acquired by a confidential client.
12745
+ *
12746
+ * @param request {@link AuthorizationCodeRequest}
12747
+ * @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
12748
+ */
12749
+ ClientApplication.prototype.acquireTokenByCode = function (request) {
12750
+ return __awaiter$1(this, void 0, void 0, function () {
12751
+ var response;
12752
+ var _this = this;
12753
+ return __generator$1(this, function (_a) {
12754
+ this.preflightBrowserEnvironmentCheck(exports.InteractionType.Silent);
12755
+ this.logger.trace("acquireTokenByCode called", request.correlationId);
12756
+ this.eventHandler.emitEvent(exports.EventType.ACQUIRE_TOKEN_BY_CODE_START, exports.InteractionType.Silent, request);
12757
+ try {
12758
+ if (!request.code) {
12759
+ throw BrowserAuthError.createAuthCodeRequiredError();
12760
+ }
12761
+ response = this.hybridAuthCodeResponses.get(request.code);
12762
+ if (!response) {
12763
+ this.logger.verbose("Initiating new acquireTokenByCode request", request.correlationId);
12764
+ response = this.acquireTokenByCodeAsync(request)
12765
+ .then(function (result) {
12766
+ _this.eventHandler.emitEvent(exports.EventType.ACQUIRE_TOKEN_BY_CODE_SUCCESS, exports.InteractionType.Silent, result);
12767
+ _this.hybridAuthCodeResponses.delete(request.code);
12768
+ return result;
12769
+ })
12770
+ .catch(function (error) {
12771
+ _this.hybridAuthCodeResponses.delete(request.code);
12772
+ throw error;
12773
+ });
12774
+ this.hybridAuthCodeResponses.set(request.code, response);
12775
+ }
12776
+ else {
12777
+ this.logger.verbose("Existing acquireTokenByCode request found", request.correlationId);
12778
+ }
12779
+ return [2 /*return*/, response];
12780
+ }
12781
+ catch (e) {
12782
+ this.eventHandler.emitEvent(exports.EventType.ACQUIRE_TOKEN_BY_CODE_FAILURE, exports.InteractionType.Silent, null, e);
12783
+ throw e;
12784
+ }
12785
+ return [2 /*return*/];
12786
+ });
12787
+ });
12788
+ };
12789
+ /**
12790
+ * Creates a SilentAuthCodeClient to redeem an authorization code.
12791
+ * @param request
12792
+ * @returns Result of the operation to redeem the authorization code
12793
+ */
12794
+ ClientApplication.prototype.acquireTokenByCodeAsync = function (request) {
12795
+ return __awaiter$1(this, void 0, void 0, function () {
12796
+ var silentAuthCodeClient, silentTokenResult;
12797
+ return __generator$1(this, function (_a) {
12798
+ switch (_a.label) {
12799
+ case 0:
12800
+ this.logger.trace("acquireTokenByCodeAsync called", request.correlationId);
12801
+ silentAuthCodeClient = new SilentAuthCodeClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, exports.ApiId.acquireTokenByCode, request.correlationId);
12802
+ return [4 /*yield*/, silentAuthCodeClient.acquireToken(request)];
12803
+ case 1:
12804
+ silentTokenResult = _a.sent();
12805
+ return [2 /*return*/, silentTokenResult];
12806
+ }
12807
+ });
12808
+ });
12809
+ };
11925
12810
  /**
11926
12811
  * Use this function to obtain a token before every call to the API / resource provider
11927
12812
  *
@@ -11948,7 +12833,7 @@
11948
12833
  var isInvalidGrantError = (e.errorCode === BrowserConstants.INVALID_GRANT_ERROR);
11949
12834
  if (isServerError && isInvalidGrantError && !isInteractionRequiredError) {
11950
12835
  _this.logger.verbose("Refresh token expired or invalid, attempting acquire token by iframe", request.correlationId);
11951
- var silentIframeClient = new SilentIframeClient(_this.config, _this.browserStorage, _this.browserCrypto, _this.logger, _this.eventHandler, _this.navigationClient, exports.ApiId.acquireTokenSilent_authCode);
12836
+ var silentIframeClient = new SilentIframeClient(_this.config, _this.browserStorage, _this.browserCrypto, _this.logger, _this.eventHandler, _this.navigationClient, exports.ApiId.acquireTokenSilent_authCode, request.correlationId);
11952
12837
  return silentIframeClient.acquireToken(request);
11953
12838
  }
11954
12839
  throw e;
@@ -12121,6 +13006,18 @@
12121
13006
  ClientApplication.prototype.removeEventCallback = function (callbackId) {
12122
13007
  this.eventHandler.removeEventCallback(callbackId);
12123
13008
  };
13009
+ /**
13010
+ * Adds event listener that emits an event when a user account is added or removed from localstorage in a different browser tab or window
13011
+ */
13012
+ ClientApplication.prototype.enableAccountStorageEvents = function () {
13013
+ this.eventHandler.enableAccountStorageEvents();
13014
+ };
13015
+ /**
13016
+ * Removes event listener that emits an event when a user account is added or removed from localstorage in a different browser tab or window
13017
+ */
13018
+ ClientApplication.prototype.disableAccountStorageEvents = function () {
13019
+ this.eventHandler.disableAccountStorageEvents();
13020
+ };
12124
13021
  /**
12125
13022
  * Gets the token cache for the application.
12126
13023
  */
@@ -12156,6 +13053,12 @@
12156
13053
  ClientApplication.prototype.setNavigationClient = function (navigationClient) {
12157
13054
  this.navigationClient = navigationClient;
12158
13055
  };
13056
+ /**
13057
+ * Returns the configuration object
13058
+ */
13059
+ ClientApplication.prototype.getConfiguration = function () {
13060
+ return this.config;
13061
+ };
12159
13062
  return ClientApplication;
12160
13063
  }());
12161
13064
 
@@ -12228,7 +13131,17 @@
12228
13131
  });
12229
13132
  };
12230
13133
  SilentCacheClient.prototype.initializeSilentRequest = function (request, account) {
12231
- return __assign$1(__assign$1(__assign$1({}, request), this.initializeBaseRequest(request)), { account: account, forceRefresh: request.forceRefresh || false });
13134
+ return __awaiter$1(this, void 0, void 0, function () {
13135
+ var _a;
13136
+ return __generator$1(this, function (_b) {
13137
+ switch (_b.label) {
13138
+ case 0:
13139
+ _a = [__assign$1({}, request)];
13140
+ return [4 /*yield*/, this.initializeBaseRequest(request)];
13141
+ case 1: return [2 /*return*/, __assign$1.apply(void 0, [__assign$1.apply(void 0, _a.concat([_b.sent()])), { account: account, forceRefresh: request.forceRefresh || false }])];
13142
+ }
13143
+ });
13144
+ });
12232
13145
  };
12233
13146
  return SilentCacheClient;
12234
13147
  }(StandardInteractionClient));
@@ -12319,10 +13232,12 @@
12319
13232
  authority: request.authority || "",
12320
13233
  scopes: request.scopes,
12321
13234
  homeAccountIdentifier: account.homeAccountId,
13235
+ claims: request.claims,
12322
13236
  authenticationScheme: request.authenticationScheme,
12323
13237
  resourceRequestMethod: request.resourceRequestMethod,
12324
13238
  resourceRequestUri: request.resourceRequestUri,
12325
- shrClaims: request.shrClaims
13239
+ shrClaims: request.shrClaims,
13240
+ sshKid: request.sshKid
12326
13241
  };
12327
13242
  silentRequestKey = JSON.stringify(thumbprint);
12328
13243
  cachedResponse = this.activeSilentTokenRequests.get(silentRequestKey);
@@ -12358,28 +13273,33 @@
12358
13273
  var silentCacheClient, silentRequest;
12359
13274
  var _this = this;
12360
13275
  return __generator$1(this, function (_a) {
12361
- silentCacheClient = new SilentCacheClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient);
12362
- silentRequest = silentCacheClient.initializeSilentRequest(request, account);
12363
- this.eventHandler.emitEvent(exports.EventType.ACQUIRE_TOKEN_START, exports.InteractionType.Silent, request);
12364
- return [2 /*return*/, silentCacheClient.acquireToken(silentRequest).catch(function () { return __awaiter$1(_this, void 0, void 0, function () {
12365
- var tokenRenewalResult, tokenRenewalError_1;
12366
- return __generator$1(this, function (_a) {
12367
- switch (_a.label) {
12368
- case 0:
12369
- _a.trys.push([0, 2, , 3]);
12370
- return [4 /*yield*/, this.acquireTokenByRefreshToken(silentRequest)];
12371
- case 1:
12372
- tokenRenewalResult = _a.sent();
12373
- this.eventHandler.emitEvent(exports.EventType.ACQUIRE_TOKEN_SUCCESS, exports.InteractionType.Silent, tokenRenewalResult);
12374
- return [2 /*return*/, tokenRenewalResult];
12375
- case 2:
12376
- tokenRenewalError_1 = _a.sent();
12377
- this.eventHandler.emitEvent(exports.EventType.ACQUIRE_TOKEN_FAILURE, exports.InteractionType.Silent, null, tokenRenewalError_1);
12378
- throw tokenRenewalError_1;
12379
- case 3: return [2 /*return*/];
12380
- }
12381
- });
12382
- }); })];
13276
+ switch (_a.label) {
13277
+ case 0:
13278
+ silentCacheClient = new SilentCacheClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, request.correlationId);
13279
+ return [4 /*yield*/, silentCacheClient.initializeSilentRequest(request, account)];
13280
+ case 1:
13281
+ silentRequest = _a.sent();
13282
+ this.eventHandler.emitEvent(exports.EventType.ACQUIRE_TOKEN_START, exports.InteractionType.Silent, request);
13283
+ return [2 /*return*/, silentCacheClient.acquireToken(silentRequest).catch(function () { return __awaiter$1(_this, void 0, void 0, function () {
13284
+ var tokenRenewalResult, tokenRenewalError_1;
13285
+ return __generator$1(this, function (_a) {
13286
+ switch (_a.label) {
13287
+ case 0:
13288
+ _a.trys.push([0, 2, , 3]);
13289
+ return [4 /*yield*/, this.acquireTokenByRefreshToken(silentRequest)];
13290
+ case 1:
13291
+ tokenRenewalResult = _a.sent();
13292
+ this.eventHandler.emitEvent(exports.EventType.ACQUIRE_TOKEN_SUCCESS, exports.InteractionType.Silent, tokenRenewalResult);
13293
+ return [2 /*return*/, tokenRenewalResult];
13294
+ case 2:
13295
+ tokenRenewalError_1 = _a.sent();
13296
+ this.eventHandler.emitEvent(exports.EventType.ACQUIRE_TOKEN_FAILURE, exports.InteractionType.Silent, null, tokenRenewalError_1);
13297
+ throw tokenRenewalError_1;
13298
+ case 3: return [2 /*return*/];
13299
+ }
13300
+ });
13301
+ }); })];
13302
+ }
12383
13303
  });
12384
13304
  });
12385
13305
  };
@@ -12400,6 +13320,9 @@
12400
13320
  acquireTokenSilent: function () {
12401
13321
  return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());
12402
13322
  },
13323
+ acquireTokenByCode: function () {
13324
+ return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());
13325
+ },
12403
13326
  getAllAccounts: function () {
12404
13327
  return [];
12405
13328
  },
@@ -12439,6 +13362,12 @@
12439
13362
  removeEventCallback: function () {
12440
13363
  return;
12441
13364
  },
13365
+ enableAccountStorageEvents: function () {
13366
+ return;
13367
+ },
13368
+ disableAccountStorageEvents: function () {
13369
+ return;
13370
+ },
12442
13371
  getTokenCache: function () {
12443
13372
  throw BrowserConfigurationAuthError.createStubPcaInstanceCalledError();
12444
13373
  },
@@ -12459,6 +13388,9 @@
12459
13388
  },
12460
13389
  setNavigationClient: function () {
12461
13390
  return;
13391
+ },
13392
+ getConfiguration: function () {
13393
+ throw BrowserConfigurationAuthError.createStubPcaInstanceCalledError();
12462
13394
  }
12463
13395
  };
12464
13396
 
@@ -12531,8 +13463,10 @@
12531
13463
  * Licensed under the MIT License.
12532
13464
  */
12533
13465
  var SignedHttpRequest = /** @class */ (function () {
12534
- function SignedHttpRequest(shrParameters) {
12535
- this.cryptoOps = new CryptoOps();
13466
+ function SignedHttpRequest(shrParameters, shrOptions) {
13467
+ var loggerOptions = (shrOptions && shrOptions.loggerOptions) || {};
13468
+ this.logger = new Logger(loggerOptions, name, version);
13469
+ this.cryptoOps = new CryptoOps(this.logger);
12536
13470
  this.popTokenGenerator = new PopTokenGenerator(this.cryptoOps);
12537
13471
  this.shrParameters = shrParameters;
12538
13472
  }
@@ -12575,7 +13509,10 @@
12575
13509
  SignedHttpRequest.prototype.removeKeys = function (publicKeyThumbprint) {
12576
13510
  return __awaiter$1(this, void 0, void 0, function () {
12577
13511
  return __generator$1(this, function (_a) {
12578
- return [2 /*return*/, this.cryptoOps.removeTokenBindingKey(publicKeyThumbprint)];
13512
+ switch (_a.label) {
13513
+ case 0: return [4 /*yield*/, this.cryptoOps.removeTokenBindingKey(publicKeyThumbprint)];
13514
+ case 1: return [2 /*return*/, _a.sent()];
13515
+ }
12579
13516
  });
12580
13517
  });
12581
13518
  };
@@ -12585,20 +13522,28 @@
12585
13522
  exports.AccountEntity = AccountEntity;
12586
13523
  exports.AuthError = AuthError;
12587
13524
  exports.AuthErrorMessage = AuthErrorMessage;
13525
+ exports.AuthenticationHeaderParser = AuthenticationHeaderParser;
12588
13526
  exports.BrowserAuthError = BrowserAuthError;
12589
13527
  exports.BrowserAuthErrorMessage = BrowserAuthErrorMessage;
12590
13528
  exports.BrowserConfigurationAuthError = BrowserConfigurationAuthError;
12591
13529
  exports.BrowserConfigurationAuthErrorMessage = BrowserConfigurationAuthErrorMessage;
12592
13530
  exports.BrowserUtils = BrowserUtils;
13531
+ exports.ClientAuthError = ClientAuthError;
13532
+ exports.ClientAuthErrorMessage = ClientAuthErrorMessage;
13533
+ exports.ClientConfigurationError = ClientConfigurationError;
13534
+ exports.ClientConfigurationErrorMessage = ClientConfigurationErrorMessage;
12593
13535
  exports.EventMessageUtils = EventMessageUtils;
12594
13536
  exports.InteractionRequiredAuthError = InteractionRequiredAuthError;
13537
+ exports.InteractionRequiredAuthErrorMessage = InteractionRequiredAuthErrorMessage;
12595
13538
  exports.Logger = Logger;
12596
13539
  exports.NavigationClient = NavigationClient;
12597
13540
  exports.PublicClientApplication = PublicClientApplication;
13541
+ exports.ServerError = ServerError;
12598
13542
  exports.SignedHttpRequest = SignedHttpRequest;
12599
13543
  exports.StringUtils = StringUtils;
12600
13544
  exports.UrlString = UrlString;
12601
13545
  exports.stubbedPublicClientApplication = stubbedPublicClientApplication;
13546
+ exports.version = version;
12602
13547
 
12603
13548
  Object.defineProperty(exports, '__esModule', { value: true });
12604
13549