@azure/msal-common 14.15.0 → 14.16.1

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 (225) hide show
  1. package/dist/account/AccountInfo.d.ts +1 -0
  2. package/dist/account/AccountInfo.d.ts.map +1 -1
  3. package/dist/account/AccountInfo.mjs +1 -1
  4. package/dist/account/AccountInfo.mjs.map +1 -1
  5. package/dist/account/AuthToken.mjs +1 -1
  6. package/dist/account/CcsCredential.mjs +1 -1
  7. package/dist/account/ClientInfo.mjs +1 -1
  8. package/dist/account/TokenClaims.mjs +1 -1
  9. package/dist/authority/Authority.mjs +1 -1
  10. package/dist/authority/AuthorityFactory.mjs +1 -1
  11. package/dist/authority/AuthorityMetadata.mjs +1 -1
  12. package/dist/authority/AuthorityOptions.mjs +1 -1
  13. package/dist/authority/AuthorityType.mjs +1 -1
  14. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  15. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  16. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  17. package/dist/authority/ProtocolMode.mjs +1 -1
  18. package/dist/authority/RegionDiscovery.mjs +1 -1
  19. package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts +1 -0
  20. package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts.map +1 -1
  21. package/dist/cache/CacheManager.d.ts +34 -39
  22. package/dist/cache/CacheManager.d.ts.map +1 -1
  23. package/dist/cache/CacheManager.mjs +84 -102
  24. package/dist/cache/CacheManager.mjs.map +1 -1
  25. package/dist/cache/entities/AccountEntity.d.ts +1 -0
  26. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  27. package/dist/cache/entities/AccountEntity.mjs +1 -1
  28. package/dist/cache/entities/AccountEntity.mjs.map +1 -1
  29. package/dist/cache/entities/CredentialEntity.d.ts +2 -0
  30. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  31. package/dist/cache/interface/ICacheManager.d.ts +21 -21
  32. package/dist/cache/interface/ICacheManager.d.ts.map +1 -1
  33. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  34. package/dist/cache/utils/CacheHelpers.mjs +1 -1
  35. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  36. package/dist/client/AuthorizationCodeClient.mjs +24 -13
  37. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  38. package/dist/client/BaseClient.d.ts +10 -3
  39. package/dist/client/BaseClient.d.ts.map +1 -1
  40. package/dist/client/BaseClient.mjs +62 -10
  41. package/dist/client/BaseClient.mjs.map +1 -1
  42. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  43. package/dist/client/RefreshTokenClient.mjs +12 -6
  44. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  45. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  46. package/dist/client/SilentFlowClient.mjs +4 -4
  47. package/dist/client/SilentFlowClient.mjs.map +1 -1
  48. package/dist/config/ClientConfiguration.d.ts +2 -0
  49. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  50. package/dist/config/ClientConfiguration.mjs +1 -1
  51. package/dist/config/ClientConfiguration.mjs.map +1 -1
  52. package/dist/constants/AADServerParamKeys.d.ts +2 -0
  53. package/dist/constants/AADServerParamKeys.d.ts.map +1 -1
  54. package/dist/constants/AADServerParamKeys.mjs +5 -3
  55. package/dist/constants/AADServerParamKeys.mjs.map +1 -1
  56. package/dist/crypto/ICrypto.mjs +1 -1
  57. package/dist/crypto/JoseHeader.mjs +1 -1
  58. package/dist/crypto/PopTokenGenerator.mjs +1 -1
  59. package/dist/error/AuthError.mjs +1 -1
  60. package/dist/error/AuthErrorCodes.mjs +1 -1
  61. package/dist/error/CacheError.d.ts +6 -0
  62. package/dist/error/CacheError.d.ts.map +1 -1
  63. package/dist/error/CacheError.mjs +24 -6
  64. package/dist/error/CacheError.mjs.map +1 -1
  65. package/dist/error/CacheErrorCodes.d.ts +2 -2
  66. package/dist/error/CacheErrorCodes.d.ts.map +1 -1
  67. package/dist/error/CacheErrorCodes.mjs +4 -4
  68. package/dist/error/CacheErrorCodes.mjs.map +1 -1
  69. package/dist/error/ClientAuthError.mjs +1 -1
  70. package/dist/error/ClientAuthErrorCodes.mjs +1 -1
  71. package/dist/error/ClientConfigurationError.mjs +1 -1
  72. package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
  73. package/dist/error/InteractionRequiredAuthError.mjs +1 -1
  74. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +1 -1
  75. package/dist/error/JoseHeaderError.mjs +1 -1
  76. package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
  77. package/dist/error/NetworkError.d.ts +19 -0
  78. package/dist/error/NetworkError.d.ts.map +1 -0
  79. package/dist/error/NetworkError.mjs +34 -0
  80. package/dist/error/NetworkError.mjs.map +1 -0
  81. package/dist/error/ServerError.mjs +1 -1
  82. package/dist/exports-common.d.ts +3 -2
  83. package/dist/exports-common.d.ts.map +1 -1
  84. package/dist/index-browser.mjs +3 -3
  85. package/dist/index-node.mjs +3 -3
  86. package/dist/index.mjs +3 -3
  87. package/dist/logger/Logger.mjs +1 -1
  88. package/dist/network/INetworkModule.d.ts +1 -1
  89. package/dist/network/INetworkModule.d.ts.map +1 -1
  90. package/dist/network/INetworkModule.mjs +1 -1
  91. package/dist/network/NetworkResponse.d.ts +6 -0
  92. package/dist/network/NetworkResponse.d.ts.map +1 -0
  93. package/dist/network/ThrottlingUtils.d.ts +3 -3
  94. package/dist/network/ThrottlingUtils.d.ts.map +1 -1
  95. package/dist/network/ThrottlingUtils.mjs +6 -6
  96. package/dist/network/ThrottlingUtils.mjs.map +1 -1
  97. package/dist/packageMetadata.d.ts +1 -1
  98. package/dist/packageMetadata.mjs +2 -2
  99. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  100. package/dist/request/BaseAuthRequest.d.ts +2 -0
  101. package/dist/request/BaseAuthRequest.d.ts.map +1 -1
  102. package/dist/request/RequestParameterBuilder.d.ts +8 -1
  103. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  104. package/dist/request/RequestParameterBuilder.mjs +26 -3
  105. package/dist/request/RequestParameterBuilder.mjs.map +1 -1
  106. package/dist/request/RequestValidator.mjs +1 -1
  107. package/dist/request/ScopeSet.mjs +1 -1
  108. package/dist/response/ResponseHandler.d.ts +1 -1
  109. package/dist/response/ResponseHandler.d.ts.map +1 -1
  110. package/dist/response/ResponseHandler.mjs +6 -6
  111. package/dist/response/ResponseHandler.mjs.map +1 -1
  112. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  113. package/dist/telemetry/performance/PerformanceClient.mjs +29 -10
  114. package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
  115. package/dist/telemetry/performance/PerformanceEvent.d.ts +9 -0
  116. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  117. package/dist/telemetry/performance/PerformanceEvent.mjs +6 -1
  118. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  119. package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
  120. package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
  121. package/dist/telemetry/server/ServerTelemetryManager.mjs +7 -7
  122. package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
  123. package/dist/url/UrlString.mjs +1 -1
  124. package/dist/utils/ClientAssertionUtils.mjs +1 -1
  125. package/dist/utils/Constants.d.ts +1 -0
  126. package/dist/utils/Constants.d.ts.map +1 -1
  127. package/dist/utils/Constants.mjs +2 -1
  128. package/dist/utils/Constants.mjs.map +1 -1
  129. package/dist/utils/FunctionWrappers.mjs +1 -1
  130. package/dist/utils/ProtocolUtils.mjs +1 -1
  131. package/dist/utils/StringUtils.mjs +1 -1
  132. package/dist/utils/TimeUtils.mjs +1 -1
  133. package/dist/utils/UrlUtils.mjs +1 -1
  134. package/lib/index-browser.cjs +34 -13
  135. package/lib/index-browser.cjs.map +1 -1
  136. package/lib/{index-node-aee3f7b6.js → index-node-CebvEPer.js} +390 -298
  137. package/lib/index-node-CebvEPer.js.map +1 -0
  138. package/lib/index-node.cjs +6 -4
  139. package/lib/index-node.cjs.map +1 -1
  140. package/lib/index.cjs +6 -4
  141. package/lib/index.cjs.map +1 -1
  142. package/lib/types/account/AccountInfo.d.ts +1 -0
  143. package/lib/types/account/AccountInfo.d.ts.map +1 -1
  144. package/lib/types/broker/nativeBroker/INativeBrokerPlugin.d.ts +1 -0
  145. package/lib/types/broker/nativeBroker/INativeBrokerPlugin.d.ts.map +1 -1
  146. package/lib/types/cache/CacheManager.d.ts +34 -39
  147. package/lib/types/cache/CacheManager.d.ts.map +1 -1
  148. package/lib/types/cache/entities/AccountEntity.d.ts +1 -0
  149. package/lib/types/cache/entities/AccountEntity.d.ts.map +1 -1
  150. package/lib/types/cache/entities/CredentialEntity.d.ts +2 -0
  151. package/lib/types/cache/entities/CredentialEntity.d.ts.map +1 -1
  152. package/lib/types/cache/interface/ICacheManager.d.ts +21 -21
  153. package/lib/types/cache/interface/ICacheManager.d.ts.map +1 -1
  154. package/lib/types/client/AuthorizationCodeClient.d.ts.map +1 -1
  155. package/lib/types/client/BaseClient.d.ts +10 -3
  156. package/lib/types/client/BaseClient.d.ts.map +1 -1
  157. package/lib/types/client/RefreshTokenClient.d.ts.map +1 -1
  158. package/lib/types/client/SilentFlowClient.d.ts.map +1 -1
  159. package/lib/types/config/ClientConfiguration.d.ts +2 -0
  160. package/lib/types/config/ClientConfiguration.d.ts.map +1 -1
  161. package/lib/types/constants/AADServerParamKeys.d.ts +2 -0
  162. package/lib/types/constants/AADServerParamKeys.d.ts.map +1 -1
  163. package/lib/types/error/CacheError.d.ts +6 -0
  164. package/lib/types/error/CacheError.d.ts.map +1 -1
  165. package/lib/types/error/CacheErrorCodes.d.ts +2 -2
  166. package/lib/types/error/CacheErrorCodes.d.ts.map +1 -1
  167. package/lib/types/error/NetworkError.d.ts +19 -0
  168. package/lib/types/error/NetworkError.d.ts.map +1 -0
  169. package/lib/types/exports-common.d.ts +3 -2
  170. package/lib/types/exports-common.d.ts.map +1 -1
  171. package/lib/types/network/INetworkModule.d.ts +1 -1
  172. package/lib/types/network/INetworkModule.d.ts.map +1 -1
  173. package/lib/types/network/NetworkResponse.d.ts +6 -0
  174. package/lib/types/network/NetworkResponse.d.ts.map +1 -0
  175. package/lib/types/network/ThrottlingUtils.d.ts +3 -3
  176. package/lib/types/network/ThrottlingUtils.d.ts.map +1 -1
  177. package/lib/types/packageMetadata.d.ts +1 -1
  178. package/lib/types/request/BaseAuthRequest.d.ts +2 -0
  179. package/lib/types/request/BaseAuthRequest.d.ts.map +1 -1
  180. package/lib/types/request/RequestParameterBuilder.d.ts +8 -1
  181. package/lib/types/request/RequestParameterBuilder.d.ts.map +1 -1
  182. package/lib/types/response/ResponseHandler.d.ts +1 -1
  183. package/lib/types/response/ResponseHandler.d.ts.map +1 -1
  184. package/lib/types/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  185. package/lib/types/telemetry/performance/PerformanceEvent.d.ts +9 -0
  186. package/lib/types/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  187. package/lib/types/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
  188. package/lib/types/utils/Constants.d.ts +1 -0
  189. package/lib/types/utils/Constants.d.ts.map +1 -1
  190. package/package.json +2 -4
  191. package/src/account/AccountInfo.ts +1 -0
  192. package/src/authority/RegionDiscovery.ts +1 -1
  193. package/src/cache/CacheManager.ts +184 -131
  194. package/src/cache/entities/AccountEntity.ts +1 -0
  195. package/src/cache/entities/CredentialEntity.ts +2 -0
  196. package/src/cache/interface/ICacheManager.ts +45 -20
  197. package/src/client/AuthorizationCodeClient.ts +37 -16
  198. package/src/client/BaseClient.ts +113 -22
  199. package/src/client/RefreshTokenClient.ts +20 -8
  200. package/src/client/SilentFlowClient.ts +7 -5
  201. package/src/config/ClientConfiguration.ts +2 -0
  202. package/src/constants/AADServerParamKeys.ts +2 -0
  203. package/src/error/CacheError.ts +24 -4
  204. package/src/error/CacheErrorCodes.ts +2 -2
  205. package/src/error/NetworkError.ts +44 -0
  206. package/src/exports-common.ts +7 -6
  207. package/src/network/INetworkModule.ts +1 -1
  208. package/src/network/NetworkResponse.ts +10 -0
  209. package/src/network/ThrottlingUtils.ts +9 -6
  210. package/src/packageMetadata.ts +1 -1
  211. package/src/request/BaseAuthRequest.ts +2 -0
  212. package/src/request/RequestParameterBuilder.ts +51 -1
  213. package/src/response/ResponseHandler.ts +14 -4
  214. package/src/telemetry/performance/PerformanceClient.ts +42 -12
  215. package/src/telemetry/performance/PerformanceEvent.ts +15 -0
  216. package/src/telemetry/server/ServerTelemetryManager.ts +14 -6
  217. package/src/utils/Constants.ts +1 -0
  218. package/dist/network/NetworkManager.d.ts +0 -34
  219. package/dist/network/NetworkManager.d.ts.map +0 -1
  220. package/dist/network/NetworkManager.mjs +0 -44
  221. package/dist/network/NetworkManager.mjs.map +0 -1
  222. package/lib/index-node-aee3f7b6.js.map +0 -1
  223. package/lib/types/network/NetworkManager.d.ts +0 -34
  224. package/lib/types/network/NetworkManager.d.ts.map +0 -1
  225. package/src/network/NetworkManager.ts +0 -76
