@azure/msal-common 6.4.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 (114) hide show
  1. package/dist/_virtual/_tslib.js +1 -1
  2. package/dist/account/AuthToken.js +1 -1
  3. package/dist/account/CcsCredential.js +1 -1
  4. package/dist/account/ClientCredentials.d.ts +15 -0
  5. package/dist/account/ClientCredentials.d.ts.map +1 -0
  6. package/dist/account/ClientInfo.js +1 -1
  7. package/dist/authority/Authority.js +1 -1
  8. package/dist/authority/AuthorityFactory.js +1 -1
  9. package/dist/authority/AuthorityOptions.js +1 -1
  10. package/dist/authority/AuthorityType.js +1 -1
  11. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  12. package/dist/authority/OpenIdConfigResponse.js +1 -1
  13. package/dist/authority/ProtocolMode.js +1 -1
  14. package/dist/authority/RegionDiscovery.js +1 -1
  15. package/dist/cache/CacheManager.d.ts +2 -2
  16. package/dist/cache/CacheManager.d.ts.map +1 -1
  17. package/dist/cache/CacheManager.js +9 -9
  18. package/dist/cache/CacheManager.js.map +1 -1
  19. package/dist/cache/entities/AccessTokenEntity.d.ts +1 -1
  20. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  21. package/dist/cache/entities/AccessTokenEntity.js +3 -3
  22. package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
  23. package/dist/cache/entities/AccountEntity.d.ts +2 -4
  24. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  25. package/dist/cache/entities/AccountEntity.js +3 -6
  26. package/dist/cache/entities/AccountEntity.js.map +1 -1
  27. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  28. package/dist/cache/entities/AuthorityMetadataEntity.js +1 -1
  29. package/dist/cache/entities/CacheRecord.js +1 -1
  30. package/dist/cache/entities/CredentialEntity.d.ts +2 -2
  31. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  32. package/dist/cache/entities/CredentialEntity.js +2 -2
  33. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  34. package/dist/cache/entities/IdTokenEntity.d.ts +1 -1
  35. package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -1
  36. package/dist/cache/entities/IdTokenEntity.js +2 -3
  37. package/dist/cache/entities/IdTokenEntity.js.map +1 -1
  38. package/dist/cache/entities/RefreshTokenEntity.d.ts +1 -1
  39. package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
  40. package/dist/cache/entities/RefreshTokenEntity.js +3 -3
  41. package/dist/cache/entities/RefreshTokenEntity.js.map +1 -1
  42. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  43. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  44. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  45. package/dist/cache/utils/CacheTypes.d.ts +1 -1
  46. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  47. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  48. package/dist/client/AuthorizationCodeClient.js +3 -3
  49. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  50. package/dist/client/BaseClient.js +1 -1
  51. package/dist/client/ClientCredentialClient.js +1 -1
  52. package/dist/client/DeviceCodeClient.js +1 -1
  53. package/dist/client/OnBehalfOfClient.d.ts +12 -9
  54. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  55. package/dist/client/OnBehalfOfClient.js +89 -62
  56. package/dist/client/OnBehalfOfClient.js.map +1 -1
  57. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  58. package/dist/client/RefreshTokenClient.js +3 -3
  59. package/dist/client/RefreshTokenClient.js.map +1 -1
  60. package/dist/client/SilentFlowClient.js +1 -1
  61. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  62. package/dist/client/UsernamePasswordClient.js +3 -4
  63. package/dist/client/UsernamePasswordClient.js.map +1 -1
  64. package/dist/config/ClientConfiguration.d.ts +1 -11
  65. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  66. package/dist/config/ClientConfiguration.js +1 -1
  67. package/dist/config/ClientConfiguration.js.map +1 -1
  68. package/dist/crypto/ICrypto.js +1 -1
  69. package/dist/crypto/JoseHeader.js +1 -1
  70. package/dist/crypto/PopTokenGenerator.js +1 -1
  71. package/dist/error/AuthError.js +1 -1
  72. package/dist/error/ClientAuthError.js +1 -1
  73. package/dist/error/ClientConfigurationError.js +1 -1
  74. package/dist/error/InteractionRequiredAuthError.js +1 -1
  75. package/dist/error/JoseHeaderError.js +1 -1
  76. package/dist/error/ServerError.js +1 -1
  77. package/dist/index.cjs.js +128 -102
  78. package/dist/index.cjs.js.map +1 -1
  79. package/dist/index.js +1 -1
  80. package/dist/logger/Logger.js +1 -1
  81. package/dist/network/INetworkModule.js +1 -1
  82. package/dist/network/NetworkManager.js +1 -1
  83. package/dist/network/ThrottlingUtils.js +1 -1
  84. package/dist/packageMetadata.d.ts +1 -1
  85. package/dist/packageMetadata.js +2 -2
  86. package/dist/packageMetadata.js.map +1 -1
  87. package/dist/request/AuthenticationHeaderParser.js +1 -1
  88. package/dist/request/BaseAuthRequest.d.ts +1 -3
  89. package/dist/request/BaseAuthRequest.d.ts.map +1 -1
  90. package/dist/request/CommonClientCredentialRequest.d.ts +2 -0
  91. package/dist/request/CommonClientCredentialRequest.d.ts.map +1 -1
  92. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  93. package/dist/request/RequestParameterBuilder.js +7 -3
  94. package/dist/request/RequestParameterBuilder.js.map +1 -1
  95. package/dist/request/RequestValidator.js +1 -1
  96. package/dist/request/ScopeSet.js +1 -1
  97. package/dist/response/ResponseHandler.d.ts +1 -1
  98. package/dist/response/ResponseHandler.d.ts.map +1 -1
  99. package/dist/response/ResponseHandler.js +12 -12
  100. package/dist/response/ResponseHandler.js.map +1 -1
  101. package/dist/telemetry/performance/PerformanceClient.js +1 -1
  102. package/dist/telemetry/performance/PerformanceEvent.d.ts +12 -0
  103. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  104. package/dist/telemetry/performance/PerformanceEvent.js +1 -1
  105. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -1
  106. package/dist/telemetry/performance/StubPerformanceClient.js +1 -1
  107. package/dist/telemetry/server/ServerTelemetryManager.js +1 -1
  108. package/dist/url/UrlString.js +1 -1
  109. package/dist/utils/Constants.js +1 -1
  110. package/dist/utils/Constants.js.map +1 -1
  111. package/dist/utils/ProtocolUtils.js +1 -1
  112. package/dist/utils/StringUtils.js +1 -1
  113. package/dist/utils/TimeUtils.js +1 -1
  114. package/package.json +1 -1
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v6.4.0 2022-06-06 */
1
+ /*! @azure/msal-common v7.0.0 2022-06-13 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -1357,7 +1357,7 @@ var Logger = /** @class */ (function () {
1357
1357
 
1358
1358
  /* eslint-disable header/header */
1359
1359
  var name = "@azure/msal-common";
1360
- var version = "6.4.0";
1360
+ var version = "7.0.0";
1361
1361
 
1362
1362
  /*
1363
1363
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1400,9 +1400,9 @@ exports.AzureCloudInstance = void 0;
1400
1400
  * familyId: Family ID identifier, usually only used for refresh tokens
1401
1401
  * realm: Full tenant or organizational identifier that the account belongs to
1402
1402
  * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
1403
- * oboAssertion: access token passed in as part of OBO request
1404
1403
  * tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
1405
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
1406
1406
  * }
1407
1407
  */
1408
1408
  var CredentialEntity = /** @class */ (function () {
@@ -2043,7 +2043,6 @@ exports.AuthorityType = void 0;
2043
2043
  * clientInfo: Full base64 encoded client info received from ESTS
2044
2044
  * lastModificationTime: last time this entity was modified in the cache
2045
2045
  * lastModificationApp:
2046
- * oboAssertion: access token passed in as part of OBO request
2047
2046
  * idTokenClaims: Object containing claims parsed from ID token
2048
2047
  * nativeAccountId: Account identifier on the native device
2049
2048
  * }
@@ -2122,7 +2121,7 @@ var AccountEntity = /** @class */ (function () {
2122
2121
  * @param idToken
2123
2122
  * @param policy
2124
2123
  */
2125
- AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment, nativeAccountId) {
2124
+ AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, cloudGraphHostName, msGraphHost, environment, nativeAccountId) {
2126
2125
  var _a, _b, _c, _d, _e, _f;
2127
2126
  var account = new AccountEntity();
2128
2127
  account.authorityType = exports.CacheAccountType.MSSTS_ACCOUNT_TYPE;
@@ -2136,7 +2135,6 @@ var AccountEntity = /** @class */ (function () {
2136
2135
  account.environment = env;
2137
2136
  // non AAD scenarios can have empty realm
2138
2137
  account.realm = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.tid) || Constants.EMPTY_STRING;
2139
- account.oboAssertion = oboAssertion;
2140
2138
  if (idToken) {
2141
2139
  account.idTokenClaims = idToken.claims;
2142
2140
  // How do you account for MSA CID here?
@@ -2157,14 +2155,13 @@ var AccountEntity = /** @class */ (function () {
2157
2155
  * @param authority
2158
2156
  * @param idToken
2159
2157
  */
2160
- AccountEntity.createGenericAccount = function (homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment) {
2158
+ AccountEntity.createGenericAccount = function (homeAccountId, idToken, authority, cloudGraphHostName, msGraphHost, environment) {
2161
2159
  var _a, _b, _c, _d;
2162
2160
  var account = new AccountEntity();
2163
2161
  account.authorityType = (authority && authority.authorityType === exports.AuthorityType.Adfs) ? exports.CacheAccountType.ADFS_ACCOUNT_TYPE : exports.CacheAccountType.GENERIC_ACCOUNT_TYPE;
2164
2162
  account.homeAccountId = homeAccountId;
2165
2163
  // non AAD scenarios can have empty realm
2166
2164
  account.realm = Constants.EMPTY_STRING;
2167
- account.oboAssertion = oboAssertion;
2168
2165
  var env = environment || authority && authority.getPreferredCache();
2169
2166
  if (!env) {
2170
2167
  throw ClientAuthError.createInvalidCacheEnvironmentError();
@@ -2453,7 +2450,7 @@ var CacheManager = /** @class */ (function () {
2453
2450
  * @param target
2454
2451
  */
2455
2452
  CacheManager.prototype.getCredentialsFilteredBy = function (filter) {
2456
- 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);
2457
2454
  };
2458
2455
  /**
2459
2456
  * Support function to help match credentials
@@ -2463,10 +2460,10 @@ var CacheManager = /** @class */ (function () {
2463
2460
  * @param clientId
2464
2461
  * @param realm
2465
2462
  * @param target
2466
- * @param oboAssertion
2463
+ * @param userAssertionHash
2467
2464
  * @param tokenType
2468
2465
  */
2469
- 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) {
2470
2467
  var _this = this;
2471
2468
  var allCacheKeys = this.getKeys();
2472
2469
  var matchingCredentials = {
@@ -2485,7 +2482,7 @@ var CacheManager = /** @class */ (function () {
2485
2482
  if (!entity) {
2486
2483
  return;
2487
2484
  }
2488
- if (!!oboAssertion && !_this.matchOboAssertion(entity, oboAssertion)) {
2485
+ if (!!userAssertionHash && !_this.matchUserAssertionHash(entity, userAssertionHash)) {
2489
2486
  return;
2490
2487
  }
2491
2488
  if (!!homeAccountId && !_this.matchHomeAccountId(entity, homeAccountId)) {
@@ -2816,7 +2813,7 @@ var CacheManager = /** @class */ (function () {
2816
2813
  target: scopes.printScopesLowerCase(),
2817
2814
  tokenType: authScheme,
2818
2815
  keyId: request.sshKid,
2819
- requestedClaimsHash: request.requestedClaimsHash
2816
+ requestedClaimsHash: request.requestedClaimsHash,
2820
2817
  };
2821
2818
  var credentialCache = this.getCredentialsFilteredBy(accessTokenFilter);
2822
2819
  var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
@@ -2842,7 +2839,7 @@ var CacheManager = /** @class */ (function () {
2842
2839
  environment: account.environment,
2843
2840
  credentialType: exports.CredentialType.REFRESH_TOKEN,
2844
2841
  clientId: clientId,
2845
- familyId: id
2842
+ familyId: id,
2846
2843
  };
2847
2844
  var credentialCache = this.getCredentialsFilteredBy(refreshTokenFilter);
2848
2845
  var refreshTokens = Object.keys(credentialCache.refreshTokens).map(function (key) { return credentialCache.refreshTokens[key]; });
@@ -2894,8 +2891,8 @@ var CacheManager = /** @class */ (function () {
2894
2891
  * @param value
2895
2892
  * @param oboAssertion
2896
2893
  */
2897
- CacheManager.prototype.matchOboAssertion = function (entity, oboAssertion) {
2898
- return !!(entity.oboAssertion && oboAssertion === entity.oboAssertion);
2894
+ CacheManager.prototype.matchUserAssertionHash = function (entity, userAssertionHash) {
2895
+ return !!(entity.userAssertionHash && userAssertionHash === entity.userAssertionHash);
2899
2896
  };
2900
2897
  /**
2901
2898
  * helper to match environment
@@ -3796,14 +3793,18 @@ var RequestParameterBuilder = /** @class */ (function () {
3796
3793
  * @param clientAssertion
3797
3794
  */
3798
3795
  RequestParameterBuilder.prototype.addClientAssertion = function (clientAssertion) {
3799
- this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION, encodeURIComponent(clientAssertion));
3796
+ if (!StringUtils.isEmpty(clientAssertion)) {
3797
+ this.parameters.set(AADServerParamKeys.CLIENT_ASSERTION, encodeURIComponent(clientAssertion));
3798
+ }
3800
3799
  };
3801
3800
  /**
3802
3801
  * add clientAssertionType for confidential client flows
3803
3802
  * @param clientAssertionType
3804
3803
  */
3805
3804
  RequestParameterBuilder.prototype.addClientAssertionType = function (clientAssertionType) {
3806
- 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
+ }
3807
3808
  };
3808
3809
  /**
3809
3810
  * add OBO assertion for confidential client flows
@@ -3969,7 +3970,7 @@ var IdTokenEntity = /** @class */ (function (_super) {
3969
3970
  * @param clientId
3970
3971
  * @param authority
3971
3972
  */
3972
- IdTokenEntity.createIdTokenEntity = function (homeAccountId, environment, idToken, clientId, tenantId, oboAssertion) {
3973
+ IdTokenEntity.createIdTokenEntity = function (homeAccountId, environment, idToken, clientId, tenantId) {
3973
3974
  var idTokenEntity = new IdTokenEntity();
3974
3975
  idTokenEntity.credentialType = exports.CredentialType.ID_TOKEN;
3975
3976
  idTokenEntity.homeAccountId = homeAccountId;
@@ -3977,7 +3978,6 @@ var IdTokenEntity = /** @class */ (function (_super) {
3977
3978
  idTokenEntity.clientId = clientId;
3978
3979
  idTokenEntity.secret = idToken;
3979
3980
  idTokenEntity.realm = tenantId;
3980
- idTokenEntity.oboAssertion = oboAssertion;
3981
3981
  return idTokenEntity;
3982
3982
  };
3983
3983
  /**
@@ -4092,7 +4092,7 @@ var AccessTokenEntity = /** @class */ (function (_super) {
4092
4092
  * @param expiresOn
4093
4093
  * @param extExpiresOn
4094
4094
  */
4095
- 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) {
4096
4096
  var _a, _b;
4097
4097
  var atEntity = new AccessTokenEntity();
4098
4098
  atEntity.homeAccountId = homeAccountId;
@@ -4113,7 +4113,7 @@ var AccessTokenEntity = /** @class */ (function (_super) {
4113
4113
  atEntity.clientId = clientId;
4114
4114
  atEntity.realm = tenantId;
4115
4115
  atEntity.target = scopes;
4116
- atEntity.oboAssertion = oboAssertion;
4116
+ atEntity.userAssertionHash = userAssertionHash;
4117
4117
  atEntity.tokenType = StringUtils.isEmpty(tokenType) ? exports.AuthenticationScheme.BEARER : tokenType;
4118
4118
  if (requestedClaims) {
4119
4119
  atEntity.requestedClaims = requestedClaims;
@@ -4195,14 +4195,14 @@ var RefreshTokenEntity = /** @class */ (function (_super) {
4195
4195
  * @param clientId
4196
4196
  * @param authority
4197
4197
  */
4198
- RefreshTokenEntity.createRefreshTokenEntity = function (homeAccountId, environment, refreshToken, clientId, familyId, oboAssertion) {
4198
+ RefreshTokenEntity.createRefreshTokenEntity = function (homeAccountId, environment, refreshToken, clientId, familyId, userAssertionHash) {
4199
4199
  var rtEntity = new RefreshTokenEntity();
4200
4200
  rtEntity.clientId = clientId;
4201
4201
  rtEntity.credentialType = exports.CredentialType.REFRESH_TOKEN;
4202
4202
  rtEntity.environment = environment;
4203
4203
  rtEntity.homeAccountId = homeAccountId;
4204
4204
  rtEntity.secret = refreshToken;
4205
- rtEntity.oboAssertion = oboAssertion;
4205
+ rtEntity.userAssertionHash = userAssertionHash;
4206
4206
  if (familyId)
4207
4207
  rtEntity.familyId = familyId;
4208
4208
  return rtEntity;
@@ -4831,7 +4831,7 @@ var ResponseHandler = /** @class */ (function () {
4831
4831
  * @param serverTokenResponse
4832
4832
  * @param authority
4833
4833
  */
4834
- ResponseHandler.prototype.handleServerTokenResponse = function (serverTokenResponse, authority, reqTimestamp, request, authCodePayload, oboAssertion, handlingRefreshTokenResponse) {
4834
+ ResponseHandler.prototype.handleServerTokenResponse = function (serverTokenResponse, authority, reqTimestamp, request, authCodePayload, userAssertionHash, handlingRefreshTokenResponse) {
4835
4835
  return __awaiter(this, void 0, void 0, function () {
4836
4836
  var idTokenObj, requestStateObj, cacheRecord, cacheContext, key, account;
4837
4837
  return __generator(this, function (_a) {
@@ -4853,7 +4853,7 @@ var ResponseHandler = /** @class */ (function () {
4853
4853
  }
4854
4854
  // Add keyId from request to serverTokenResponse if defined
4855
4855
  serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;
4856
- cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload);
4856
+ cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, request, idTokenObj, userAssertionHash, authCodePayload);
4857
4857
  _a.label = 1;
4858
4858
  case 1:
4859
4859
  _a.trys.push([1, , 5, 8]);
@@ -4901,7 +4901,7 @@ var ResponseHandler = /** @class */ (function () {
4901
4901
  * @param idTokenObj
4902
4902
  * @param authority
4903
4903
  */
4904
- ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload) {
4904
+ ResponseHandler.prototype.generateCacheRecord = function (serverTokenResponse, authority, reqTimestamp, request, idTokenObj, userAssertionHash, authCodePayload) {
4905
4905
  var env = authority.getPreferredCache();
4906
4906
  if (StringUtils.isEmpty(env)) {
4907
4907
  throw ClientAuthError.createInvalidCacheEnvironmentError();
@@ -4910,8 +4910,8 @@ var ResponseHandler = /** @class */ (function () {
4910
4910
  var cachedIdToken;
4911
4911
  var cachedAccount;
4912
4912
  if (!StringUtils.isEmpty(serverTokenResponse.id_token) && !!idTokenObj) {
4913
- cachedIdToken = IdTokenEntity.createIdTokenEntity(this.homeAccountIdentifier, env, serverTokenResponse.id_token || Constants.EMPTY_STRING, this.clientId, idTokenObj.claims.tid || Constants.EMPTY_STRING, oboAssertion);
4914
- 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);
4915
4915
  }
4916
4916
  // AccessToken
4917
4917
  var cachedAccessToken = null;
@@ -4929,12 +4929,12 @@ var ResponseHandler = /** @class */ (function () {
4929
4929
  var extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;
4930
4930
  var refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;
4931
4931
  // non AAD scenarios can have empty realm
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, 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);
4933
4933
  }
4934
4934
  // refreshToken
4935
4935
  var cachedRefreshToken = null;
4936
4936
  if (!StringUtils.isEmpty(serverTokenResponse.refresh_token)) {
4937
- 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);
4938
4938
  }
4939
4939
  // appMetadata
4940
4940
  var cachedAppMetadata = null;
@@ -4949,22 +4949,22 @@ var ResponseHandler = /** @class */ (function () {
4949
4949
  * @param idToken
4950
4950
  * @param authority
4951
4951
  */
4952
- ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, oboAssertion, authCodePayload) {
4952
+ ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, authCodePayload) {
4953
4953
  var authorityType = authority.authorityType;
4954
4954
  var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : Constants.EMPTY_STRING;
4955
4955
  var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : Constants.EMPTY_STRING;
4956
4956
  // ADFS does not require client_info in the response
4957
4957
  if (authorityType === exports.AuthorityType.Adfs) {
4958
4958
  this.logger.verbose("Authority type is ADFS, creating ADFS account");
4959
- return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);
4959
+ return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, cloudGraphHostName, msGraphhost);
4960
4960
  }
4961
4961
  // This fallback applies to B2C as well as they fall under an AAD account type.
4962
4962
  if (StringUtils.isEmpty(serverTokenResponse.client_info) && authority.protocolMode === "AAD") {
4963
4963
  throw ClientAuthError.createClientInfoEmptyError();
4964
4964
  }
4965
4965
  return serverTokenResponse.client_info ?
4966
- AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost) :
4967
- 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);
4968
4968
  };
4969
4969
  /**
4970
4970
  * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.
@@ -5242,8 +5242,8 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5242
5242
  if (this.config.clientCredentials.clientSecret) {
5243
5243
  parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
5244
5244
  }
5245
- clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;
5246
- if (clientAssertion) {
5245
+ if (this.config.clientCredentials.clientAssertion) {
5246
+ clientAssertion = this.config.clientCredentials.clientAssertion;
5247
5247
  parameterBuilder.addClientAssertion(clientAssertion.assertion);
5248
5248
  parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
5249
5249
  }
@@ -5846,8 +5846,8 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5846
5846
  if (this.config.clientCredentials.clientSecret) {
5847
5847
  parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
5848
5848
  }
5849
- clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;
5850
- if (clientAssertion) {
5849
+ if (this.config.clientCredentials.clientAssertion) {
5850
+ clientAssertion = this.config.clientCredentials.clientAssertion;
5851
5851
  parameterBuilder.addClientAssertion(clientAssertion.assertion);
5852
5852
  parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
5853
5853
  }
@@ -6078,44 +6078,64 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6078
6078
  */
6079
6079
  OnBehalfOfClient.prototype.acquireToken = function (request) {
6080
6080
  return __awaiter(this, void 0, void 0, function () {
6081
- var cachedAuthenticationResult;
6082
- return __generator(this, function (_a) {
6083
- switch (_a.label) {
6081
+ var _a;
6082
+ return __generator(this, function (_b) {
6083
+ switch (_b.label) {
6084
6084
  case 0:
6085
6085
  this.scopeSet = new ScopeSet(request.scopes || []);
6086
- if (!request.skipCache) return [3 /*break*/, 2];
6087
- return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
6088
- case 1: return [2 /*return*/, _a.sent()];
6089
- 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()];
6090
6095
  case 3:
6091
- cachedAuthenticationResult = _a.sent();
6092
- if (!cachedAuthenticationResult) return [3 /*break*/, 4];
6093
- return [2 /*return*/, cachedAuthenticationResult];
6094
- case 4: return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
6095
- 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*/];
6096
6106
  }
6097
6107
  });
6098
6108
  });
6099
6109
  };
6100
6110
  /**
6101
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
6102
6116
  * @param request
6103
6117
  */
6104
6118
  OnBehalfOfClient.prototype.getCachedAuthenticationResult = function (request) {
6105
- var _a;
6119
+ var _a, _b;
6106
6120
  return __awaiter(this, void 0, void 0, function () {
6107
6121
  var cachedAccessToken, cachedIdToken, idTokenObject, cachedAccount, localAccountId, accountInfo;
6108
- return __generator(this, function (_b) {
6109
- switch (_b.label) {
6122
+ return __generator(this, function (_c) {
6123
+ switch (_c.label) {
6110
6124
  case 0:
6111
- cachedAccessToken = this.readAccessTokenFromCache();
6112
- if (!cachedAccessToken ||
6113
- TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
6114
- // Update the server telemetry outcome
6115
- (_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(!cachedAccessToken ? CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED : CacheOutcome.NO_CACHED_ACCESS_TOKEN);
6116
- 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();
6117
6137
  }
6118
- cachedIdToken = this.readIdTokenFromCache(request);
6138
+ cachedIdToken = this.readIdTokenFromCacheForOBO(request, cachedAccessToken.homeAccountId);
6119
6139
  cachedAccount = null;
6120
6140
  if (cachedIdToken) {
6121
6141
  idTokenObject = new AuthToken(cachedIdToken.secret, this.config.cryptoInterface);
@@ -6127,7 +6147,11 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6127
6147
  username: Constants.EMPTY_STRING,
6128
6148
  localAccountId: localAccountId || Constants.EMPTY_STRING
6129
6149
  };
6130
- 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();
6131
6155
  }
6132
6156
  return [4 /*yield*/, ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
6133
6157
  account: cachedAccount,
@@ -6136,45 +6160,23 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6136
6160
  refreshToken: null,
6137
6161
  appMetadata: null
6138
6162
  }, true, request, idTokenObject)];
6139
- case 1: return [2 /*return*/, _b.sent()];
6163
+ case 1: return [2 /*return*/, _c.sent()];
6140
6164
  }
6141
6165
  });
6142
6166
  });
6143
6167
  };
6144
6168
  /**
6145
- * 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
6146
6171
  * @param request
6147
6172
  */
6148
- OnBehalfOfClient.prototype.readAccessTokenFromCache = function () {
6149
- var accessTokenFilter = {
6150
- environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
6151
- credentialType: exports.CredentialType.ACCESS_TOKEN,
6152
- clientId: this.config.authOptions.clientId,
6153
- realm: this.authority.tenant,
6154
- target: this.scopeSet.printScopesLowerCase(),
6155
- };
6156
- var credentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);
6157
- var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
6158
- var numAccessTokens = accessTokens.length;
6159
- if (numAccessTokens < 1) {
6160
- return null;
6161
- }
6162
- else if (numAccessTokens > 1) {
6163
- throw ClientAuthError.createMultipleMatchingTokensInCacheError();
6164
- }
6165
- return accessTokens[0];
6166
- };
6167
- /**
6168
- * read idtoken from cache TODO: CacheManager API should be used here instead
6169
- * @param request
6170
- */
6171
- OnBehalfOfClient.prototype.readIdTokenFromCache = function (request) {
6173
+ OnBehalfOfClient.prototype.readIdTokenFromCacheForOBO = function (request, atHomeAccountId) {
6172
6174
  var idTokenFilter = {
6175
+ homeAccountId: atHomeAccountId,
6173
6176
  environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
6174
6177
  credentialType: exports.CredentialType.ID_TOKEN,
6175
6178
  clientId: this.config.authOptions.clientId,
6176
- realm: this.authority.tenant,
6177
- oboAssertion: request.oboAssertion
6179
+ realm: this.authority.tenant
6178
6180
  };
6179
6181
  var credentialCache = this.cacheManager.getCredentialsFilteredBy(idTokenFilter);
6180
6182
  var idTokens = Object.keys(credentialCache.idTokens).map(function (key) { return credentialCache.idTokens[key]; });
@@ -6185,18 +6187,44 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6185
6187
  return idTokens[0];
6186
6188
  };
6187
6189
  /**
6188
- * read account from cache, TODO: CacheManager API should be used here instead
6189
- * @param account
6190
+ * Fetches the cached access token based on incoming assertion
6191
+ * @param clientId
6192
+ * @param request
6193
+ * @param userAssertionHash
6190
6194
  */
6191
- OnBehalfOfClient.prototype.readAccountFromCache = function (account) {
6192
- 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];
6193
6221
  };
6194
6222
  /**
6195
6223
  * Make a network call to the server requesting credentials
6196
6224
  * @param request
6197
6225
  * @param authority
6198
6226
  */
6199
- OnBehalfOfClient.prototype.executeTokenRequest = function (request, authority) {
6227
+ OnBehalfOfClient.prototype.executeTokenRequest = function (request, authority, userAssertionHash) {
6200
6228
  return __awaiter(this, void 0, void 0, function () {
6201
6229
  var requestBody, headers, thumbprint, reqTimestamp, response, responseHandler, tokenResponse;
6202
6230
  return __generator(this, function (_a) {
@@ -6221,7 +6249,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6221
6249
  response = _a.sent();
6222
6250
  responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
6223
6251
  responseHandler.validateTokenResponse(response.body);
6224
- 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)];
6225
6253
  case 2:
6226
6254
  tokenResponse = _a.sent();
6227
6255
  return [2 /*return*/, tokenResponse];
@@ -6252,9 +6280,8 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6252
6280
  if (this.config.clientCredentials.clientSecret) {
6253
6281
  parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
6254
6282
  }
6255
- // Use clientAssertion from request, fallback to client assertion in base configuration
6256
- var clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;
6257
- if (clientAssertion) {
6283
+ if (this.config.clientCredentials.clientAssertion) {
6284
+ var clientAssertion = this.config.clientCredentials.clientAssertion;
6258
6285
  parameterBuilder.addClientAssertion(clientAssertion.assertion);
6259
6286
  parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
6260
6287
  }
@@ -6468,9 +6495,8 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6468
6495
  if (this.config.clientCredentials.clientSecret) {
6469
6496
  parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
6470
6497
  }
6471
- // Use clientAssertion from request, fallback to client assertion in base configuration
6472
- var clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;
6473
- if (clientAssertion) {
6498
+ if (this.config.clientCredentials.clientAssertion) {
6499
+ var clientAssertion = this.config.clientCredentials.clientAssertion;
6474
6500
  parameterBuilder.addClientAssertion(clientAssertion.assertion);
6475
6501
  parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
6476
6502
  }