@azure/msal-node 2.12.0 → 2.13.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 (159) hide show
  1. package/dist/cache/ITokenCache.d.ts +15 -15
  2. package/dist/cache/NodeStorage.cjs +423 -423
  3. package/dist/cache/NodeStorage.d.ts +193 -193
  4. package/dist/cache/NodeStorage.mjs +423 -423
  5. package/dist/cache/TokenCache.cjs +265 -265
  6. package/dist/cache/TokenCache.d.ts +90 -90
  7. package/dist/cache/TokenCache.mjs +265 -265
  8. package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
  9. package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
  10. package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
  11. package/dist/cache/distributed/ICacheClient.d.ts +17 -17
  12. package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
  13. package/dist/cache/serializer/Deserializer.cjs +167 -167
  14. package/dist/cache/serializer/Deserializer.d.ts +42 -42
  15. package/dist/cache/serializer/Deserializer.mjs +167 -167
  16. package/dist/cache/serializer/Serializer.cjs +137 -137
  17. package/dist/cache/serializer/Serializer.d.ts +39 -39
  18. package/dist/cache/serializer/Serializer.mjs +137 -137
  19. package/dist/cache/serializer/SerializerTypes.d.ts +102 -102
  20. package/dist/client/ClientApplication.cjs +334 -334
  21. package/dist/client/ClientApplication.d.ts +143 -143
  22. package/dist/client/ClientApplication.mjs +334 -334
  23. package/dist/client/ClientAssertion.cjs +143 -143
  24. package/dist/client/ClientAssertion.d.ts +55 -55
  25. package/dist/client/ClientAssertion.mjs +143 -143
  26. package/dist/client/ClientCredentialClient.cjs +194 -194
  27. package/dist/client/ClientCredentialClient.d.ts +33 -33
  28. package/dist/client/ClientCredentialClient.mjs +194 -194
  29. package/dist/client/ConfidentialClientApplication.cjs +169 -169
  30. package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
  31. package/dist/client/ConfidentialClientApplication.d.ts +58 -58
  32. package/dist/client/ConfidentialClientApplication.mjs +169 -169
  33. package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
  34. package/dist/client/DeviceCodeClient.cjs +207 -207
  35. package/dist/client/DeviceCodeClient.d.ts +53 -53
  36. package/dist/client/DeviceCodeClient.mjs +207 -207
  37. package/dist/client/IConfidentialClientApplication.d.ts +39 -39
  38. package/dist/client/IPublicClientApplication.d.ts +42 -42
  39. package/dist/client/ManagedIdentityApplication.cjs +84 -84
  40. package/dist/client/ManagedIdentityApplication.d.ts +30 -30
  41. package/dist/client/ManagedIdentityApplication.mjs +84 -84
  42. package/dist/client/ManagedIdentityClient.cjs +60 -60
  43. package/dist/client/ManagedIdentityClient.d.ts +27 -27
  44. package/dist/client/ManagedIdentityClient.mjs +60 -60
  45. package/dist/client/ManagedIdentitySources/AppService.cjs +45 -45
  46. package/dist/client/ManagedIdentitySources/AppService.d.ts +17 -17
  47. package/dist/client/ManagedIdentitySources/AppService.mjs +45 -45
  48. package/dist/client/ManagedIdentitySources/AzureArc.cjs +155 -120
  49. package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +1 -1
  50. package/dist/client/ManagedIdentitySources/AzureArc.d.ts +27 -23
  51. package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
  52. package/dist/client/ManagedIdentitySources/AzureArc.mjs +155 -122
  53. package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
  54. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +122 -122
  55. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -1
  56. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +30 -30
  57. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +122 -122
  58. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
  59. package/dist/client/ManagedIdentitySources/CloudShell.cjs +38 -38
  60. package/dist/client/ManagedIdentitySources/CloudShell.d.ts +16 -16
  61. package/dist/client/ManagedIdentitySources/CloudShell.mjs +38 -38
  62. package/dist/client/ManagedIdentitySources/Imds.cjs +43 -43
  63. package/dist/client/ManagedIdentitySources/Imds.d.ts +12 -12
  64. package/dist/client/ManagedIdentitySources/Imds.mjs +43 -43
  65. package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +54 -54
  66. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +17 -17
  67. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +54 -54
  68. package/dist/client/OnBehalfOfClient.cjs +202 -202
  69. package/dist/client/OnBehalfOfClient.d.ts +47 -47
  70. package/dist/client/OnBehalfOfClient.mjs +202 -202
  71. package/dist/client/PublicClientApplication.cjs +237 -237
  72. package/dist/client/PublicClientApplication.d.ts +72 -72
  73. package/dist/client/PublicClientApplication.mjs +237 -237
  74. package/dist/client/UsernamePasswordClient.cjs +95 -95
  75. package/dist/client/UsernamePasswordClient.d.ts +25 -25
  76. package/dist/client/UsernamePasswordClient.mjs +95 -95
  77. package/dist/config/Configuration.cjs +106 -106
  78. package/dist/config/Configuration.d.ts +131 -131
  79. package/dist/config/Configuration.mjs +106 -106
  80. package/dist/config/ManagedIdentityId.cjs +48 -48
  81. package/dist/config/ManagedIdentityId.d.ts +11 -11
  82. package/dist/config/ManagedIdentityId.mjs +48 -48
  83. package/dist/config/ManagedIdentityRequestParameters.cjs +28 -28
  84. package/dist/config/ManagedIdentityRequestParameters.d.ts +11 -11
  85. package/dist/config/ManagedIdentityRequestParameters.mjs +28 -28
  86. package/dist/crypto/CryptoProvider.cjs +89 -89
  87. package/dist/crypto/CryptoProvider.d.ts +62 -62
  88. package/dist/crypto/CryptoProvider.mjs +89 -89
  89. package/dist/crypto/GuidGenerator.cjs +22 -22
  90. package/dist/crypto/GuidGenerator.d.ts +14 -14
  91. package/dist/crypto/GuidGenerator.mjs +22 -22
  92. package/dist/crypto/HashUtils.cjs +13 -13
  93. package/dist/crypto/HashUtils.d.ts +8 -8
  94. package/dist/crypto/HashUtils.mjs +13 -13
  95. package/dist/crypto/PkceGenerator.cjs +49 -49
  96. package/dist/crypto/PkceGenerator.d.ts +22 -22
  97. package/dist/crypto/PkceGenerator.mjs +49 -49
  98. package/dist/error/ManagedIdentityError.cjs +41 -41
  99. package/dist/error/ManagedIdentityError.d.ts +30 -30
  100. package/dist/error/ManagedIdentityError.mjs +41 -41
  101. package/dist/error/ManagedIdentityErrorCodes.cjs +24 -24
  102. package/dist/error/ManagedIdentityErrorCodes.d.ts +22 -22
  103. package/dist/error/ManagedIdentityErrorCodes.mjs +24 -24
  104. package/dist/error/NodeAuthError.cjs +95 -95
  105. package/dist/error/NodeAuthError.d.ts +73 -73
  106. package/dist/error/NodeAuthError.mjs +95 -95
  107. package/dist/index.cjs +1 -1
  108. package/dist/index.d.ts +45 -45
  109. package/dist/index.mjs +1 -1
  110. package/dist/internals.cjs +8 -8
  111. package/dist/internals.d.ts +6 -6
  112. package/dist/internals.mjs +8 -8
  113. package/dist/network/HttpClient.cjs +281 -281
  114. package/dist/network/HttpClient.d.ts +25 -25
  115. package/dist/network/HttpClient.mjs +281 -281
  116. package/dist/network/HttpClientWithRetries.cjs +34 -34
  117. package/dist/network/HttpClientWithRetries.d.ts +11 -11
  118. package/dist/network/HttpClientWithRetries.mjs +34 -34
  119. package/dist/network/ILoopbackClient.d.ts +10 -10
  120. package/dist/network/LoopbackClient.cjs +81 -77
  121. package/dist/network/LoopbackClient.cjs.map +1 -1
  122. package/dist/network/LoopbackClient.d.ts +21 -21
  123. package/dist/network/LoopbackClient.d.ts.map +1 -1
  124. package/dist/network/LoopbackClient.mjs +81 -77
  125. package/dist/network/LoopbackClient.mjs.map +1 -1
  126. package/dist/packageMetadata.cjs +4 -4
  127. package/dist/packageMetadata.d.ts +2 -2
  128. package/dist/packageMetadata.mjs +4 -4
  129. package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
  130. package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
  131. package/dist/request/ClientCredentialRequest.d.ts +14 -14
  132. package/dist/request/DeviceCodeRequest.d.ts +15 -15
  133. package/dist/request/InteractiveRequest.d.ts +22 -22
  134. package/dist/request/ManagedIdentityRequest.d.ts +8 -8
  135. package/dist/request/ManagedIdentityRequestParams.d.ts +9 -9
  136. package/dist/request/OnBehalfOfRequest.d.ts +14 -14
  137. package/dist/request/RefreshTokenRequest.d.ts +17 -17
  138. package/dist/request/SignOutRequest.d.ts +5 -5
  139. package/dist/request/SilentFlowRequest.d.ts +16 -16
  140. package/dist/request/UsernamePasswordRequest.d.ts +19 -19
  141. package/dist/response/ManagedIdentityTokenResponse.d.ts +34 -34
  142. package/dist/retry/IHttpRetryPolicy.d.ts +5 -5
  143. package/dist/retry/LinearRetryPolicy.cjs +40 -40
  144. package/dist/retry/LinearRetryPolicy.d.ts +11 -11
  145. package/dist/retry/LinearRetryPolicy.mjs +40 -40
  146. package/dist/utils/Constants.cjs +136 -136
  147. package/dist/utils/Constants.d.ts +141 -141
  148. package/dist/utils/Constants.mjs +136 -136
  149. package/dist/utils/EncodingUtils.cjs +44 -44
  150. package/dist/utils/EncodingUtils.d.ts +26 -26
  151. package/dist/utils/EncodingUtils.mjs +44 -44
  152. package/dist/utils/NetworkUtils.cjs +38 -38
  153. package/dist/utils/NetworkUtils.d.ts +5 -5
  154. package/dist/utils/NetworkUtils.mjs +38 -38
  155. package/package.json +2 -2
  156. package/src/client/ConfidentialClientApplication.ts +3 -3
  157. package/src/client/ManagedIdentitySources/AzureArc.ts +80 -25
  158. package/src/network/LoopbackClient.ts +7 -1
  159. package/src/packageMetadata.ts +1 -1
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-node v2.12.0 2024-07-23 */
1
+ /*! @azure/msal-node v2.13.1 2024-08-29 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -6,428 +6,428 @@ var msalCommon = require('@azure/msal-common');
6
6
  var Deserializer = require('./serializer/Deserializer.cjs');
7
7
  var Serializer = require('./serializer/Serializer.cjs');
8
8
 
9
- /*
10
- * Copyright (c) Microsoft Corporation. All rights reserved.
11
- * Licensed under the MIT License.
12
- */
13
- /**
14
- * This class implements Storage for node, reading cache from user specified storage location or an extension library
15
- * @public
16
- */
17
- class NodeStorage extends msalCommon.CacheManager {
18
- constructor(logger, clientId, cryptoImpl, staticAuthorityOptions) {
19
- super(clientId, cryptoImpl, logger, staticAuthorityOptions);
20
- this.cache = {};
21
- this.changeEmitters = [];
22
- this.logger = logger;
23
- }
24
- /**
25
- * Queue up callbacks
26
- * @param func - a callback function for cache change indication
27
- */
28
- registerChangeEmitter(func) {
29
- this.changeEmitters.push(func);
30
- }
31
- /**
32
- * Invoke the callback when cache changes
33
- */
34
- emitChange() {
35
- this.changeEmitters.forEach((func) => func.call(null));
36
- }
37
- /**
38
- * Converts cacheKVStore to InMemoryCache
39
- * @param cache - key value store
40
- */
41
- cacheToInMemoryCache(cache) {
42
- const inMemoryCache = {
43
- accounts: {},
44
- idTokens: {},
45
- accessTokens: {},
46
- refreshTokens: {},
47
- appMetadata: {},
48
- };
49
- for (const key in cache) {
50
- const value = cache[key];
51
- if (typeof value !== "object") {
52
- continue;
53
- }
54
- if (value instanceof msalCommon.AccountEntity) {
55
- inMemoryCache.accounts[key] = value;
56
- }
57
- else if (msalCommon.CacheHelpers.isIdTokenEntity(value)) {
58
- inMemoryCache.idTokens[key] = value;
59
- }
60
- else if (msalCommon.CacheHelpers.isAccessTokenEntity(value)) {
61
- inMemoryCache.accessTokens[key] = value;
62
- }
63
- else if (msalCommon.CacheHelpers.isRefreshTokenEntity(value)) {
64
- inMemoryCache.refreshTokens[key] = value;
65
- }
66
- else if (msalCommon.CacheHelpers.isAppMetadataEntity(key, value)) {
67
- inMemoryCache.appMetadata[key] = value;
68
- }
69
- else {
70
- continue;
71
- }
72
- }
73
- return inMemoryCache;
74
- }
75
- /**
76
- * converts inMemoryCache to CacheKVStore
77
- * @param inMemoryCache - kvstore map for inmemory
78
- */
79
- inMemoryCacheToCache(inMemoryCache) {
80
- // convert in memory cache to a flat Key-Value map
81
- let cache = this.getCache();
82
- cache = {
83
- ...cache,
84
- ...inMemoryCache.accounts,
85
- ...inMemoryCache.idTokens,
86
- ...inMemoryCache.accessTokens,
87
- ...inMemoryCache.refreshTokens,
88
- ...inMemoryCache.appMetadata,
89
- };
90
- // convert in memory cache to a flat Key-Value map
91
- return cache;
92
- }
93
- /**
94
- * gets the current in memory cache for the client
95
- */
96
- getInMemoryCache() {
97
- this.logger.trace("Getting in-memory cache");
98
- // convert the cache key value store to inMemoryCache
99
- const inMemoryCache = this.cacheToInMemoryCache(this.getCache());
100
- return inMemoryCache;
101
- }
102
- /**
103
- * sets the current in memory cache for the client
104
- * @param inMemoryCache - key value map in memory
105
- */
106
- setInMemoryCache(inMemoryCache) {
107
- this.logger.trace("Setting in-memory cache");
108
- // convert and append the inMemoryCache to cacheKVStore
109
- const cache = this.inMemoryCacheToCache(inMemoryCache);
110
- this.setCache(cache);
111
- this.emitChange();
112
- }
113
- /**
114
- * get the current cache key-value store
115
- */
116
- getCache() {
117
- this.logger.trace("Getting cache key-value store");
118
- return this.cache;
119
- }
120
- /**
121
- * sets the current cache (key value store)
122
- * @param cacheMap - key value map
123
- */
124
- setCache(cache) {
125
- this.logger.trace("Setting cache key value store");
126
- this.cache = cache;
127
- // mark change in cache
128
- this.emitChange();
129
- }
130
- /**
131
- * Gets cache item with given key.
132
- * @param key - lookup key for the cache entry
133
- */
134
- getItem(key) {
135
- this.logger.tracePii(`Item key: ${key}`);
136
- // read cache
137
- const cache = this.getCache();
138
- return cache[key];
139
- }
140
- /**
141
- * Gets cache item with given key-value
142
- * @param key - lookup key for the cache entry
143
- * @param value - value of the cache entry
144
- */
145
- setItem(key, value) {
146
- this.logger.tracePii(`Item key: ${key}`);
147
- // read cache
148
- const cache = this.getCache();
149
- cache[key] = value;
150
- // write to cache
151
- this.setCache(cache);
152
- }
153
- getAccountKeys() {
154
- const inMemoryCache = this.getInMemoryCache();
155
- const accountKeys = Object.keys(inMemoryCache.accounts);
156
- return accountKeys;
157
- }
158
- getTokenKeys() {
159
- const inMemoryCache = this.getInMemoryCache();
160
- const tokenKeys = {
161
- idToken: Object.keys(inMemoryCache.idTokens),
162
- accessToken: Object.keys(inMemoryCache.accessTokens),
163
- refreshToken: Object.keys(inMemoryCache.refreshTokens),
164
- };
165
- return tokenKeys;
166
- }
167
- /**
168
- * fetch the account entity
169
- * @param accountKey - lookup key to fetch cache type AccountEntity
170
- */
171
- getAccount(accountKey) {
172
- const accountEntity = this.getCachedAccountEntity(accountKey);
173
- if (accountEntity && msalCommon.AccountEntity.isAccountEntity(accountEntity)) {
174
- return this.updateOutdatedCachedAccount(accountKey, accountEntity);
175
- }
176
- return null;
177
- }
178
- /**
179
- * Reads account from cache, builds it into an account entity and returns it.
180
- * @param accountKey
181
- * @returns
182
- */
183
- getCachedAccountEntity(accountKey) {
184
- const cachedAccount = this.getItem(accountKey);
185
- return cachedAccount
186
- ? Object.assign(new msalCommon.AccountEntity(), this.getItem(accountKey))
187
- : null;
188
- }
189
- /**
190
- * set account entity
191
- * @param account - cache value to be set of type AccountEntity
192
- */
193
- setAccount(account) {
194
- const accountKey = account.generateAccountKey();
195
- this.setItem(accountKey, account);
196
- }
197
- /**
198
- * fetch the idToken credential
199
- * @param idTokenKey - lookup key to fetch cache type IdTokenEntity
200
- */
201
- getIdTokenCredential(idTokenKey) {
202
- const idToken = this.getItem(idTokenKey);
203
- if (msalCommon.CacheHelpers.isIdTokenEntity(idToken)) {
204
- return idToken;
205
- }
206
- return null;
207
- }
208
- /**
209
- * set idToken credential
210
- * @param idToken - cache value to be set of type IdTokenEntity
211
- */
212
- setIdTokenCredential(idToken) {
213
- const idTokenKey = msalCommon.CacheHelpers.generateCredentialKey(idToken);
214
- this.setItem(idTokenKey, idToken);
215
- }
216
- /**
217
- * fetch the accessToken credential
218
- * @param accessTokenKey - lookup key to fetch cache type AccessTokenEntity
219
- */
220
- getAccessTokenCredential(accessTokenKey) {
221
- const accessToken = this.getItem(accessTokenKey);
222
- if (msalCommon.CacheHelpers.isAccessTokenEntity(accessToken)) {
223
- return accessToken;
224
- }
225
- return null;
226
- }
227
- /**
228
- * set accessToken credential
229
- * @param accessToken - cache value to be set of type AccessTokenEntity
230
- */
231
- setAccessTokenCredential(accessToken) {
232
- const accessTokenKey = msalCommon.CacheHelpers.generateCredentialKey(accessToken);
233
- this.setItem(accessTokenKey, accessToken);
234
- }
235
- /**
236
- * fetch the refreshToken credential
237
- * @param refreshTokenKey - lookup key to fetch cache type RefreshTokenEntity
238
- */
239
- getRefreshTokenCredential(refreshTokenKey) {
240
- const refreshToken = this.getItem(refreshTokenKey);
241
- if (msalCommon.CacheHelpers.isRefreshTokenEntity(refreshToken)) {
242
- return refreshToken;
243
- }
244
- return null;
245
- }
246
- /**
247
- * set refreshToken credential
248
- * @param refreshToken - cache value to be set of type RefreshTokenEntity
249
- */
250
- setRefreshTokenCredential(refreshToken) {
251
- const refreshTokenKey = msalCommon.CacheHelpers.generateCredentialKey(refreshToken);
252
- this.setItem(refreshTokenKey, refreshToken);
253
- }
254
- /**
255
- * fetch appMetadata entity from the platform cache
256
- * @param appMetadataKey - lookup key to fetch cache type AppMetadataEntity
257
- */
258
- getAppMetadata(appMetadataKey) {
259
- const appMetadata = this.getItem(appMetadataKey);
260
- if (msalCommon.CacheHelpers.isAppMetadataEntity(appMetadataKey, appMetadata)) {
261
- return appMetadata;
262
- }
263
- return null;
264
- }
265
- /**
266
- * set appMetadata entity to the platform cache
267
- * @param appMetadata - cache value to be set of type AppMetadataEntity
268
- */
269
- setAppMetadata(appMetadata) {
270
- const appMetadataKey = msalCommon.CacheHelpers.generateAppMetadataKey(appMetadata);
271
- this.setItem(appMetadataKey, appMetadata);
272
- }
273
- /**
274
- * fetch server telemetry entity from the platform cache
275
- * @param serverTelemetrykey - lookup key to fetch cache type ServerTelemetryEntity
276
- */
277
- getServerTelemetry(serverTelemetrykey) {
278
- const serverTelemetryEntity = this.getItem(serverTelemetrykey);
279
- if (serverTelemetryEntity &&
280
- msalCommon.CacheHelpers.isServerTelemetryEntity(serverTelemetrykey, serverTelemetryEntity)) {
281
- return serverTelemetryEntity;
282
- }
283
- return null;
284
- }
285
- /**
286
- * set server telemetry entity to the platform cache
287
- * @param serverTelemetryKey - lookup key to fetch cache type ServerTelemetryEntity
288
- * @param serverTelemetry - cache value to be set of type ServerTelemetryEntity
289
- */
290
- setServerTelemetry(serverTelemetryKey, serverTelemetry) {
291
- this.setItem(serverTelemetryKey, serverTelemetry);
292
- }
293
- /**
294
- * fetch authority metadata entity from the platform cache
295
- * @param key - lookup key to fetch cache type AuthorityMetadataEntity
296
- */
297
- getAuthorityMetadata(key) {
298
- const authorityMetadataEntity = this.getItem(key);
299
- if (authorityMetadataEntity &&
300
- msalCommon.CacheHelpers.isAuthorityMetadataEntity(key, authorityMetadataEntity)) {
301
- return authorityMetadataEntity;
302
- }
303
- return null;
304
- }
305
- /**
306
- * Get all authority metadata keys
307
- */
308
- getAuthorityMetadataKeys() {
309
- return this.getKeys().filter((key) => {
310
- return this.isAuthorityMetadata(key);
311
- });
312
- }
313
- /**
314
- * set authority metadata entity to the platform cache
315
- * @param key - lookup key to fetch cache type AuthorityMetadataEntity
316
- * @param metadata - cache value to be set of type AuthorityMetadataEntity
317
- */
318
- setAuthorityMetadata(key, metadata) {
319
- this.setItem(key, metadata);
320
- }
321
- /**
322
- * fetch throttling entity from the platform cache
323
- * @param throttlingCacheKey - lookup key to fetch cache type ThrottlingEntity
324
- */
325
- getThrottlingCache(throttlingCacheKey) {
326
- const throttlingCache = this.getItem(throttlingCacheKey);
327
- if (throttlingCache &&
328
- msalCommon.CacheHelpers.isThrottlingEntity(throttlingCacheKey, throttlingCache)) {
329
- return throttlingCache;
330
- }
331
- return null;
332
- }
333
- /**
334
- * set throttling entity to the platform cache
335
- * @param throttlingCacheKey - lookup key to fetch cache type ThrottlingEntity
336
- * @param throttlingCache - cache value to be set of type ThrottlingEntity
337
- */
338
- setThrottlingCache(throttlingCacheKey, throttlingCache) {
339
- this.setItem(throttlingCacheKey, throttlingCache);
340
- }
341
- /**
342
- * Removes the cache item from memory with the given key.
343
- * @param key - lookup key to remove a cache entity
344
- * @param inMemory - key value map of the cache
345
- */
346
- removeItem(key) {
347
- this.logger.tracePii(`Item key: ${key}`);
348
- // read inMemoryCache
349
- let result = false;
350
- const cache = this.getCache();
351
- if (!!cache[key]) {
352
- delete cache[key];
353
- result = true;
354
- }
355
- // write to the cache after removal
356
- if (result) {
357
- this.setCache(cache);
358
- this.emitChange();
359
- }
360
- return result;
361
- }
362
- /**
363
- * Remove account entity from the platform cache if it's outdated
364
- * @param accountKey
365
- */
366
- removeOutdatedAccount(accountKey) {
367
- this.removeItem(accountKey);
368
- }
369
- /**
370
- * Checks whether key is in cache.
371
- * @param key - look up key for a cache entity
372
- */
373
- containsKey(key) {
374
- return this.getKeys().includes(key);
375
- }
376
- /**
377
- * Gets all keys in window.
378
- */
379
- getKeys() {
380
- this.logger.trace("Retrieving all cache keys");
381
- // read cache
382
- const cache = this.getCache();
383
- return [...Object.keys(cache)];
384
- }
385
- /**
386
- * Clears all cache entries created by MSAL (except tokens).
387
- */
388
- async clear() {
389
- this.logger.trace("Clearing cache entries created by MSAL");
390
- // read inMemoryCache
391
- const cacheKeys = this.getKeys();
392
- // delete each element
393
- cacheKeys.forEach((key) => {
394
- this.removeItem(key);
395
- });
396
- this.emitChange();
397
- }
398
- /**
399
- * Initialize in memory cache from an exisiting cache vault
400
- * @param cache - blob formatted cache (JSON)
401
- */
402
- static generateInMemoryCache(cache) {
403
- return Deserializer.Deserializer.deserializeAllCache(Deserializer.Deserializer.deserializeJSONBlob(cache));
404
- }
405
- /**
406
- * retrieves the final JSON
407
- * @param inMemoryCache - itemised cache read from the JSON
408
- */
409
- static generateJsonCache(inMemoryCache) {
410
- return Serializer.Serializer.serializeAllCache(inMemoryCache);
411
- }
412
- /**
413
- * Updates a credential's cache key if the current cache key is outdated
414
- */
415
- updateCredentialCacheKey(currentCacheKey, credential) {
416
- const updatedCacheKey = msalCommon.CacheHelpers.generateCredentialKey(credential);
417
- if (currentCacheKey !== updatedCacheKey) {
418
- const cacheItem = this.getItem(currentCacheKey);
419
- if (cacheItem) {
420
- this.removeItem(currentCacheKey);
421
- this.setItem(updatedCacheKey, cacheItem);
422
- this.logger.verbose(`Updated an outdated ${credential.credentialType} cache key`);
423
- return updatedCacheKey;
424
- }
425
- else {
426
- this.logger.error(`Attempted to update an outdated ${credential.credentialType} cache key but no item matching the outdated key was found in storage`);
427
- }
428
- }
429
- return currentCacheKey;
430
- }
9
+ /*
10
+ * Copyright (c) Microsoft Corporation. All rights reserved.
11
+ * Licensed under the MIT License.
12
+ */
13
+ /**
14
+ * This class implements Storage for node, reading cache from user specified storage location or an extension library
15
+ * @public
16
+ */
17
+ class NodeStorage extends msalCommon.CacheManager {
18
+ constructor(logger, clientId, cryptoImpl, staticAuthorityOptions) {
19
+ super(clientId, cryptoImpl, logger, staticAuthorityOptions);
20
+ this.cache = {};
21
+ this.changeEmitters = [];
22
+ this.logger = logger;
23
+ }
24
+ /**
25
+ * Queue up callbacks
26
+ * @param func - a callback function for cache change indication
27
+ */
28
+ registerChangeEmitter(func) {
29
+ this.changeEmitters.push(func);
30
+ }
31
+ /**
32
+ * Invoke the callback when cache changes
33
+ */
34
+ emitChange() {
35
+ this.changeEmitters.forEach((func) => func.call(null));
36
+ }
37
+ /**
38
+ * Converts cacheKVStore to InMemoryCache
39
+ * @param cache - key value store
40
+ */
41
+ cacheToInMemoryCache(cache) {
42
+ const inMemoryCache = {
43
+ accounts: {},
44
+ idTokens: {},
45
+ accessTokens: {},
46
+ refreshTokens: {},
47
+ appMetadata: {},
48
+ };
49
+ for (const key in cache) {
50
+ const value = cache[key];
51
+ if (typeof value !== "object") {
52
+ continue;
53
+ }
54
+ if (value instanceof msalCommon.AccountEntity) {
55
+ inMemoryCache.accounts[key] = value;
56
+ }
57
+ else if (msalCommon.CacheHelpers.isIdTokenEntity(value)) {
58
+ inMemoryCache.idTokens[key] = value;
59
+ }
60
+ else if (msalCommon.CacheHelpers.isAccessTokenEntity(value)) {
61
+ inMemoryCache.accessTokens[key] = value;
62
+ }
63
+ else if (msalCommon.CacheHelpers.isRefreshTokenEntity(value)) {
64
+ inMemoryCache.refreshTokens[key] = value;
65
+ }
66
+ else if (msalCommon.CacheHelpers.isAppMetadataEntity(key, value)) {
67
+ inMemoryCache.appMetadata[key] = value;
68
+ }
69
+ else {
70
+ continue;
71
+ }
72
+ }
73
+ return inMemoryCache;
74
+ }
75
+ /**
76
+ * converts inMemoryCache to CacheKVStore
77
+ * @param inMemoryCache - kvstore map for inmemory
78
+ */
79
+ inMemoryCacheToCache(inMemoryCache) {
80
+ // convert in memory cache to a flat Key-Value map
81
+ let cache = this.getCache();
82
+ cache = {
83
+ ...cache,
84
+ ...inMemoryCache.accounts,
85
+ ...inMemoryCache.idTokens,
86
+ ...inMemoryCache.accessTokens,
87
+ ...inMemoryCache.refreshTokens,
88
+ ...inMemoryCache.appMetadata,
89
+ };
90
+ // convert in memory cache to a flat Key-Value map
91
+ return cache;
92
+ }
93
+ /**
94
+ * gets the current in memory cache for the client
95
+ */
96
+ getInMemoryCache() {
97
+ this.logger.trace("Getting in-memory cache");
98
+ // convert the cache key value store to inMemoryCache
99
+ const inMemoryCache = this.cacheToInMemoryCache(this.getCache());
100
+ return inMemoryCache;
101
+ }
102
+ /**
103
+ * sets the current in memory cache for the client
104
+ * @param inMemoryCache - key value map in memory
105
+ */
106
+ setInMemoryCache(inMemoryCache) {
107
+ this.logger.trace("Setting in-memory cache");
108
+ // convert and append the inMemoryCache to cacheKVStore
109
+ const cache = this.inMemoryCacheToCache(inMemoryCache);
110
+ this.setCache(cache);
111
+ this.emitChange();
112
+ }
113
+ /**
114
+ * get the current cache key-value store
115
+ */
116
+ getCache() {
117
+ this.logger.trace("Getting cache key-value store");
118
+ return this.cache;
119
+ }
120
+ /**
121
+ * sets the current cache (key value store)
122
+ * @param cacheMap - key value map
123
+ */
124
+ setCache(cache) {
125
+ this.logger.trace("Setting cache key value store");
126
+ this.cache = cache;
127
+ // mark change in cache
128
+ this.emitChange();
129
+ }
130
+ /**
131
+ * Gets cache item with given key.
132
+ * @param key - lookup key for the cache entry
133
+ */
134
+ getItem(key) {
135
+ this.logger.tracePii(`Item key: ${key}`);
136
+ // read cache
137
+ const cache = this.getCache();
138
+ return cache[key];
139
+ }
140
+ /**
141
+ * Gets cache item with given key-value
142
+ * @param key - lookup key for the cache entry
143
+ * @param value - value of the cache entry
144
+ */
145
+ setItem(key, value) {
146
+ this.logger.tracePii(`Item key: ${key}`);
147
+ // read cache
148
+ const cache = this.getCache();
149
+ cache[key] = value;
150
+ // write to cache
151
+ this.setCache(cache);
152
+ }
153
+ getAccountKeys() {
154
+ const inMemoryCache = this.getInMemoryCache();
155
+ const accountKeys = Object.keys(inMemoryCache.accounts);
156
+ return accountKeys;
157
+ }
158
+ getTokenKeys() {
159
+ const inMemoryCache = this.getInMemoryCache();
160
+ const tokenKeys = {
161
+ idToken: Object.keys(inMemoryCache.idTokens),
162
+ accessToken: Object.keys(inMemoryCache.accessTokens),
163
+ refreshToken: Object.keys(inMemoryCache.refreshTokens),
164
+ };
165
+ return tokenKeys;
166
+ }
167
+ /**
168
+ * fetch the account entity
169
+ * @param accountKey - lookup key to fetch cache type AccountEntity
170
+ */
171
+ getAccount(accountKey) {
172
+ const accountEntity = this.getCachedAccountEntity(accountKey);
173
+ if (accountEntity && msalCommon.AccountEntity.isAccountEntity(accountEntity)) {
174
+ return this.updateOutdatedCachedAccount(accountKey, accountEntity);
175
+ }
176
+ return null;
177
+ }
178
+ /**
179
+ * Reads account from cache, builds it into an account entity and returns it.
180
+ * @param accountKey
181
+ * @returns
182
+ */
183
+ getCachedAccountEntity(accountKey) {
184
+ const cachedAccount = this.getItem(accountKey);
185
+ return cachedAccount
186
+ ? Object.assign(new msalCommon.AccountEntity(), this.getItem(accountKey))
187
+ : null;
188
+ }
189
+ /**
190
+ * set account entity
191
+ * @param account - cache value to be set of type AccountEntity
192
+ */
193
+ setAccount(account) {
194
+ const accountKey = account.generateAccountKey();
195
+ this.setItem(accountKey, account);
196
+ }
197
+ /**
198
+ * fetch the idToken credential
199
+ * @param idTokenKey - lookup key to fetch cache type IdTokenEntity
200
+ */
201
+ getIdTokenCredential(idTokenKey) {
202
+ const idToken = this.getItem(idTokenKey);
203
+ if (msalCommon.CacheHelpers.isIdTokenEntity(idToken)) {
204
+ return idToken;
205
+ }
206
+ return null;
207
+ }
208
+ /**
209
+ * set idToken credential
210
+ * @param idToken - cache value to be set of type IdTokenEntity
211
+ */
212
+ setIdTokenCredential(idToken) {
213
+ const idTokenKey = msalCommon.CacheHelpers.generateCredentialKey(idToken);
214
+ this.setItem(idTokenKey, idToken);
215
+ }
216
+ /**
217
+ * fetch the accessToken credential
218
+ * @param accessTokenKey - lookup key to fetch cache type AccessTokenEntity
219
+ */
220
+ getAccessTokenCredential(accessTokenKey) {
221
+ const accessToken = this.getItem(accessTokenKey);
222
+ if (msalCommon.CacheHelpers.isAccessTokenEntity(accessToken)) {
223
+ return accessToken;
224
+ }
225
+ return null;
226
+ }
227
+ /**
228
+ * set accessToken credential
229
+ * @param accessToken - cache value to be set of type AccessTokenEntity
230
+ */
231
+ setAccessTokenCredential(accessToken) {
232
+ const accessTokenKey = msalCommon.CacheHelpers.generateCredentialKey(accessToken);
233
+ this.setItem(accessTokenKey, accessToken);
234
+ }
235
+ /**
236
+ * fetch the refreshToken credential
237
+ * @param refreshTokenKey - lookup key to fetch cache type RefreshTokenEntity
238
+ */
239
+ getRefreshTokenCredential(refreshTokenKey) {
240
+ const refreshToken = this.getItem(refreshTokenKey);
241
+ if (msalCommon.CacheHelpers.isRefreshTokenEntity(refreshToken)) {
242
+ return refreshToken;
243
+ }
244
+ return null;
245
+ }
246
+ /**
247
+ * set refreshToken credential
248
+ * @param refreshToken - cache value to be set of type RefreshTokenEntity
249
+ */
250
+ setRefreshTokenCredential(refreshToken) {
251
+ const refreshTokenKey = msalCommon.CacheHelpers.generateCredentialKey(refreshToken);
252
+ this.setItem(refreshTokenKey, refreshToken);
253
+ }
254
+ /**
255
+ * fetch appMetadata entity from the platform cache
256
+ * @param appMetadataKey - lookup key to fetch cache type AppMetadataEntity
257
+ */
258
+ getAppMetadata(appMetadataKey) {
259
+ const appMetadata = this.getItem(appMetadataKey);
260
+ if (msalCommon.CacheHelpers.isAppMetadataEntity(appMetadataKey, appMetadata)) {
261
+ return appMetadata;
262
+ }
263
+ return null;
264
+ }
265
+ /**
266
+ * set appMetadata entity to the platform cache
267
+ * @param appMetadata - cache value to be set of type AppMetadataEntity
268
+ */
269
+ setAppMetadata(appMetadata) {
270
+ const appMetadataKey = msalCommon.CacheHelpers.generateAppMetadataKey(appMetadata);
271
+ this.setItem(appMetadataKey, appMetadata);
272
+ }
273
+ /**
274
+ * fetch server telemetry entity from the platform cache
275
+ * @param serverTelemetrykey - lookup key to fetch cache type ServerTelemetryEntity
276
+ */
277
+ getServerTelemetry(serverTelemetrykey) {
278
+ const serverTelemetryEntity = this.getItem(serverTelemetrykey);
279
+ if (serverTelemetryEntity &&
280
+ msalCommon.CacheHelpers.isServerTelemetryEntity(serverTelemetrykey, serverTelemetryEntity)) {
281
+ return serverTelemetryEntity;
282
+ }
283
+ return null;
284
+ }
285
+ /**
286
+ * set server telemetry entity to the platform cache
287
+ * @param serverTelemetryKey - lookup key to fetch cache type ServerTelemetryEntity
288
+ * @param serverTelemetry - cache value to be set of type ServerTelemetryEntity
289
+ */
290
+ setServerTelemetry(serverTelemetryKey, serverTelemetry) {
291
+ this.setItem(serverTelemetryKey, serverTelemetry);
292
+ }
293
+ /**
294
+ * fetch authority metadata entity from the platform cache
295
+ * @param key - lookup key to fetch cache type AuthorityMetadataEntity
296
+ */
297
+ getAuthorityMetadata(key) {
298
+ const authorityMetadataEntity = this.getItem(key);
299
+ if (authorityMetadataEntity &&
300
+ msalCommon.CacheHelpers.isAuthorityMetadataEntity(key, authorityMetadataEntity)) {
301
+ return authorityMetadataEntity;
302
+ }
303
+ return null;
304
+ }
305
+ /**
306
+ * Get all authority metadata keys
307
+ */
308
+ getAuthorityMetadataKeys() {
309
+ return this.getKeys().filter((key) => {
310
+ return this.isAuthorityMetadata(key);
311
+ });
312
+ }
313
+ /**
314
+ * set authority metadata entity to the platform cache
315
+ * @param key - lookup key to fetch cache type AuthorityMetadataEntity
316
+ * @param metadata - cache value to be set of type AuthorityMetadataEntity
317
+ */
318
+ setAuthorityMetadata(key, metadata) {
319
+ this.setItem(key, metadata);
320
+ }
321
+ /**
322
+ * fetch throttling entity from the platform cache
323
+ * @param throttlingCacheKey - lookup key to fetch cache type ThrottlingEntity
324
+ */
325
+ getThrottlingCache(throttlingCacheKey) {
326
+ const throttlingCache = this.getItem(throttlingCacheKey);
327
+ if (throttlingCache &&
328
+ msalCommon.CacheHelpers.isThrottlingEntity(throttlingCacheKey, throttlingCache)) {
329
+ return throttlingCache;
330
+ }
331
+ return null;
332
+ }
333
+ /**
334
+ * set throttling entity to the platform cache
335
+ * @param throttlingCacheKey - lookup key to fetch cache type ThrottlingEntity
336
+ * @param throttlingCache - cache value to be set of type ThrottlingEntity
337
+ */
338
+ setThrottlingCache(throttlingCacheKey, throttlingCache) {
339
+ this.setItem(throttlingCacheKey, throttlingCache);
340
+ }
341
+ /**
342
+ * Removes the cache item from memory with the given key.
343
+ * @param key - lookup key to remove a cache entity
344
+ * @param inMemory - key value map of the cache
345
+ */
346
+ removeItem(key) {
347
+ this.logger.tracePii(`Item key: ${key}`);
348
+ // read inMemoryCache
349
+ let result = false;
350
+ const cache = this.getCache();
351
+ if (!!cache[key]) {
352
+ delete cache[key];
353
+ result = true;
354
+ }
355
+ // write to the cache after removal
356
+ if (result) {
357
+ this.setCache(cache);
358
+ this.emitChange();
359
+ }
360
+ return result;
361
+ }
362
+ /**
363
+ * Remove account entity from the platform cache if it's outdated
364
+ * @param accountKey
365
+ */
366
+ removeOutdatedAccount(accountKey) {
367
+ this.removeItem(accountKey);
368
+ }
369
+ /**
370
+ * Checks whether key is in cache.
371
+ * @param key - look up key for a cache entity
372
+ */
373
+ containsKey(key) {
374
+ return this.getKeys().includes(key);
375
+ }
376
+ /**
377
+ * Gets all keys in window.
378
+ */
379
+ getKeys() {
380
+ this.logger.trace("Retrieving all cache keys");
381
+ // read cache
382
+ const cache = this.getCache();
383
+ return [...Object.keys(cache)];
384
+ }
385
+ /**
386
+ * Clears all cache entries created by MSAL (except tokens).
387
+ */
388
+ async clear() {
389
+ this.logger.trace("Clearing cache entries created by MSAL");
390
+ // read inMemoryCache
391
+ const cacheKeys = this.getKeys();
392
+ // delete each element
393
+ cacheKeys.forEach((key) => {
394
+ this.removeItem(key);
395
+ });
396
+ this.emitChange();
397
+ }
398
+ /**
399
+ * Initialize in memory cache from an exisiting cache vault
400
+ * @param cache - blob formatted cache (JSON)
401
+ */
402
+ static generateInMemoryCache(cache) {
403
+ return Deserializer.Deserializer.deserializeAllCache(Deserializer.Deserializer.deserializeJSONBlob(cache));
404
+ }
405
+ /**
406
+ * retrieves the final JSON
407
+ * @param inMemoryCache - itemised cache read from the JSON
408
+ */
409
+ static generateJsonCache(inMemoryCache) {
410
+ return Serializer.Serializer.serializeAllCache(inMemoryCache);
411
+ }
412
+ /**
413
+ * Updates a credential's cache key if the current cache key is outdated
414
+ */
415
+ updateCredentialCacheKey(currentCacheKey, credential) {
416
+ const updatedCacheKey = msalCommon.CacheHelpers.generateCredentialKey(credential);
417
+ if (currentCacheKey !== updatedCacheKey) {
418
+ const cacheItem = this.getItem(currentCacheKey);
419
+ if (cacheItem) {
420
+ this.removeItem(currentCacheKey);
421
+ this.setItem(updatedCacheKey, cacheItem);
422
+ this.logger.verbose(`Updated an outdated ${credential.credentialType} cache key`);
423
+ return updatedCacheKey;
424
+ }
425
+ else {
426
+ this.logger.error(`Attempted to update an outdated ${credential.credentialType} cache key but no item matching the outdated key was found in storage`);
427
+ }
428
+ }
429
+ return currentCacheKey;
430
+ }
431
431
  }
432
432
 
433
433
  exports.NodeStorage = NodeStorage;