@@ -53,7 +53,8 @@ import { getAliasesFromStaticSources } from "../authority/AuthorityMetadata.js";
53
53
  import { StaticAuthorityOptions } from "../authority/AuthorityOptions.js";
54
54
  import { TokenClaims } from "../account/TokenClaims.js";
55
55
  import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient.js";
56
- import { CacheError, CacheErrorCodes } from "../error/CacheError.js";
56
+ import { createCacheError } from "../error/CacheError.js";
57
+ import { AuthError } from "../error/AuthError.js";
57
58
 
58
59
  /**
59
60
  * Interface class which implement cache storage functions used by MSAL to perform validity checks, and store tokens.
@@ -84,64 +85,85 @@ export abstract class CacheManager implements ICacheManager {
84
85
  */
85
86
  abstract getAccount(
86
87
  accountKey: string,
88
+ correlationId: string,
87
89
  logger?: Logger
88
90
  ): AccountEntity | null;
89
91
 
90
92
  /**
91
93
  * Returns deserialized account if found in the cache, otherwiser returns null
92
94
  */
93
- abstract getCachedAccountEntity(accountKey: string): AccountEntity | null;
95
+ abstract getCachedAccountEntity(
96
+ accountKey: string,
97
+ correlationId: string
98
+ ): AccountEntity | null;
94
99
 
