@azure/msal-common 6.3.0-beta.0 → 7.0.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 (175) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +62 -62
  3. package/dist/_virtual/_tslib.js +1 -1
  4. package/dist/account/AuthToken.js +1 -1
  5. package/dist/account/AuthToken.js.map +1 -1
  6. package/dist/account/CcsCredential.js +1 -1
  7. package/dist/account/CcsCredential.js.map +1 -1
  8. package/dist/account/ClientCredentials.d.ts +15 -0
  9. package/dist/account/ClientCredentials.d.ts.map +1 -0
  10. package/dist/account/ClientInfo.js +1 -1
  11. package/dist/account/ClientInfo.js.map +1 -1
  12. package/dist/account/TokenClaims.d.ts +1 -1
  13. package/dist/account/TokenClaims.d.ts.map +1 -1
  14. package/dist/authority/Authority.js +1 -1
  15. package/dist/authority/Authority.js.map +1 -1
  16. package/dist/authority/AuthorityFactory.js +1 -1
  17. package/dist/authority/AuthorityFactory.js.map +1 -1
  18. package/dist/authority/AuthorityOptions.js +1 -1
  19. package/dist/authority/AuthorityOptions.js.map +1 -1
  20. package/dist/authority/AuthorityType.js +1 -1
  21. package/dist/authority/AuthorityType.js.map +1 -1
  22. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  23. package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -1
  24. package/dist/authority/OpenIdConfigResponse.js +1 -1
  25. package/dist/authority/OpenIdConfigResponse.js.map +1 -1
  26. package/dist/authority/ProtocolMode.js +1 -1
  27. package/dist/authority/ProtocolMode.js.map +1 -1
  28. package/dist/authority/RegionDiscovery.js +1 -1
  29. package/dist/authority/RegionDiscovery.js.map +1 -1
  30. package/dist/cache/CacheManager.d.ts +2 -2
  31. package/dist/cache/CacheManager.d.ts.map +1 -1
  32. package/dist/cache/CacheManager.js +9 -9
  33. package/dist/cache/CacheManager.js.map +1 -1
  34. package/dist/cache/entities/AccessTokenEntity.d.ts +1 -1
  35. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  36. package/dist/cache/entities/AccessTokenEntity.js +3 -3
  37. package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
  38. package/dist/cache/entities/AccountEntity.d.ts +2 -4
  39. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  40. package/dist/cache/entities/AccountEntity.js +3 -6
  41. package/dist/cache/entities/AccountEntity.js.map +1 -1
  42. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  43. package/dist/cache/entities/AppMetadataEntity.js.map +1 -1
  44. package/dist/cache/entities/AuthorityMetadataEntity.js +1 -1
  45. package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -1
  46. package/dist/cache/entities/CacheRecord.js +1 -1
  47. package/dist/cache/entities/CacheRecord.js.map +1 -1
  48. package/dist/cache/entities/CredentialEntity.d.ts +2 -2
  49. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  50. package/dist/cache/entities/CredentialEntity.js +2 -2
  51. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  52. package/dist/cache/entities/IdTokenEntity.d.ts +1 -1
  53. package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -1
  54. package/dist/cache/entities/IdTokenEntity.js +2 -3
  55. package/dist/cache/entities/IdTokenEntity.js.map +1 -1
  56. package/dist/cache/entities/RefreshTokenEntity.d.ts +1 -1
  57. package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
  58. package/dist/cache/entities/RefreshTokenEntity.js +3 -3
  59. package/dist/cache/entities/RefreshTokenEntity.js.map +1 -1
  60. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  61. package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -1
  62. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  63. package/dist/cache/entities/ThrottlingEntity.js.map +1 -1
  64. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  65. package/dist/cache/persistence/TokenCacheContext.js.map +1 -1
  66. package/dist/cache/utils/CacheTypes.d.ts +1 -1
  67. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  68. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  69. package/dist/client/AuthorizationCodeClient.js +12 -14
  70. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  71. package/dist/client/BaseClient.js +1 -1
  72. package/dist/client/BaseClient.js.map +1 -1
  73. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  74. package/dist/client/ClientCredentialClient.js +4 -3
  75. package/dist/client/ClientCredentialClient.js.map +1 -1
  76. package/dist/client/DeviceCodeClient.js +1 -1
  77. package/dist/client/DeviceCodeClient.js.map +1 -1
  78. package/dist/client/OnBehalfOfClient.d.ts +12 -9
  79. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  80. package/dist/client/OnBehalfOfClient.js +87 -59
  81. package/dist/client/OnBehalfOfClient.js.map +1 -1
  82. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  83. package/dist/client/RefreshTokenClient.js +5 -4
  84. package/dist/client/RefreshTokenClient.js.map +1 -1
  85. package/dist/client/SilentFlowClient.js +1 -1
  86. package/dist/client/SilentFlowClient.js.map +1 -1
  87. package/dist/client/UsernamePasswordClient.js +1 -1
  88. package/dist/client/UsernamePasswordClient.js.map +1 -1
  89. package/dist/config/ClientConfiguration.d.ts +1 -10
  90. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  91. package/dist/config/ClientConfiguration.js +1 -1
  92. package/dist/config/ClientConfiguration.js.map +1 -1
  93. package/dist/crypto/ICrypto.js +1 -1
  94. package/dist/crypto/ICrypto.js.map +1 -1
  95. package/dist/crypto/JoseHeader.d.ts +22 -0
  96. package/dist/crypto/JoseHeader.d.ts.map +1 -0
  97. package/dist/crypto/JoseHeader.js +45 -0
  98. package/dist/crypto/JoseHeader.js.map +1 -0
  99. package/dist/crypto/PopTokenGenerator.d.ts +9 -9
  100. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  101. package/dist/crypto/PopTokenGenerator.js +19 -31
  102. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  103. package/dist/error/AuthError.js +1 -1
  104. package/dist/error/AuthError.js.map +1 -1
  105. package/dist/error/ClientAuthError.d.ts +8 -0
  106. package/dist/error/ClientAuthError.d.ts.map +1 -1
  107. package/dist/error/ClientAuthError.js +11 -1
  108. package/dist/error/ClientAuthError.js.map +1 -1
  109. package/dist/error/ClientConfigurationError.js +1 -1
  110. package/dist/error/ClientConfigurationError.js.map +1 -1
  111. package/dist/error/InteractionRequiredAuthError.js +1 -1
  112. package/dist/error/InteractionRequiredAuthError.js.map +1 -1
  113. package/dist/error/JoseHeaderError.d.ts +29 -0
  114. package/dist/error/JoseHeaderError.d.ts.map +1 -0
  115. package/dist/error/JoseHeaderError.js +50 -0
  116. package/dist/error/JoseHeaderError.js.map +1 -0
  117. package/dist/error/ServerError.js +1 -1
  118. package/dist/error/ServerError.js.map +1 -1
  119. package/dist/index.cjs.js +267 -148
  120. package/dist/index.cjs.js.map +1 -1
  121. package/dist/index.d.ts +1 -0
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js +2 -1
  124. package/dist/index.js.map +1 -1
  125. package/dist/logger/Logger.js +1 -1
  126. package/dist/logger/Logger.js.map +1 -1
  127. package/dist/network/INetworkModule.js +1 -1
  128. package/dist/network/INetworkModule.js.map +1 -1
  129. package/dist/network/NetworkManager.js +1 -1
  130. package/dist/network/NetworkManager.js.map +1 -1
  131. package/dist/network/ThrottlingUtils.js +1 -1
  132. package/dist/network/ThrottlingUtils.js.map +1 -1
  133. package/dist/packageMetadata.d.ts +1 -1
  134. package/dist/packageMetadata.d.ts.map +1 -1
  135. package/dist/packageMetadata.js +2 -2
  136. package/dist/packageMetadata.js.map +1 -1
  137. package/dist/request/AuthenticationHeaderParser.js +1 -1
  138. package/dist/request/AuthenticationHeaderParser.js.map +1 -1
  139. package/dist/request/BaseAuthRequest.d.ts +2 -2
  140. package/dist/request/CommonClientCredentialRequest.d.ts +2 -0
  141. package/dist/request/CommonClientCredentialRequest.d.ts.map +1 -1
  142. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  143. package/dist/request/RequestParameterBuilder.js +9 -5
  144. package/dist/request/RequestParameterBuilder.js.map +1 -1
  145. package/dist/request/RequestValidator.js +1 -1
  146. package/dist/request/RequestValidator.js.map +1 -1
  147. package/dist/request/ScopeSet.js +1 -1
  148. package/dist/request/ScopeSet.js.map +1 -1
  149. package/dist/response/ResponseHandler.d.ts +1 -1
  150. package/dist/response/ResponseHandler.d.ts.map +1 -1
  151. package/dist/response/ResponseHandler.js +23 -19
  152. package/dist/response/ResponseHandler.js.map +1 -1
  153. package/dist/telemetry/performance/PerformanceClient.js +1 -1
  154. package/dist/telemetry/performance/PerformanceClient.js.map +1 -1
  155. package/dist/telemetry/performance/PerformanceEvent.d.ts +12 -0
  156. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  157. package/dist/telemetry/performance/PerformanceEvent.js +1 -1
  158. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -1
  159. package/dist/telemetry/performance/StubPerformanceClient.js +1 -1
  160. package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -1
  161. package/dist/telemetry/server/ServerTelemetryManager.js +1 -1
  162. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
  163. package/dist/url/UrlString.js +1 -1
  164. package/dist/url/UrlString.js.map +1 -1
  165. package/dist/utils/Constants.d.ts +4 -0
  166. package/dist/utils/Constants.d.ts.map +1 -1
  167. package/dist/utils/Constants.js +8 -3
  168. package/dist/utils/Constants.js.map +1 -1
  169. package/dist/utils/ProtocolUtils.js +1 -1
  170. package/dist/utils/ProtocolUtils.js.map +1 -1
  171. package/dist/utils/StringUtils.js +1 -1
  172. package/dist/utils/StringUtils.js.map +1 -1
  173. package/dist/utils/TimeUtils.js +1 -1
  174. package/dist/utils/TimeUtils.js.map +1 -1
  175. package/package.json +74 -74
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v6.3.0-beta.0 2022-04-27 */
1
+ /*! @azure/msal-common v7.0.0 2022-06-13 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -462,7 +462,12 @@ var CacheOutcome;
462
462
  CacheOutcome["NO_CACHED_ACCESS_TOKEN"] = "2";
463
463
  CacheOutcome["CACHED_ACCESS_TOKEN_EXPIRED"] = "3";
464
464
  CacheOutcome["REFRESH_CACHED_ACCESS_TOKEN"] = "4";
465
- })(CacheOutcome || (CacheOutcome = {}));
465
+ })(CacheOutcome || (CacheOutcome = {}));
466
+ var JsonTypes;
467
+ (function (JsonTypes) {
468
+ JsonTypes["Jwt"] = "JWT";
469
+ JsonTypes["Jwk"] = "JWK";
470
+ })(JsonTypes || (JsonTypes = {}));
466
471
 
467
472
  /*
468
473
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -767,6 +772,10 @@ var ClientAuthErrorMessage = {
767
772
  logoutNotSupported: {
768
773
  code: "end_session_endpoint_not_supported",
769
774
  desc: "Provided authority does not support logout."
775
+ },
776
+ keyIdMissing: {
777
+ code: "key_id_missing",
778
+ desc: "A keyId value is missing from the requested bound token's cache record and is required to match the token to it's stored binding key."
770
779
  }
771
780
  };
772
781
  /**
@@ -1036,6 +1045,12 @@ var ClientAuthError = /** @class */ (function (_super) {
1036
1045
  ClientAuthError.createLogoutNotSupportedError = function () {
1037
1046
  return new ClientAuthError(ClientAuthErrorMessage.logoutNotSupported.code, ClientAuthErrorMessage.logoutNotSupported.desc);
1038
1047
  };
1048
+ /**
1049
+ * Create an error when kid attribute is missing from a PoP token's cache record
1050
+ */
1051
+ ClientAuthError.createKeyIdMissingError = function () {
1052
+ return new ClientAuthError(ClientAuthErrorMessage.keyIdMissing.code, ClientAuthErrorMessage.keyIdMissing.desc);
1053
+ };
1039
1054
  return ClientAuthError;
1040
1055
  }(AuthError));