95
100
  /**
96
101
  * set account entity in the platform cache
97
102
  * @param account
98
103
  */
99
- abstract setAccount(account: AccountEntity): void;
104
+ abstract setAccount(account: AccountEntity, correlationId: string): void;
100
105
 
101
106
  /**
102
107
  * remove account entity from the platform cache if it's outdated
103
108
  */
104
- abstract removeOutdatedAccount(accountKey: string): void;
109
+ abstract removeOutdatedAccount(
110
+ accountKey: string,
111
+ correlationId: string
112
+ ): void;
105
113
 
106
114
  /**
107
115
  * fetch the idToken entity from the platform cache
108
116
  * @param idTokenKey
109
117
  */
110
- abstract getIdTokenCredential(idTokenKey: string): IdTokenEntity | null;
118
+ abstract getIdTokenCredential(
119
+ idTokenKey: string,
120
+ correlationId: string
121
+ ): IdTokenEntity | null;
111
122
 
112
123
  /**
113
124
  * set idToken entity to the platform cache
114
125
  * @param idToken
115
126
  */
116
- abstract setIdTokenCredential(idToken: IdTokenEntity): void;
127
+ abstract setIdTokenCredential(
128
+ idToken: IdTokenEntity,
129
+ correlationId: string
130
+ ): void;
117
131
 
118
132
  /**
119
133
  * fetch the idToken entity from the platform cache
120
134
  * @param accessTokenKey
121
135
  */
122
136
  abstract getAccessTokenCredential(
123
- accessTokenKey: string
137
+ accessTokenKey: string,
138
+ correlationId: string
124
139
  ): AccessTokenEntity | null;
125
140
 
126
141
  /**
127
142
  * set idToken entity to the platform cache
128
143
  * @param accessToken
129
144
  */
130
- abstract setAccessTokenCredential(accessToken: AccessTokenEntity): void;
145
+ abstract setAccessTokenCredential(
146
+ accessToken: AccessTokenEntity,
147
+ correlationId: string
148
+ ): void;
131
149
 
132
150
  /**
133
151
  * fetch the idToken entity from the platform cache
134
152
  * @param refreshTokenKey
135
153
  */
136
154
  abstract getRefreshTokenCredential(
137
- refreshTokenKey: string
155
+ refreshTokenKey: string,
156
+ correlationId: string
138
157
  ): RefreshTokenEntity | null;
139
158
 
140
159
  /**
141
160
  * set idToken entity to the platform cache
142
161
  * @param refreshToken
143
162
  */
144
- abstract setRefreshTokenCredential(refreshToken: RefreshTokenEntity): void;
163
+ abstract setRefreshTokenCredential(
164
+ refreshToken: RefreshTokenEntity,
165
+ correlationId: string
166
+ ): void;
145
167
 
146
168
  /**
147
169
  * fetch appMetadata entity from the platform cache
@@ -153,7 +175,10 @@ export abstract class CacheManager implements ICacheManager {
153
175
  * set appMetadata entity to the platform cache
154
176
  * @param appMetadata
155
177
  */
156
- abstract setAppMetadata(appMetadata: AppMetadataEntity): void;
178
+ abstract setAppMetadata(
179
+ appMetadata: AppMetadataEntity,
180
+ correlationId: string
181
+ ): void;
157
182
 
158
183
  /**
159
184
  * fetch server telemetry entity from the platform cache
@@ -170,7 +195,8 @@ export abstract class CacheManager implements ICacheManager {
170
195
  */
171
196
  abstract setServerTelemetry(
172
197
  serverTelemetryKey: string,
173
- serverTelemetry: ServerTelemetryEntity
198
+ serverTelemetry: ServerTelemetryEntity,
199
+ correlationId: string
174
200
  ): void;
175
201
 
176
202
  /**
@@ -209,14 +235,15 @@ export abstract class CacheManager implements ICacheManager {
209
235
  */
210
236
  abstract setThrottlingCache(
211
237
  throttlingCacheKey: string,
212
- throttlingCache: ThrottlingEntity
238
+ throttlingCache: ThrottlingEntity,
239
+ correlationId: string
213
240
  ): void;
214
241
 
215
242
  /**
216
243
  * Function to remove an item from cache given its key.
217
244
  * @param key
218
245
  */
219
- abstract removeItem(key: string): void;
246
+ abstract removeItem(key: string, correlationId: string): void;
220
247
 
221
248
  /**
222
249
  * Function which retrieves all current keys from the cache.
@@ -233,17 +260,13 @@ export abstract class CacheManager implements ICacheManager {
233
260
  */
234
261
  abstract getTokenKeys(): TokenKeys;
235
262
 
236
- /**
237
- * Function which clears cache.
238
- */
239
- abstract clear(): Promise<void>;
240
-
241
263
  /**
242
264
  * Function which updates an outdated credential cache key
243
265
  */
244
266
  abstract updateCredentialCacheKey(
245
267
  currentCacheKey: string,
246
- credential: ValidCredentialType
268
+ credential: ValidCredentialType,
269
+ correlationId: string
247
270
  ): string;
248
271
 
249
272
  /**
@@ -251,9 +274,13 @@ export abstract class CacheManager implements ICacheManager {
251
274
  * @param accountFilter - (Optional) filter to narrow down the accounts returned
252
275
  * @returns Array of AccountInfo objects in cache
253
276
  */