1041
1056
 
@@ -1342,7 +1357,7 @@ var Logger = /** @class */ (function () {
1342
1357
 
1343
1358
  /* eslint-disable header/header */
1344
1359
  var name = "@azure/msal-common";
1345
- var version = "6.3.0-beta.0";
1360
+ var version = "7.0.0";
1346
1361
 
1347
1362
  /*
1348
1363
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1385,9 +1400,9 @@ exports.AzureCloudInstance = void 0;
1385
1400
  * familyId: Family ID identifier, usually only used for refresh tokens
1386
1401
  * realm: Full tenant or organizational identifier that the account belongs to
1387
1402
  * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
1388
- * oboAssertion: access token passed in as part of OBO request
1389
1403
  * tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
1390
1404
  * requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request
1405
+ * userAssertionHash: Matches the SHA 256 hash of the obo_assertion for the OBO flow
1391
1406
  * }
1392
1407
  */
1393
1408
  var CredentialEntity = /** @class */ (function () {
@@ -2028,7 +2043,6 @@ exports.AuthorityType = void 0;
2028
2043
  * clientInfo: Full base64 encoded client info received from ESTS
2029
2044
  * lastModificationTime: last time this entity was modified in the cache
2030
2045
  * lastModificationApp:
2031
- * oboAssertion: access token passed in as part of OBO request
2032
2046
  * idTokenClaims: Object containing claims parsed from ID token
2033
2047
  * nativeAccountId: Account identifier on the native device
2034
2048
  * }
@@ -2107,7 +2121,7 @@ var AccountEntity = /** @class */ (function () {
2107
2121
  * @param idToken
2108
2122
  * @param policy
2109
2123
  */
2110
- AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment, nativeAccountId) {
2124
+ AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, cloudGraphHostName, msGraphHost, environment, nativeAccountId) {
2111
2125
  var _a, _b, _c, _d, _e, _f;
2112
2126
  var account = new AccountEntity();
2113
2127
  account.authorityType = exports.CacheAccountType.MSSTS_ACCOUNT_TYPE;
@@ -2121,7 +2135,6 @@ var AccountEntity = /** @class */ (function () {
2121
2135
  account.environment = env;
2122
2136
  // non AAD scenarios can have empty realm
2123
2137
  account.realm = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.tid) || Constants.EMPTY_STRING;
2124
- account.oboAssertion = oboAssertion;
2125
2138
  if (idToken) {
2126
2139
  account.idTokenClaims = idToken.claims;
2127
2140
  // How do you account for MSA CID here?
@@ -2142,14 +2155,13 @@ var AccountEntity = /** @class */ (function () {
2142
2155
  * @param authority
2143
2156
  * @param idToken
2144
2157
  */
2145
- AccountEntity.createGenericAccount = function (homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment) {
2158
+ AccountEntity.createGenericAccount = function (homeAccountId, idToken, authority, cloudGraphHostName, msGraphHost, environment) {
2146
2159
  var _a, _b, _c, _d;
2147
2160
  var account = new AccountEntity();
2148
2161
  account.authorityType = (authority && authority.authorityType === exports.AuthorityType.Adfs) ? exports.CacheAccountType.ADFS_ACCOUNT_TYPE : exports.CacheAccountType.GENERIC_ACCOUNT_TYPE;
2149
2162
  account.homeAccountId = homeAccountId;
2150
2163
  // non AAD scenarios can have empty realm
2151
2164
  account.realm = Constants.EMPTY_STRING;
2152
- account.oboAssertion = oboAssertion;
2153
2165
  var env = environment || authority && authority.getPreferredCache();
2154
2166
  if (!env) {
2155
2167
  throw ClientAuthError.createInvalidCacheEnvironmentError();
@@ -2438,7 +2450,7 @@ var CacheManager = /** @class */ (function () {
2438
2450
  * @param target
2439
2451
  */
2440
2452
  CacheManager.prototype.getCredentialsFilteredBy = function (filter) {
2441
- 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
+ return this.getCredentialsFilteredByInternal(filter.homeAccountId, filter.environment, filter.credentialType, filter.clientId, filter.familyId, filter.realm, filter.target, filter.userAssertionHash, filter.tokenType, filter.keyId, filter.requestedClaimsHash);
2442
2454
  };
2443
2455
  /**
2444
2456
  * Support function to help match credentials
@@ -2448,10 +2460,10 @@ var CacheManager = /** @class */ (function () {
2448
2460
  * @param clientId
2449
2461
  * @param realm
2450
2462
  * @param target
2451
- * @param oboAssertion
2463
+ * @param userAssertionHash
2452
2464
  * @param tokenType
2453
2465
  */
2454
- CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, oboAssertion, tokenType, keyId, requestedClaimsHash) {
2466
+ CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, userAssertionHash, tokenType, keyId, requestedClaimsHash) {
2455
2467
  var _this = this;
2456
2468
  var allCacheKeys = this.getKeys();
2457
2469
  var matchingCredentials = {
@@ -2470,7 +2482,7 @@ var CacheManager = /** @class */ (function () {
2470
2482
  if (!entity) {
2471
2483
  return;
2472
2484
  }
2473
- if (!!oboAssertion && !_this.matchOboAssertion(entity, oboAssertion)) {
2485
+ if (!!userAssertionHash && !_this.matchUserAssertionHash(entity, userAssertionHash)) {
2474
2486
  return;
2475
2487
  }
2476
2488
  if (!!homeAccountId && !_this.matchHomeAccountId(entity, homeAccountId)) {
@@ -2801,7 +2813,7 @@ var CacheManager = /** @class */ (function () {
2801
2813
  target: scopes.printScopesLowerCase(),
2802
2814
  tokenType: authScheme,
2803
2815
  keyId: request.sshKid,
2804
- requestedClaimsHash: request.requestedClaimsHash
2816
+ requestedClaimsHash: request.requestedClaimsHash,
2805
2817
  };
2806
2818
  var credentialCache = this.getCredentialsFilteredBy(accessTokenFilter);
2807
2819
  var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
@@ -2827,7 +2839,7 @@ var CacheManager = /** @class */ (function () {
2827
2839
  environment: account.environment,
2828
2840
  credentialType: exports.CredentialType.REFRESH_TOKEN,
2829
2841
  clientId: clientId,
2830
- familyId: id
2842
+ familyId: id,
2831
2843
  };
2832
2844
  var credentialCache = this.getCredentialsFilteredBy(refreshTokenFilter);
2833
2845
  var refreshTokens = Object.keys(credentialCache.refreshTokens).map(function (key) { return credentialCache.refreshTokens[key]; });
@@ -2879,8 +2891,8 @@ var CacheManager = /** @class */ (function () {
2879
2891
  * @param value
2880
2892
  * @param oboAssertion
2881
2893
  */
2882
- CacheManager.prototype.matchOboAssertion = function (entity, oboAssertion) {
2883
- return !!(entity.oboAssertion && oboAssertion === entity.oboAssertion);
2894
+ CacheManager.prototype.matchUserAssertionHash = function (entity, userAssertionHash) {
2895
+ return !!(entity.userAssertionHash && userAssertionHash === entity.userAssertionHash);
2884
2896
  };
2885
2897
  /**
2886
2898
  * helper to match environment
@@ -3781,14 +3793,18 @@ var RequestParameterBuilder = /** @class */ (function () {
3781
3793
  * @param clientAssertion
3782
3794
  */
3783
3795
  RequestParameterBuilder.prototype.addClientAssertion = function (clientAssertion) {
3784
- this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION, encodeURIComponent(clientAssertion));
3796
+ if (!StringUtils.isEmpty(clientAssertion)) {
3797
+ this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION, encodeURIComponent(clientAssertion));
3798
+ }
3785
3799
  };
3786
3800
  /**
3787
3801
  * add clientAssertionType for confidential client flows
3788
3802
  * @param clientAssertionType
3789
3803
  */
3790
3804
  RequestParameterBuilder.prototype.addClientAssertionType = function (clientAssertionType) {
3791
- this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION_TYPE, encodeURIComponent(clientAssertionType));
3805
+ if (!StringUtils.isEmpty(clientAssertionType)) {
3806
+ this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION_TYPE, encodeURIComponent(clientAssertionType));
3807
+ }
3792
3808
  };
3793
3809
  /**
3794
3810
  * add OBO assertion for confidential client flows
@@ -3860,14 +3876,14 @@ var RequestParameterBuilder = /** @class */ (function () {
3860
3876
  * @param username
3861
3877
  */
3862
3878
  RequestParameterBuilder.prototype.addUsername = function (username) {
3863
- this.parameters.set(PasswordGrantConstants.username, username);
3879
+ this.parameters.set(PasswordGrantConstants.username, encodeURIComponent(username));
3864
3880
  };
3865
3881
  /**
3866
3882
  * adds `password` for Password Grant flow
3867
3883
  * @param password
3868
3884
  */
3869
3885
  RequestParameterBuilder.prototype.addPassword = function (password) {
3870
- this.parameters.set(PasswordGrantConstants.password, password);
3886
+ this.parameters.set(PasswordGrantConstants.password, encodeURIComponent(password));
3871
3887
  };
3872
3888
  /**
3873
3889
  * add pop_jwk to query params
@@ -3954,7 +3970,7 @@ var IdTokenEntity = /** @class */ (function (_super) {
3954
3970
  * @param clientId
3955
3971
  * @param authority
3956
3972
  */
3957
- IdTokenEntity.createIdTokenEntity = function (homeAccountId, environment, idToken, clientId, tenantId, oboAssertion) {
3973
+ IdTokenEntity.createIdTokenEntity = function (homeAccountId, environment, idToken, clientId, tenantId) {
3958
3974
  var idTokenEntity = new IdTokenEntity();
3959
3975
  idTokenEntity.credentialType = exports.CredentialType.ID_TOKEN;
3960
3976
  idTokenEntity.homeAccountId = homeAccountId;
@@ -3962,7 +3978,6 @@ var IdTokenEntity = /** @class */ (function (_super) {
3962
3978
  idTokenEntity.clientId = clientId;
3963
3979
  idTokenEntity.secret = idToken;
3964
3980
  idTokenEntity.realm = tenantId;
3965
- idTokenEntity.oboAssertion = oboAssertion;
3966
3981
  return idTokenEntity;
3967
3982
  };
3968
3983
  /**
@@ -4077,7 +4092,7 @@ var AccessTokenEntity = /** @class */ (function (_super) {
4077
4092
  * @param expiresOn
4078
4093
  * @param extExpiresOn
4079
4094
  */
4080
- AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, oboAssertion, keyId, requestedClaims, requestedClaimsHash) {
4095
+ AccessTokenEntity.createAccessTokenEntity = function (homeAccountId, environment, accessToken, clientId, tenantId, scopes, expiresOn, extExpiresOn, cryptoUtils, refreshOn, tokenType, userAssertionHash, keyId, requestedClaims, requestedClaimsHash) {
4081
4096
  var _a, _b;
4082
4097
  var atEntity = new AccessTokenEntity();
4083
4098
  atEntity.homeAccountId = homeAccountId;
@@ -4098,7 +4113,7 @@ var AccessTokenEntity = /** @class */ (function (_super) {
4098
4113
  atEntity.clientId = clientId;
4099
4114
  atEntity.realm = tenantId;
4100
4115
  atEntity.target = scopes;
4101
- atEntity.oboAssertion = oboAssertion;
4116
+ atEntity.userAssertionHash = userAssertionHash;
4102
4117
  atEntity.tokenType = StringUtils.isEmpty(tokenType) ? exports.AuthenticationScheme.BEARER : tokenType;
4103
4118
  if (requestedClaims) {
4104
4119
  atEntity.requestedClaims = requestedClaims;
@@ -4180,14 +4195,14 @@ var RefreshTokenEntity = /** @class */ (function (_super) {
4180
4195
  * @param clientId
4181
4196
  * @param authority
4182
4197
  */
4183
- RefreshTokenEntity.createRefreshTokenEntity = function (homeAccountId, environment, refreshToken, clientId, familyId, oboAssertion) {
4198
+ RefreshTokenEntity.createRefreshTokenEntity = function (homeAccountId, environment, refreshToken, clientId, familyId, userAssertionHash) {
4184
4199
  var rtEntity = new RefreshTokenEntity();
4185
4200
  rtEntity.clientId = clientId;
4186
4201
  rtEntity.credentialType = exports.CredentialType.REFRESH_TOKEN;
4187
4202
  rtEntity.environment = environment;
4188
4203
  rtEntity.homeAccountId = homeAccountId;
4189
4204
  rtEntity.secret = refreshToken;
4190
- rtEntity.oboAssertion = oboAssertion;
4205
+ rtEntity.userAssertionHash = userAssertionHash;
4191
4206
  if (familyId)
4192
4207
  rtEntity.familyId = familyId;
4193
4208
  return rtEntity;
@@ -4570,34 +4585,30 @@ var PopTokenGenerator = /** @class */ (function () {
4570
4585
  }
4571
4586
  /**
4572
4587
  * Generates the req_cnf validated at the RP in the POP protocol for SHR parameters
4588
+ * and returns an object containing the keyid, the full req_cnf string and the req_cnf string hash
4573
4589
  * @param request
4574
4590
  * @returns
4575
4591
  */
4576
4592
  PopTokenGenerator.prototype.generateCnf = function (request) {
4577
4593
  return __awaiter(this, void 0, void 0, function () {
4578
- var reqCnf;
4579
- return __generator(this, function (_a) {
4580
- switch (_a.label) {
4594
+ var reqCnf, reqCnfString, _a;
4595
+ return __generator(this, function (_b) {
4596
+ switch (_b.label) {
4581
4597
  case 0: return [4 /*yield*/, this.generateKid(request)];
4582
4598
  case 1:
4583
- reqCnf = _a.sent();
4584
- return [2 /*return*/, this.cryptoUtils.base64Encode(JSON.stringify(reqCnf))];
4599
+ reqCnf = _b.sent();
4600
+ reqCnfString = this.cryptoUtils.base64Encode(JSON.stringify(reqCnf));
4601
+ _a = {
4602
+ kid: reqCnf.kid,
4603
+ reqCnfString: reqCnfString
4604
+ };
4605
+ return [4 /*yield*/, this.cryptoUtils.hashString(reqCnfString)];
4606
+ case 2: return [2 /*return*/, (_a.reqCnfHash = _b.sent(),
4607
+ _a)];
4585
4608
  }
4586
4609
  });
4587
4610
  });
4588
4611
  };
4589
- /**
4590
- * Generates the hash of the req_cnf
4591
- * @param cnf
4592
- * @returns
4593
- */
4594
- PopTokenGenerator.prototype.generateCnfHash = function (cnf) {
4595
- return __awaiter(this, void 0, void 0, function () {
4596
- return __generator(this, function (_a) {
4597
- return [2 /*return*/, this.cryptoUtils.hashString(cnf)];
4598
- });
4599
- });
4600
- };
4601
4612
  /**
4602
4613
  * Generates key_id for a SHR token request
4603
4614
  * @param request
@@ -4625,16 +4636,10 @@ var PopTokenGenerator = /** @class */ (function () {
4625
4636
  * @param request
4626
4637
  * @returns
4627
4638
  */
4628
- PopTokenGenerator.prototype.signPopToken = function (accessToken, request) {
4629
- var _a;
4639
+ PopTokenGenerator.prototype.signPopToken = function (accessToken, keyId, request) {
4630
4640
  return __awaiter(this, void 0, void 0, function () {
4631
- var tokenClaims;
4632
- return __generator(this, function (_b) {
4633
- tokenClaims = AuthToken.extractTokenClaims(accessToken, this.cryptoUtils);
4634
- if (!((_a = tokenClaims === null || tokenClaims === void 0 ? void 0 : tokenClaims.cnf) === null || _a === void 0 ? void 0 : _a.kid)) {
4635
- throw ClientAuthError.createTokenClaimsRequiredError();
4636
- }
4637
- return [2 /*return*/, this.signPayload(accessToken, tokenClaims.cnf.kid, request)];
4641
+ return __generator(this, function (_a) {
4642
+ return [2 /*return*/, this.signPayload(accessToken, keyId, request)];
4638
4643
  });
4639
4644
  });
4640
4645
  };
@@ -4646,7 +4651,7 @@ var PopTokenGenerator = /** @class */ (function () {
4646
4651
  * @param claims
4647
4652
  * @returns
4648
4653
  */
4649
- PopTokenGenerator.prototype.signPayload = function (payload, kid, request, claims) {
4654
+ PopTokenGenerator.prototype.signPayload = function (payload, keyId, request, claims) {
4650
4655
  return __awaiter(this, void 0, void 0, function () {
4651
4656
  var resourceRequestMethod, resourceRequestUri, shrClaims, shrNonce, resourceUrlString, resourceUrlComponents;
4652
4657
  return __generator(this, function (_a) {
@@ -4655,7 +4660,7 @@ var PopTokenGenerator = /** @class */ (function () {
4655
4660
  resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims, shrNonce = request.shrNonce;
4656
4661
  resourceUrlString = (resourceRequestUri) ? new UrlString(resourceRequestUri) : undefined;
4657
4662
  resourceUrlComponents = resourceUrlString === null || resourceUrlString === void 0 ? void 0 : resourceUrlString.getUrlComponents();
4658
- return [4 /*yield*/, this.cryptoUtils.signJwt(__assign({ at: payload, ts: TimeUtils.nowSeconds(), m: resourceRequestMethod === null || resourceRequestMethod === void 0 ? void 0 : resourceRequestMethod.toUpperCase(), u: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.HostNameAndPort, nonce: shrNonce || this.cryptoUtils.createNewGuid(), p: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.AbsolutePath, q: (resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.QueryString) ? [[], resourceUrlComponents.QueryString] : undefined, client_claims: shrClaims || undefined }, claims), kid, request.correlationId)];
4663
+ 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), keyId, request.correlationId)];
4659
4664
  case 1: return [2 /*return*/, _a.sent()];
4660
4665
  }
4661
4666
  });
@@ -4826,7 +4831,7 @@ var ResponseHandler = /** @class */ (function () {
4826
4831
  * @param serverTokenResponse
4827
4832
  * @param authority
4828
4833
  */
4829
- ResponseHandler.prototype.handleServerTokenResponse = function (serverTokenResponse, authority, reqTimestamp, request, authCodePayload, oboAssertion, handlingRefreshTokenResponse) {
4834
+ ResponseHandler.prototype.handleServerTokenResponse = function (serverTokenResponse, authority, reqTimestamp, request, authCodePayload, userAssertionHash, handlingRefreshTokenResponse) {
4830
4835
  return __awaiter(this, void 0, void 0, function () {
4831
4836
  var idTokenObj, requestStateObj, cacheRecord, cacheContext, key, account;
4832
4837
  return __generator(this, function (_a) {
@@ -4848,7 +4853,7 @@ var ResponseHandler = /** @class */ (function () {
4848
4853
  }
4849
4854
  // Add keyId from request to serverTokenResponse if defined
4850
4855
  serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;
4851
- cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload);
4856
+ cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, request, idTokenObj, userAssertionHash, authCodePayload);
4852
4857
  _a.label = 1;
4853
4858
  case 1:
4854
4859
  _a.trys.push([1, , 5, 8]);
@@ -4896,7 +4901,7 @@ var ResponseHandler = /** @class */ (function () {
4896
4901
  * @param idTokenObj
4897
4902
  * @param authority
4898
4903
  */
4899
- ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload) {
4904
+ ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, request, idTokenObj, userAssertionHash, authCodePayload) {
4900
4905
  var env = authority.getPreferredCache();
4901
4906
  if (StringUtils.isEmpty(env)) {
4902
4907
  throw ClientAuthError.createInvalidCacheEnvironmentError();
@@ -4905,8 +4910,8 @@ var ResponseHandler = /** @class */ (function () {
4905
4910
  var cachedIdToken;
4906
4911
  var cachedAccount;
4907
4912
  if (!StringUtils.isEmpty(serverTokenResponse.id_token) && !!idTokenObj) {
4908
- cachedIdToken = IdTokenEntity.createIdTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.id_token || Constants.EMPTY_STRING, this.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING, oboAssertion);
4909
- cachedAccount = this.generateAccountEntity(serverTokenResponse, idTokenObj, authority, oboAssertion, authCodePayload);
4913
+ cachedIdToken = IdTokenEntity.createIdTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.id_token || Constants.EMPTY_STRING, this.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING);
4914
+ cachedAccount = this.generateAccountEntity(serverTokenResponse, idTokenObj, authority, authCodePayload);
4910
4915
  }
4911
4916
  // AccessToken
4912
4917
  var cachedAccessToken = null;
@@ -4924,12 +4929,12 @@ var ResponseHandler = /** @class */ (function () {
4924
4929
  var extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;
4925
4930
  var refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;
4926
4931
  // non AAD scenarios can have empty realm
4927
- 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);
4932
+ 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, userAssertionHash, serverTokenResponse.key_id, request.claims, request.requestedClaimsHash);
4928
4933
  }
4929
4934
  // refreshToken
4930
4935
  var cachedRefreshToken = null;
4931
4936
  if (!StringUtils.isEmpty(serverTokenResponse.refresh_token)) {
4932
- cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.refresh_token || Constants.EMPTY_STRING, this.clientId, serverTokenResponse.foci, oboAssertion);
4937
+ cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.refresh_token || Constants.EMPTY_STRING, this.clientId, serverTokenResponse.foci, userAssertionHash);
4933
4938
  }
4934
4939
  // appMetadata
4935
4940
  var cachedAppMetadata = null;
@@ -4944,22 +4949,22 @@ var ResponseHandler = /** @class */ (function () {
4944
4949
  * @param idToken
4945
4950
  * @param authority
4946
4951
  */
4947
- ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, oboAssertion, authCodePayload) {
4952
+ ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, authCodePayload) {
4948
4953
  var authorityType = authority.authorityType;
4949
4954
  var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : Constants.EMPTY_STRING;
4950
4955
  var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : Constants.EMPTY_STRING;
4951
4956
  // ADFS does not require client_info in the response
4952
4957
  if (authorityType === exports.AuthorityType.Adfs) {
4953
4958
  this.logger.verbose("Authority type is ADFS, creating ADFS account");
4954
- return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);
4959
+ return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
4955
4960
  }
4956
4961
  // This fallback applies to B2C as well as they fall under an AAD account type.
4957
4962
  if (StringUtils.isEmpty(serverTokenResponse.client_info) && authority.protocolMode === "AAD") {
4958
4963
  throw ClientAuthError.createClientInfoEmptyError();
4959
4964
  }
4960
4965
  return serverTokenResponse.client_info ?
4961
- AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost) :
4962
- AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);
4966
+ AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost) :
4967
+ AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
4963
4968
  };
4964
4969
  /**
4965
4970
  * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.
@@ -4974,9 +4979,9 @@ var ResponseHandler = /** @class */ (function () {
4974
4979
  ResponseHandler.generateAuthenticationResult = function (cryptoObj, authority, cacheRecord, fromTokenCache, request, idTokenObj, requestState, code) {
4975
4980
  var _a, _b, _c;
4976
4981
  return __awaiter(this, void 0, void 0, function () {
4977
- var accessToken, responseScopes, expiresOn, extExpiresOn, familyId, popTokenGenerator, uid, tid;
4978
- return __generator(this, function (_d) {
4979
- switch (_d.label) {
4982
+ var accessToken, responseScopes, expiresOn, extExpiresOn, familyId, popTokenGenerator, _d, secret, keyId, uid, tid;
4983
+ return __generator(this, function (_e) {
4984
+ switch (_e.label) {
4980
4985
  case 0:
4981
4986
  accessToken = Constants.EMPTY_STRING;
4982
4987
  responseScopes = [];
@@ -4985,18 +4990,22 @@ var ResponseHandler = /** @class */ (function () {
4985
4990
  if (!cacheRecord.accessToken) return [3 /*break*/, 4];
4986
4991
  if (!(cacheRecord.accessToken.tokenType === exports.AuthenticationScheme.POP)) return [3 /*break*/, 2];
4987
4992
  popTokenGenerator = new PopTokenGenerator(cryptoObj);
4988
- return [4 /*yield*/, popTokenGenerator.signPopToken(cacheRecord.accessToken.secret, request)];
4993
+ _d = cacheRecord.accessToken, secret = _d.secret, keyId = _d.keyId;
4994
+ if (!keyId) {
4995
+ throw ClientAuthError.createKeyIdMissingError();
4996
+ }
4997
+ return [4 /*yield*/, popTokenGenerator.signPopToken(secret, keyId, request)];
4989
4998
  case 1:
4990
- accessToken = _d.sent();
4999
+ accessToken = _e.sent();
4991
5000
  return [3 /*break*/, 3];
4992
5001
  case 2:
4993
5002
  accessToken = cacheRecord.accessToken.secret;
4994
- _d.label = 3;
5003
+ _e.label = 3;
4995
5004
  case 3:
4996
5005
  responseScopes = ScopeSet.fromString(cacheRecord.accessToken.target).asArray();
4997
5006
  expiresOn = new Date(Number(cacheRecord.accessToken.expiresOn) * 1000);
4998
5007
  extExpiresOn = new Date(Number(cacheRecord.accessToken.extendedExpiresOn) * 1000);
4999
- _d.label = 4;
5008
+ _e.label = 4;
5000
5009
  case 4:
5001
5010
  if (cacheRecord.appMetadata) {
5002
5011
  familyId = cacheRecord.appMetadata.familyId === THE_FAMILY_ID ? THE_FAMILY_ID : Constants.EMPTY_STRING;
@@ -5196,7 +5205,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5196
5205
  */
5197
5206
  AuthorizationCodeClient.prototype.createTokenRequestBody = function (request) {
5198
5207
  return __awaiter(this, void 0, void 0, function () {
5199
- var parameterBuilder, clientAssertion, popTokenGenerator, cnfString, correlationId, ccsCred, clientInfo, clientInfo;
5208
+ var parameterBuilder, clientAssertion, popTokenGenerator, reqCnfData, correlationId, ccsCred, clientInfo, clientInfo;
5200
5209
  var _a;
5201
5210
  return __generator(this, function (_b) {
5202
5211
  switch (_b.label) {
@@ -5244,8 +5253,9 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5244
5253
  popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5245
5254
  return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5246
5255
  case 1:
5247
- cnfString = _b.sent();
5248
- parameterBuilder.addPopToken(cnfString);
5256
+ reqCnfData = _b.sent();
5257
+ // SPA PoP requires full Base64Url encoded req_cnf string (unhashed)
5258
+ parameterBuilder.addPopToken(reqCnfData.reqCnfString);
5249
5259
  return [3 /*break*/, 3];
5250
5260
  case 2:
5251
5261
  if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
@@ -5316,7 +5326,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5316
5326
  */
5317
5327
  AuthorizationCodeClient.prototype.createAuthCodeUrlQueryString = function (request) {
5318
5328
  return __awaiter(this, void 0, void 0, function () {
5319
- var parameterBuilder, requestScopes, correlationId, accountSid, clientInfo, clientInfo, popTokenGenerator, cnf, cnfHash;
5329
+ var parameterBuilder, requestScopes, correlationId, accountSid, clientInfo, clientInfo, popTokenGenerator, reqCnfData;
5320
5330
  return __generator(this, function (_a) {
5321
5331
  switch (_a.label) {
5322
5332
  case 0:
@@ -5408,20 +5418,17 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5408
5418
  if (request.extraQueryParameters) {
5409
5419
  parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
5410
5420
  }
5411
- if (!request.nativeBroker) return [3 /*break*/, 3];
5421
+ if (!request.nativeBroker) return [3 /*break*/, 2];
5412
5422
  // signal ests that this is a WAM call
5413
5423
  parameterBuilder.addNativeBroker();
5414
- if (!(request.authenticationScheme === exports.AuthenticationScheme.POP)) return [3 /*break*/, 3];
5424
+ if (!(request.authenticationScheme === exports.AuthenticationScheme.POP)) return [3 /*break*/, 2];
5415
5425
  popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5416
5426
  return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5417
5427
  case 1:
5418
- cnf = _a.sent();
5419
- return [4 /*yield*/, popTokenGenerator.generateCnfHash(cnf)];
5420
- case 2:
5421
- cnfHash = _a.sent();
5422
- parameterBuilder.addPopToken(cnfHash);
5423
- _a.label = 3;
5424
- case 3: return [2 /*return*/, parameterBuilder.createQueryString()];
5428
+ reqCnfData = _a.sent();
5429
+ parameterBuilder.addPopToken(reqCnfData.reqCnfHash);
5430
+ _a.label = 2;
5431
+ case 2: return [2 /*return*/, parameterBuilder.createQueryString()];
5425
5432
  }
5426
5433
  });
5427
5434
  });
@@ -5818,7 +5825,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5818
5825
  */
5819
5826
  RefreshTokenClient.prototype.createTokenRequestBody = function (request) {
5820
5827
  return __awaiter(this, void 0, void 0, function () {
5821
- var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, cnfString, clientInfo;
5828
+ var parameterBuilder, correlationId, clientAssertion, popTokenGenerator, reqCnfData, clientInfo;
5822
5829
  return __generator(this, function (_a) {
5823
5830
  switch (_a.label) {
5824
5831
  case 0:
@@ -5848,8 +5855,9 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5848
5855
  popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5849
5856
  return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5850
5857
  case 1:
5851
- cnfString = _a.sent();
5852
- parameterBuilder.addPopToken(cnfString);
5858
+ reqCnfData = _a.sent();
5859
+ // SPA PoP requires full Base64Url encoded req_cnf string (unhashed)
5860
+ parameterBuilder.addPopToken(reqCnfData.reqCnfString);
5853
5861
  return [3 /*break*/, 3];
5854
5862
  case 2:
5855
5863
  if (request.authenticationScheme === exports.AuthenticationScheme.SSH) {
@@ -6038,8 +6046,9 @@ var ClientCredentialClient = /** @class */ (function (_super) {
6038
6046
  if (this.config.clientCredentials.clientSecret) {
6039
6047
  parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
6040
6048
  }
6041
- if (this.config.clientCredentials.clientAssertion) {
6042
- var clientAssertion = this.config.clientCredentials.clientAssertion;
6049
+ // Use clientAssertion from request, fallback to client assertion in base configuration
6050
+ var clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;
6051
+ if (clientAssertion) {
6043
6052
  parameterBuilder.addClientAssertion(clientAssertion.assertion);
6044
6053
  parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
6045
6054
  }
@@ -6069,44 +6078,64 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6069
6078
  */
6070
6079
  OnBehalfOfClient.prototype.acquireToken = function (request) {
6071
6080
  return __awaiter(this, void 0, void 0, function () {
6072
- var cachedAuthenticationResult;
6073
- return __generator(this, function (_a) {
6074
- switch (_a.label) {
6081
+ var _a;
6082
+ return __generator(this, function (_b) {
6083
+ switch (_b.label) {
6075
6084
  case 0:
6076
6085
  this.scopeSet = new ScopeSet(request.scopes || []);
6077
- if (!request.skipCache) return [3 /*break*/, 2];
6078
- return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
6079
- case 1: return [2 /*return*/, _a.sent()];
6080
- case 2: return [4 /*yield*/, this.getCachedAuthenticationResult(request)];
6086
+ // generate the user_assertion_hash for OBOAssertion
6087
+ _a = this;
6088
+ return [4 /*yield*/, this.cryptoUtils.hashString(request.oboAssertion)];
6089
+ case 1:
6090
+ // generate the user_assertion_hash for OBOAssertion
6091
+ _a.userAssertionHash = _b.sent();
6092
+ if (!request.skipCache) return [3 /*break*/, 3];
6093
+ return [4 /*yield*/, this.executeTokenRequest(request, this.authority, this.userAssertionHash)];
6094
+ case 2: return [2 /*return*/, _b.sent()];
6081
6095
  case 3:
6082
- cachedAuthenticationResult = _a.sent();
6083
- if (!cachedAuthenticationResult) return [3 /*break*/, 4];
6084
- return [2 /*return*/, cachedAuthenticationResult];
6085
- case 4: return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
6086
- case 5: return [2 /*return*/, _a.sent()];
6096
+ _b.trys.push([3, 5, , 7]);
6097
+ return [4 /*yield*/, this.getCachedAuthenticationResult(request)];
6098
+ case 4: return [2 /*return*/, _b.sent()];
6099
+ case 5:
6100
+ _b.sent();
6101
+ return [4 /*yield*/, this.executeTokenRequest(request, this.authority, this.userAssertionHash)];
6102
+ case 6:
6103
+ // Any failure falls back to interactive request, once we implement distributed cache, we plan to handle `createRefreshRequiredError` to refresh using the RT
6104
+ return [2 /*return*/, _b.sent()];
6105
+ case 7: return [2 /*return*/];
6087
6106
  }
6088
6107
  });
6089
6108
  });
6090
6109
  };
6091
6110
  /**
6092
6111
  * look up cache for tokens
6112
+ * Find idtoken in the cache
6113
+ * Find accessToken based on user assertion and account info in the cache
6114
+ * Please note we are not yet supported OBO tokens refreshed with long lived RT. User will have to send a new assertion if the current access token expires
6115
+ * This is to prevent security issues when the assertion changes over time, however, longlived RT helps retaining the session
6093
6116
  * @param request
6094
6117
  */
6095
6118
  OnBehalfOfClient.prototype.getCachedAuthenticationResult = function (request) {
6096
- var _a;
6119
+ var _a, _b;
6097
6120
  return __awaiter(this, void 0, void 0, function () {
6098
6121
  var cachedAccessToken, cachedIdToken, idTokenObject, cachedAccount, localAccountId, accountInfo;
6099
- return __generator(this, function (_b) {
6100
- switch (_b.label) {
6122
+ return __generator(this, function (_c) {
6123
+ switch (_c.label) {
6101
6124
  case 0:
6102
- cachedAccessToken = this.readAccessTokenFromCache();
6103
- if (!cachedAccessToken ||
6104
- TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
6105
- // Update the server telemetry outcome
6106
- (_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(!cachedAccessToken ? CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED : CacheOutcome.NO_CACHED_ACCESS_TOKEN);
6107
- return [2 /*return*/, null];
6125
+ cachedAccessToken = this.readAccessTokenFromCacheForOBO(this.config.authOptions.clientId, request);
6126
+ if (!cachedAccessToken) {
6127
+ // Must refresh due to non-existent access_token.
6128
+ (_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
6129
+ this.logger.info("SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.");
6130
+ throw ClientAuthError.createRefreshRequiredError();
6131
+ }
6132
+ else if (TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
6133
+ // Access token expired, will need to renewed
6134
+ (_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
6135
+ this.logger.info("OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within " + this.config.systemOptions.tokenRenewalOffsetSeconds + " seconds.");
6136
+ throw ClientAuthError.createRefreshRequiredError();
6108
6137
  }
6109
- cachedIdToken = this.readIdTokenFromCache(request);
6138
+ cachedIdToken = this.readIdTokenFromCacheForOBO(request, cachedAccessToken.homeAccountId);
6110
6139
  cachedAccount = null;
6111
6140
  if (cachedIdToken) {
6112
6141
  idTokenObject = new AuthToken(cachedIdToken.secret, this.config.cryptoInterface);
@@ -6118,7 +6147,11 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6118
6147
  username: Constants.EMPTY_STRING,
6119
6148
  localAccountId: localAccountId || Constants.EMPTY_STRING
6120
6149
  };
6121
- cachedAccount = this.readAccountFromCache(accountInfo);
6150
+ cachedAccount = this.cacheManager.readAccountFromCache(accountInfo);
6151
+ }
6152
+ // increment telemetry cache hit counter
6153
+ if (this.config.serverTelemetryManager) {
6154
+ this.config.serverTelemetryManager.incrementCacheHits();
6122
6155
  }
6123
6156
  return [4 /*yield*/, ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
6124
6157
  account: cachedAccount,
@@ -6127,45 +6160,23 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6127
6160
  refreshToken: null,
6128
6161
  appMetadata: null
6129
6162
  }, true, request, idTokenObject)];
6130
- case 1: return [2 /*return*/, _b.sent()];
6163
+ case 1: return [2 /*return*/, _c.sent()];
6131
6164
  }
6132
6165
  });
6133
6166
  });
6134
6167
  };
6135
6168
  /**
6136
- * read access token from cache TODO: CacheManager API should be used here
6169
+ * read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager
6170
+ * Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
6137
6171
  * @param request
6138
6172
  */
6139
- OnBehalfOfClient.prototype.readAccessTokenFromCache = function () {
6140
- var accessTokenFilter = {
6141
- environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
6142
- credentialType: exports.CredentialType.ACCESS_TOKEN,
6143
- clientId: this.config.authOptions.clientId,
6144
- realm: this.authority.tenant,
6145
- target: this.scopeSet.printScopesLowerCase(),
6146
- };
6147
- var credentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);
6148
- var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
6149
- var numAccessTokens = accessTokens.length;
6150
- if (numAccessTokens < 1) {
6151
- return null;
6152
- }
6153
- else if (numAccessTokens > 1) {
6154
- throw ClientAuthError.createMultipleMatchingTokensInCacheError();
6155
- }
6156
- return accessTokens[0];
6157
- };
6158
- /**
6159
- * read idtoken from cache TODO: CacheManager API should be used here instead
6160
- * @param request
6161
- */
6162
- OnBehalfOfClient.prototype.readIdTokenFromCache = function (request) {
6173
+ OnBehalfOfClient.prototype.readIdTokenFromCacheForOBO = function (request, atHomeAccountId) {
6163
6174
  var idTokenFilter = {
6175
+ homeAccountId: atHomeAccountId,
6164
6176
  environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
6165
6177
  credentialType: exports.CredentialType.ID_TOKEN,
6166
6178
  clientId: this.config.authOptions.clientId,
6167
- realm: this.authority.tenant,
6168
- oboAssertion: request.oboAssertion
6179
+ realm: this.authority.tenant
6169
6180
  };
6170
6181
  var credentialCache = this.cacheManager.getCredentialsFilteredBy(idTokenFilter);
6171
6182
  var idTokens = Object.keys(credentialCache.idTokens).map(function (key) { return credentialCache.idTokens[key]; });
@@ -6176,18 +6187,44 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6176
6187
  return idTokens[0];
6177
6188
  };
6178
6189
  /**
6179
- * read account from cache, TODO: CacheManager API should be used here instead
6180
- * @param account
6190
+ * Fetches the cached access token based on incoming assertion
6191
+ * @param clientId
6192
+ * @param request
6193
+ * @param userAssertionHash
6181
6194
  */
6182
- OnBehalfOfClient.prototype.readAccountFromCache = function (account) {
6183
- return this.cacheManager.readAccountFromCache(account);
6195
+ OnBehalfOfClient.prototype.readAccessTokenFromCacheForOBO = function (clientId, request) {
6196
+ var authScheme = request.authenticationScheme || exports.AuthenticationScheme.BEARER;
6197
+ /*
6198
+ * Distinguish between Bearer and PoP/SSH token cache types
6199
+ * Cast to lowercase to handle "bearer" from ADFS
6200
+ */
6201
+ var credentialType = (authScheme && authScheme.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : exports.CredentialType.ACCESS_TOKEN;
6202
+ var accessTokenFilter = {
6203
+ credentialType: credentialType,
6204
+ clientId: clientId,
6205
+ target: this.scopeSet.printScopesLowerCase(),
6206
+ tokenType: authScheme,
6207
+ keyId: request.sshKid,
6208
+ requestedClaimsHash: request.requestedClaimsHash,
6209
+ userAssertionHash: this.userAssertionHash
6210
+ };
6211
+ var credentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);
6212
+ var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
6213
+ var numAccessTokens = accessTokens.length;
6214
+ if (numAccessTokens < 1) {
6215
+ return null;
6216
+ }
6217
+ else if (numAccessTokens > 1) {
6218
+ throw ClientAuthError.createMultipleMatchingTokensInCacheError();
6219
+ }
6220
+ return accessTokens[0];
6184
6221
  };
6185
6222
  /**
6186
6223
  * Make a network call to the server requesting credentials
6187
6224
  * @param request
6188
6225
  * @param authority
6189
6226
  */
6190
- OnBehalfOfClient.prototype.executeTokenRequest = function (request, authority) {
6227
+ OnBehalfOfClient.prototype.executeTokenRequest = function (request, authority, userAssertionHash) {
6191
6228
  return __awaiter(this, void 0, void 0, function () {
6192
6229
  var requestBody, headers, thumbprint, reqTimestamp, response, responseHandler, tokenResponse;
6193
6230
  return __generator(this, function (_a) {
@@ -6212,7 +6249,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6212
6249
  response = _a.sent();
6213
6250
  responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
6214
6251
  responseHandler.validateTokenResponse(response.body);
6215
- return [4 /*yield*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request)];
6252
+ return [4 /*yield*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, undefined, userAssertionHash)];
6216
6253
  case 2:
6217
6254
  tokenResponse = _a.sent();
6218
6255
  return [2 /*return*/, tokenResponse];
@@ -7416,6 +7453,87 @@ var StubbedNetworkModule = {
7416
7453
  }
7417
7454
  };
7418
7455
 
7456
+ /*
7457
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7458
+ * Licensed under the MIT License.
7459
+ */
7460
+ /**
7461
+ * ClientAuthErrorMessage class containing string constants used by error codes and messages.
7462
+ */
7463
+ var JoseHeaderErrorMessage = {
7464
+ missingKidError: {
7465
+ code: "missing_kid_error",
7466
+ desc: "The JOSE Header for the requested JWT, JWS or JWK object requires a keyId to be configured as the 'kid' header claim. No 'kid' value was provided."
7467
+ },
7468
+ missingAlgError: {
7469
+ code: "missing_alg_error",
7470
+ desc: "The JOSE Header for the requested JWT, JWS or JWK object requires an algorithm to be specified as the 'alg' header claim. No 'alg' value was provided."
7471
+ },
7472
+ };
7473
+ /**
7474
+ * Error thrown when there is an error in the client code running on the browser.
7475
+ */
7476
+ var JoseHeaderError = /** @class */ (function (_super) {
7477
+ __extends(JoseHeaderError, _super);
7478
+ function JoseHeaderError(errorCode, errorMessage) {
7479
+ var _this = _super.call(this, errorCode, errorMessage) || this;
7480
+ _this.name = "JoseHeaderError";
7481
+ Object.setPrototypeOf(_this, JoseHeaderError.prototype);
7482
+ return _this;
7483
+ }
7484
+ /**
7485
+ * Creates an error thrown when keyId isn't set on JOSE header.
7486
+ */
7487
+ JoseHeaderError.createMissingKidError = function () {
7488
+ return new JoseHeaderError(JoseHeaderErrorMessage.missingKidError.code, JoseHeaderErrorMessage.missingKidError.desc);
7489
+ };
7490
+ /**
7491
+ * Creates an error thrown when algorithm isn't set on JOSE header.
7492
+ */
7493
+ JoseHeaderError.createMissingAlgError = function () {
7494
+ return new JoseHeaderError(JoseHeaderErrorMessage.missingAlgError.code, JoseHeaderErrorMessage.missingAlgError.desc);
7495
+ };
7496
+ return JoseHeaderError;
7497
+ }(AuthError));
7498
+
7499
+ /*
7500
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7501
+ * Licensed under the MIT License.
7502
+ */
7503
+ var JoseHeader = /** @class */ (function () {
7504
+ function JoseHeader(options) {
7505
+ this.typ = options.typ;
7506
+ this.alg = options.alg;
7507
+ this.kid = options.kid;
7508
+ }
7509
+ /**
7510
+ * Builds SignedHttpRequest formatted JOSE Header from the
7511
+ * JOSE Header options provided or previously set on the object and returns
7512
+ * the stringified header object.
7513
+ * Throws if keyId or algorithm aren't provided since they are required for Access Token Binding.
7514
+ * @param shrHeaderOptions
7515
+ * @returns
7516
+ */
7517
+ JoseHeader.getShrHeaderString = function (shrHeaderOptions) {
7518
+ // KeyID is required on the SHR header
7519
+ if (!shrHeaderOptions.kid) {
7520
+ throw JoseHeaderError.createMissingKidError();
7521
+ }
7522
+ // Alg is required on the SHR header
7523
+ if (!shrHeaderOptions.alg) {
7524
+ throw JoseHeaderError.createMissingAlgError();
7525
+ }
7526
+ var shrHeader = new JoseHeader({
7527
+ // Access Token PoP headers must have type JWT, but the type header can be overriden for special cases
7528
+ typ: shrHeaderOptions.typ || JsonTypes.Jwt,
7529
+ kid: shrHeaderOptions.kid,
7530
+ alg: shrHeaderOptions.alg
7531
+ });
7532
+ return JSON.stringify(shrHeader);
7533
+ };
7534
+ return JoseHeader;
7535
+ }());
7536
+
7419
7537
  /*
7420
7538
  * Copyright (c) Microsoft Corporation. All rights reserved.
7421
7539
  * Licensed under the MIT License.
@@ -8054,6 +8172,7 @@ exports.IdToken = AuthToken;
8054
8172
  exports.IdTokenEntity = IdTokenEntity;
8055
8173
  exports.InteractionRequiredAuthError = InteractionRequiredAuthError;
8056
8174
  exports.InteractionRequiredAuthErrorMessage = InteractionRequiredAuthErrorMessage;
8175
+ exports.JoseHeader = JoseHeader;
8057
8176
  exports.Logger = Logger;
8058
8177
  exports.NetworkManager = NetworkManager;
8059
8178
  exports.OIDC_DEFAULT_SCOPES = OIDC_DEFAULT_SCOPES;