254
- getAllAccounts(accountFilter?: AccountFilter): AccountInfo[] {
277
+ getAllAccounts(
278
+ correlationId: string,
279
+ accountFilter?: AccountFilter
280
+ ): AccountInfo[] {
255
281
  return this.buildTenantProfiles(
256
- this.getAccountsFilteredBy(accountFilter || {}),
282
+ this.getAccountsFilteredBy(accountFilter || {}, correlationId),
283
+ correlationId,
257
284
  accountFilter
258
285
  );
259
286
  }
@@ -261,8 +288,11 @@ export abstract class CacheManager implements ICacheManager {
261
288
  /**
262
289
  * Gets first tenanted AccountInfo object found based on provided filters
263
290
  */
264
- getAccountInfoFilteredBy(accountFilter: AccountFilter): AccountInfo | null {
265
- const allAccounts = this.getAllAccounts(accountFilter);
291
+ getAccountInfoFilteredBy(
292
+ accountFilter: AccountFilter,
293
+ correlationId: string
294
+ ): AccountInfo | null {
295
+ const allAccounts = this.getAllAccounts(correlationId, accountFilter);
266
296
  if (allAccounts.length > 1) {
267
297
  // If one or more accounts are found, prioritize accounts that have an ID token
268
298
  const sortedAccounts = allAccounts.sort((account) => {
@@ -282,8 +312,14 @@ export abstract class CacheManager implements ICacheManager {
282
312
  * @param accountFilter
283
313
  * @returns
284
314
  */
285
- getBaseAccountInfo(accountFilter: AccountFilter): AccountInfo | null {
286
- const accountEntities = this.getAccountsFilteredBy(accountFilter);
315
+ getBaseAccountInfo(
316
+ accountFilter: AccountFilter,
317
+ correlationId: string
318
+ ): AccountInfo | null {
319
+ const accountEntities = this.getAccountsFilteredBy(
320
+ accountFilter,
321
+ correlationId
322
+ );
287
323
  if (accountEntities.length > 0) {
288
324
  return accountEntities[0].getAccountInfo();
289
325
  } else {
@@ -300,11 +336,13 @@ export abstract class CacheManager implements ICacheManager {
300
336
  */
301
337
  private buildTenantProfiles(
302
338
  cachedAccounts: AccountEntity[],
339
+ correlationId: string,
303
340
  accountFilter?: AccountFilter
304
341
  ): AccountInfo[] {
305
342
  return cachedAccounts.flatMap((accountEntity) => {
306
343
  return this.getTenantProfilesFromAccountEntity(
307
344
  accountEntity,
345
+ correlationId,
308
346
  accountFilter?.tenantId,
309
347
  accountFilter
310
348
  );
@@ -315,6 +353,7 @@ export abstract class CacheManager implements ICacheManager {
315
353
  accountInfo: AccountInfo,
316
354
  tokenKeys: TokenKeys,
317
355
  tenantProfile: TenantProfile,
356
+ correlationId: string,
318
357
  tenantProfileFilter?: TenantProfileFilter
319
358
  ): AccountInfo | null {
320
359
  let tenantedAccountInfo: AccountInfo | null = null;
@@ -333,6 +372,7 @@ export abstract class CacheManager implements ICacheManager {
333
372
 
334
373
  const idToken = this.getIdToken(
335
374
  accountInfo,
375
+ correlationId,
336
376
  tokenKeys,
337
377
  tenantProfile.tenantId
338
378
  );
@@ -367,6 +407,7 @@ export abstract class CacheManager implements ICacheManager {
367
407
 
368
408
  private getTenantProfilesFromAccountEntity(
369
409
  accountEntity: AccountEntity,
410
+ correlationId: string,
370
411
  targetTenantId?: string,
371
412
  tenantProfileFilter?: TenantProfileFilter
372
413
  ): AccountInfo[] {
@@ -395,6 +436,7 @@ export abstract class CacheManager implements ICacheManager {
395
436
  accountInfo,
396
437
  tokenKeys,
397
438
  tenantProfile,
439
+ correlationId,
398
440
  tenantProfileFilter
399
441
  );
400
442
  if (tenantedAccountInfo) {
@@ -498,8 +540,8 @@ export abstract class CacheManager implements ICacheManager {
498
540
  */
499
541
  async saveCacheRecord(
500
542
  cacheRecord: CacheRecord,
501
- storeInCache?: StoreInCache,
502
- correlationId?: string
543
+ correlationId: string,
544
+ storeInCache?: StoreInCache
503
545
  ): Promise<void> {
504
546
  if (!cacheRecord) {
505
547
  throw createClientAuthError(
@@ -509,59 +551,42 @@ export abstract class CacheManager implements ICacheManager {
509
551
 
510
552
  try {
511
553
  if (!!cacheRecord.account) {
512
- this.setAccount(cacheRecord.account);
554
+ this.setAccount(cacheRecord.account, correlationId);
513
555
  }
514
556
 
515
557
  if (!!cacheRecord.idToken && storeInCache?.idToken !== false) {
516
- this.setIdTokenCredential(cacheRecord.idToken);
558
+ this.setIdTokenCredential(cacheRecord.idToken, correlationId);
517
559
  }
518
560
 
519
561
  if (
520
562
  !!cacheRecord.accessToken &&
521
563
  storeInCache?.accessToken !== false
522
564
  ) {
523
- await this.saveAccessToken(cacheRecord.accessToken);
565
+ await this.saveAccessToken(
566
+ cacheRecord.accessToken,
567
+ correlationId
568
+ );
524
569
  }
525
570
 
526
571
  if (
527
572
  !!cacheRecord.refreshToken &&
528
573
  storeInCache?.refreshToken !== false
529
574
  ) {
530
- this.setRefreshTokenCredential(cacheRecord.refreshToken);
575
+ this.setRefreshTokenCredential(
576
+ cacheRecord.refreshToken,
577
+ correlationId
578
+ );
531
579
  }
532
580
 
533
581
  if (!!cacheRecord.appMetadata) {
534
- this.setAppMetadata(cacheRecord.appMetadata);
582
+ this.setAppMetadata(cacheRecord.appMetadata, correlationId);
535
583
  }
536
584
  } catch (e: unknown) {
537
585
  this.commonLogger?.error(`CacheManager.saveCacheRecord: failed`);
538
- if (e instanceof Error) {
539
- this.commonLogger?.errorPii(
540
- `CacheManager.saveCacheRecord: ${e.message}`,
541
- correlationId
542
- );
543
-
544
- if (
545
- e.name === "QuotaExceededError" ||
546
- e.name === "NS_ERROR_DOM_QUOTA_REACHED" ||
547
- e.message.includes("exceeded the quota")
548
- ) {
549
- this.commonLogger?.error(
550
- `CacheManager.saveCacheRecord: exceeded storage quota`,
551
- correlationId
552
- );
553
- throw new CacheError(
554
- CacheErrorCodes.cacheQuotaExceededErrorCode
555
- );
556
- } else {
557
- throw new CacheError(e.name, e.message);
558
- }
586
+ if (e instanceof AuthError) {
587
+ throw e;
559
588
  } else {
560
- this.commonLogger?.errorPii(
561
- `CacheManager.saveCacheRecord: ${e}`,
562
- correlationId
563
- );
564
- throw new CacheError(CacheErrorCodes.cacheUnknownErrorCode);
589
+ throw createCacheError(e);
565
590
  }
566
591
  }
567
592
  }
@@ -571,7 +596,8 @@ export abstract class CacheManager implements ICacheManager {
571
596
  * @param credential
572
597
  */
573
598
  private async saveAccessToken(
574
- credential: AccessTokenEntity
599
+ credential: AccessTokenEntity,
600
+ correlationId: string
575
601
  ): Promise<void> {
576
602
  const accessTokenFilter: CredentialFilter = {
577
603
  clientId: credential.clientId,
@@ -586,7 +612,6 @@ export abstract class CacheManager implements ICacheManager {
586
612
  const tokenKeys = this.getTokenKeys();
587
613
  const currentScopes = ScopeSet.fromString(credential.target);
588
614
 
589
- const removedAccessTokens: Array<Promise<void>> = [];
590
615
  tokenKeys.accessToken.forEach((key) => {
591
616
  if (
592
617
  !this.accessTokenKeyMatchesFilter(key, accessTokenFilter, false)
@@ -594,7 +619,10 @@ export abstract class CacheManager implements ICacheManager {
594
619
  return;
595
620
  }
596
621
 
597
- const tokenEntity = this.getAccessTokenCredential(key);
622
+ const tokenEntity = this.getAccessTokenCredential(
623
+ key,
624
+ correlationId
625
+ );
598
626
 
599
627
  if (
600
628
  tokenEntity &&
@@ -602,12 +630,11 @@ export abstract class CacheManager implements ICacheManager {
602
630
  ) {
603
631
  const tokenScopeSet = ScopeSet.fromString(tokenEntity.target);
604
632
  if (tokenScopeSet.intersectingScopeSets(currentScopes)) {
605
- removedAccessTokens.push(this.removeAccessToken(key));
633
+ this.removeAccessToken(key, correlationId);
606
634
  }
607
635
  }
608
636
  });
609
- await Promise.all(removedAccessTokens);
610
- this.setAccessTokenCredential(credential);
637
+ this.setAccessTokenCredential(credential, correlationId);
611
638
  }
612
639
 
613
640
  /**
@@ -615,7 +642,10 @@ export abstract class CacheManager implements ICacheManager {
615
642
  * Not checking for casing as keys are all generated in lower case, remember to convert to lower case if object properties are compared
616
643
  * @param accountFilter - An object containing Account properties to filter by
617
644
  */
618
- getAccountsFilteredBy(accountFilter: AccountFilter): AccountEntity[] {
645
+ getAccountsFilteredBy(
646
+ accountFilter: AccountFilter,
647
+ correlationId: string
648
+ ): AccountEntity[] {
619
649
  const allAccountKeys = this.getAccountKeys();
620
650
  const matchingAccounts: AccountEntity[] = [];
621
651
  allAccountKeys.forEach((cacheKey) => {
@@ -626,6 +656,7 @@ export abstract class CacheManager implements ICacheManager {
626
656
 
627
657
  const entity: AccountEntity | null = this.getAccount(
628
658
  cacheKey,
659
+ correlationId,
629
660
  this.commonLogger
630
661
  );
631
662
 
@@ -957,12 +988,12 @@ export abstract class CacheManager implements ICacheManager {
957
988
  /**
958
989
  * Removes all accounts and related tokens from cache.
959
990
  */
960
- async removeAllAccounts(): Promise<void> {
991
+ async removeAllAccounts(correlationId: string): Promise<void> {
961
992
  const allAccountKeys = this.getAccountKeys();
962
993
  const removedAccounts: Array<Promise<void>> = [];
963
994
 
964
995
  allAccountKeys.forEach((cacheKey) => {
965
- removedAccounts.push(this.removeAccount(cacheKey));
996
+ removedAccounts.push(this.removeAccount(cacheKey, correlationId));
966
997
  });
967
998
 
968
999
  await Promise.all(removedAccounts);
@@ -972,43 +1003,56 @@ export abstract class CacheManager implements ICacheManager {
972
1003
  * Removes the account and related tokens for a given account key
973
1004
  * @param account
974
1005
  */
975
- async removeAccount(accountKey: string): Promise<void> {
976
- const account = this.getAccount(accountKey, this.commonLogger);
1006
+ async removeAccount(
1007
+ accountKey: string,
1008
+ correlationId: string
1009
+ ): Promise<void> {
1010
+ const account = this.getAccount(
1011
+ accountKey,
1012
+ correlationId,
1013
+ this.commonLogger
1014
+ );
977
1015
  if (!account) {
978
1016
  return;
979
1017
  }
980
- await this.removeAccountContext(account);
981
- this.removeItem(accountKey);
1018
+ await this.removeAccountContext(account, correlationId);
1019
+ this.removeItem(accountKey, correlationId);
982
1020
  }
983
1021
 
984
1022
  /**
985
1023
  * Removes credentials associated with the provided account
986
1024
  * @param account
987
1025
  */
988
- async removeAccountContext(account: AccountEntity): Promise<void> {
1026
+ async removeAccountContext(
1027
+ account: AccountEntity,
1028
+ correlationId: string
1029
+ ): Promise<void> {
989
1030
  const allTokenKeys = this.getTokenKeys();
990
1031
  const accountId = account.generateAccountId();
991
- const removedCredentials: Array<Promise<void>> = [];
992
1032
 
993
1033
  allTokenKeys.idToken.forEach((key) => {
994
1034
  if (key.indexOf(accountId) === 0) {
995
- this.removeIdToken(key);
1035
+ this.removeIdToken(key, correlationId);
996
1036
  }
997
1037
  });
998
1038
 
999
1039
  allTokenKeys.accessToken.forEach((key) => {
1000
1040
  if (key.indexOf(accountId) === 0) {
1001
- removedCredentials.push(this.removeAccessToken(key));
1041
+ this.removeAccessToken(key, correlationId);
1002
1042
  }
1003
1043
  });
1004
1044
 
1005
1045
  allTokenKeys.refreshToken.forEach((key) => {
1006
1046
  if (key.indexOf(accountId) === 0) {
1007
- this.removeRefreshToken(key);
1047
+ this.removeRefreshToken(key, correlationId);
1008
1048
  }
1009
1049
  });
1010
1050
 
1011
- await Promise.all(removedCredentials);
1051
+ this.getKeys().forEach((key) => {
1052
+ if (key.includes(accountId)) {
1053
+ this.removeItem(key, correlationId);
1054
+ }
1055
+ });
1012
1056
  }
1013
1057
 
1014
1058
  /**
@@ -1022,6 +1066,7 @@ export abstract class CacheManager implements ICacheManager {
1022
1066
  protected updateOutdatedCachedAccount(
1023
1067
  accountKey: string,
1024
1068
  accountEntity: AccountEntity | null,
1069
+ correlationId: string,
1025
1070
  logger?: Logger
1026
1071
  ): AccountEntity | null {
1027
1072
  // Only update if account entity is defined and has no tenantProfiles object (is outdated)
@@ -1040,7 +1085,7 @@ export abstract class CacheManager implements ICacheManager {
1040
1085
  // Get all account entities belonging to user
1041
1086
  const accountsToMerge: AccountEntity[] = [];
1042
1087
  matchingAccountKeys.forEach((key: string) => {
1043
- const account = this.getCachedAccountEntity(key);
1088
+ const account = this.getCachedAccountEntity(key, correlationId);
1044
1089
  if (account) {
1045
1090
  accountsToMerge.push(account);
1046
1091
  }
@@ -1079,12 +1124,12 @@ export abstract class CacheManager implements ICacheManager {
1079
1124
  // Clear cache of legacy account objects that have been collpsed into tenant profiles
1080
1125
  matchingAccountKeys.forEach((key: string) => {
1081
1126
  if (key !== newAccountKey) {
1082
- this.removeOutdatedAccount(accountKey);
1127
+ this.removeOutdatedAccount(accountKey, correlationId);
1083
1128
  }
1084
1129
  });
1085
1130
 
1086
1131
  // Cache updated account object
1087
- this.setAccount(updatedAccount);
1132
+ this.setAccount(updatedAccount, correlationId);
1088
1133
  logger?.verbose("Updated an outdated account entity in the cache");
1089
1134
  return updatedAccount;
1090
1135
  }
@@ -1097,45 +1142,37 @@ export abstract class CacheManager implements ICacheManager {
1097
1142
  * returns a boolean if the given credential is removed
1098
1143
  * @param credential
1099
1144
  */
1100
- async removeAccessToken(key: string): Promise<void> {
1101
- const credential = this.getAccessTokenCredential(key);
1102
- if (!credential) {
1103
- return;
1104
- }
1145
+ removeAccessToken(key: string, correlationId: string): void {
1146
+ const credential = this.getAccessTokenCredential(key, correlationId);
1147
+ this.removeItem(key, correlationId);
1105
1148
 
1106
- // Remove Token Binding Key from key store for PoP Tokens Credentials
1107
1149
  if (
1108
- credential.credentialType.toLowerCase() ===
1109
- CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()
1150
+ !credential ||
1151
+ credential.credentialType.toLowerCase() !==
1152
+ CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase() ||
1153
+ credential.tokenType !== AuthenticationScheme.POP
1110
1154
  ) {
1111
- if (credential.tokenType === AuthenticationScheme.POP) {
1112
- const accessTokenWithAuthSchemeEntity =
1113
- credential as AccessTokenEntity;
1114
- const kid = accessTokenWithAuthSchemeEntity.keyId;
1115
-
1116
- if (kid) {
1117
- try {
1118
- await this.cryptoImpl.removeTokenBindingKey(kid);
1119
- } catch (error) {
1120
- throw createClientAuthError(
1121
- ClientAuthErrorCodes.bindingKeyNotRemoved
1122
- );
1123
- }
1124
- }
1125
- }
1155
+ return;
1126
1156
  }
1127
1157
 
1128
- return this.removeItem(key);
1158
+ // Remove Token Binding Key from key store for PoP Tokens Credentials
1159
+ const kid = credential.keyId;
1160
+
1161
+ if (kid) {
1162
+ void this.cryptoImpl.removeTokenBindingKey(kid).catch(() => {
1163
+ this.commonLogger.error("Binding key could not be removed");
1164
+ });
1165
+ }
1129
1166
  }
1130
1167
 
1131
1168
  /**
1132
1169
  * Removes all app metadata objects from cache.
1133
1170
  */
1134
- removeAppMetadata(): boolean {
1171
+ removeAppMetadata(correlationId: string): boolean {
1135
1172
  const allCacheKeys = this.getKeys();
1136
1173
  allCacheKeys.forEach((cacheKey) => {
1137
1174
  if (this.isAppMetadata(cacheKey)) {
1138
- this.removeItem(cacheKey);
1175
+ this.removeItem(cacheKey, correlationId);
1139
1176
  }
1140
1177
  });
1141
1178
 
@@ -1146,10 +1183,13 @@ export abstract class CacheManager implements ICacheManager {
1146
1183
  * Retrieve AccountEntity from cache
1147
1184
  * @param account
1148
1185
  */
1149
- readAccountFromCache(account: AccountInfo): AccountEntity | null {
1186
+ readAccountFromCache(
1187
+ account: AccountInfo,
1188
+ correlationId: string
1189
+ ): AccountEntity | null {
1150
1190
  const accountKey: string =
1151
1191
  AccountEntity.generateAccountCacheKey(account);
1152
- return this.getAccount(accountKey, this.commonLogger);
1192
+ return this.getAccount(accountKey, correlationId, this.commonLogger);
1153
1193
  }
1154
1194
 
1155
1195
  /**
@@ -1162,10 +1202,10 @@ export abstract class CacheManager implements ICacheManager {
1162
1202
  */
1163
1203
  getIdToken(
1164
1204
  account: AccountInfo,
1205
+ correlationId: string,
1165
1206
  tokenKeys?: TokenKeys,
1166
1207
  targetRealm?: string,
1167
- performanceClient?: IPerformanceClient,
1168
- correlationId?: string
1208
+ performanceClient?: IPerformanceClient
1169
1209
  ): IdTokenEntity | null {
1170
1210
  this.commonLogger.trace("CacheManager - getIdToken called");
1171
1211
  const idTokenFilter: CredentialFilter = {
@@ -1178,6 +1218,7 @@ export abstract class CacheManager implements ICacheManager {
1178
1218
 
1179
1219
  const idTokenMap: Map<string, IdTokenEntity> = this.getIdTokensByFilter(
1180
1220
  idTokenFilter,
1221
+ correlationId,
1181
1222
  tokenKeys
1182
1223
  );
1183
1224
 
@@ -1220,7 +1261,7 @@ export abstract class CacheManager implements ICacheManager {
1220
1261
  "CacheManager:getIdToken - Multiple matching ID tokens found, clearing them"
1221
1262
  );
1222
1263
  tokensToBeRemoved.forEach((idToken, key) => {
1223
- this.removeIdToken(key);
1264
+ this.removeIdToken(key, correlationId);
1224
1265
  });
1225
1266
  if (performanceClient && correlationId) {
1226
1267
  performanceClient.addFields(
@@ -1242,6 +1283,7 @@ export abstract class CacheManager implements ICacheManager {
1242
1283
  */
1243
1284
  getIdTokensByFilter(
1244
1285
  filter: CredentialFilter,
1286
+ correlationId: string,
1245
1287
  tokenKeys?: TokenKeys
1246
1288
  ): Map<string, IdTokenEntity> {
1247
1289
  const idTokenKeys =
@@ -1260,7 +1302,7 @@ export abstract class CacheManager implements ICacheManager {
1260
1302
  ) {
1261
1303
  return;
1262
1304
  }
1263
- const idToken = this.getIdTokenCredential(key);
1305
+ const idToken = this.getIdTokenCredential(key, correlationId);
1264
1306
  if (idToken && this.credentialMatchesFilter(idToken, filter)) {
1265
1307
  idTokens.set(key, idToken);
1266
1308
  }
@@ -1301,16 +1343,16 @@ export abstract class CacheManager implements ICacheManager {
1301
1343
  * Removes idToken from the cache
1302
1344
  * @param key
1303
1345
  */
1304
- removeIdToken(key: string): void {
1305
- this.removeItem(key);
1346
+ removeIdToken(key: string, correlationId: string): void {
1347
+ this.removeItem(key, correlationId);
1306
1348
  }
1307
1349
 
1308
1350
  /**
1309
1351
  * Removes refresh token from the cache
1310
1352
  * @param key
1311
1353
  */
1312
- removeRefreshToken(key: string): void {
1313
- this.removeItem(key);
1354
+ removeRefreshToken(key: string, correlationId: string): void {
1355
+ this.removeItem(key, correlationId);
1314
1356
  }
1315
1357
 
1316
1358
  /**
@@ -1326,8 +1368,7 @@ export abstract class CacheManager implements ICacheManager {
1326
1368
  request: BaseAuthRequest,
1327
1369
  tokenKeys?: TokenKeys,
1328
1370
  targetRealm?: string,
1329
- performanceClient?: IPerformanceClient,
1330
- correlationId?: string
1371
+ performanceClient?: IPerformanceClient
1331
1372
  ): AccessTokenEntity | null {
1332
1373
  this.commonLogger.trace("CacheManager - getAccessToken called");
1333
1374
  const scopes = ScopeSet.createSearchScopes(request.scopes);
@@ -1366,7 +1407,10 @@ export abstract class CacheManager implements ICacheManager {
1366
1407
  if (
1367
1408
  this.accessTokenKeyMatchesFilter(key, accessTokenFilter, true)
1368
1409
  ) {
1369
- const accessToken = this.getAccessTokenCredential(key);
1410
+ const accessToken = this.getAccessTokenCredential(
1411
+ key,
1412
+ request.correlationId
1413
+ );
1370
1414
 
1371
1415
  // Validate value
1372
1416
  if (
@@ -1389,12 +1433,15 @@ export abstract class CacheManager implements ICacheManager {
1389
1433
  "CacheManager:getAccessToken - Multiple access tokens found, clearing them"
1390
1434
  );
1391
1435
  accessTokens.forEach((accessToken) => {
1392
- void this.removeAccessToken(generateCredentialKey(accessToken));
1436
+ void this.removeAccessToken(
1437
+ generateCredentialKey(accessToken),
1438
+ request.correlationId
1439
+ );
1393
1440
  });
1394
- if (performanceClient && correlationId) {
1441
+ if (performanceClient && request.correlationId) {
1395
1442
  performanceClient.addFields(
1396
1443
  { multiMatchedAT: accessTokens.length },
1397
- correlationId
1444
+ request.correlationId
1398
1445
  );
1399
1446
  }
1400
1447
  return null;
@@ -1471,7 +1518,10 @@ export abstract class CacheManager implements ICacheManager {
1471
1518
  * @param filter
1472
1519
  * @returns
1473
1520
  */
1474
- getAccessTokensByFilter(filter: CredentialFilter): AccessTokenEntity[] {
1521
+ getAccessTokensByFilter(
1522
+ filter: CredentialFilter,
1523
+ correlationId: string
1524
+ ): AccessTokenEntity[] {
1475
1525
  const tokenKeys = this.getTokenKeys();
1476
1526
 
1477
1527
  const accessTokens: AccessTokenEntity[] = [];
@@ -1480,7 +1530,10 @@ export abstract class CacheManager implements ICacheManager {
1480
1530
  return;
1481
1531
  }
1482
1532
 
1483
- const accessToken = this.getAccessTokenCredential(key);
1533
+ const accessToken = this.getAccessTokenCredential(
1534
+ key,
1535
+ correlationId
1536
+ );
1484
1537
  if (
1485
1538
  accessToken &&
1486
1539
  this.credentialMatchesFilter(accessToken, filter)
@@ -1503,9 +1556,9 @@ export abstract class CacheManager implements ICacheManager {
1503
1556
  getRefreshToken(
1504
1557
  account: AccountInfo,
1505
1558
  familyRT: boolean,
1559
+ correlationId: string,
1506
1560
  tokenKeys?: TokenKeys,
1507
- performanceClient?: IPerformanceClient,
1508
- correlationId?: string
1561
+ performanceClient?: IPerformanceClient
1509
1562
  ): RefreshTokenEntity | null {
1510
1563
  this.commonLogger.trace("CacheManager - getRefreshToken called");
1511
1564
  const id = familyRT ? THE_FAMILY_ID : undefined;
@@ -1525,7 +1578,10 @@ export abstract class CacheManager implements ICacheManager {
1525
1578
  refreshTokenKeys.forEach((key) => {
1526
1579
  // Validate key
1527
1580
  if (this.refreshTokenKeyMatchesFilter(key, refreshTokenFilter)) {
1528
- const refreshToken = this.getRefreshTokenCredential(key);
1581
+ const refreshToken = this.getRefreshTokenCredential(
1582
+ key,
1583
+ correlationId
1584
+ );
1529
1585
  // Validate value
1530
1586
  if (
1531
1587
  refreshToken &&
@@ -2005,9 +2061,6 @@ export class DefaultStorageClass extends CacheManager {
2005
2061
  getTokenKeys(): TokenKeys {
2006
2062
  throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
2007
2063
  }
2008
- async clear(): Promise<void> {
2009
- throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
2010
- }
2011
2064
  updateCredentialCacheKey(): string {
2012
2065
  throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
2013
2066
  }