@azure/msal-common 14.0.3 → 14.1.0-alpha.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 (296) hide show
  1. package/dist/account/AccountInfo.d.ts +32 -32
  2. package/dist/account/AuthToken.d.ts +17 -17
  3. package/dist/account/AuthToken.d.ts.map +1 -1
  4. package/dist/account/AuthToken.mjs +60 -59
  5. package/dist/account/AuthToken.mjs.map +1 -1
  6. package/dist/account/CcsCredential.d.ts +9 -9
  7. package/dist/account/CcsCredential.mjs +8 -8
  8. package/dist/account/ClientCredentials.d.ts +14 -14
  9. package/dist/account/ClientInfo.d.ts +19 -19
  10. package/dist/account/ClientInfo.d.ts.map +1 -1
  11. package/dist/account/ClientInfo.mjs +39 -38
  12. package/dist/account/ClientInfo.mjs.map +1 -1
  13. package/dist/account/TokenClaims.d.ts +65 -65
  14. package/dist/authority/Authority.d.ts +235 -235
  15. package/dist/authority/Authority.d.ts.map +1 -1
  16. package/dist/authority/Authority.mjs +743 -765
  17. package/dist/authority/Authority.mjs.map +1 -1
  18. package/dist/authority/AuthorityFactory.d.ts +31 -31
  19. package/dist/authority/AuthorityFactory.d.ts.map +1 -1
  20. package/dist/authority/AuthorityFactory.mjs +52 -50
  21. package/dist/authority/AuthorityFactory.mjs.map +1 -1
  22. package/dist/authority/AuthorityMetadata.d.ts +623 -623
  23. package/dist/authority/AuthorityMetadata.mjs +884 -884
  24. package/dist/authority/AuthorityOptions.d.ts +21 -21
  25. package/dist/authority/AuthorityOptions.mjs +18 -18
  26. package/dist/authority/AuthorityType.d.ts +10 -10
  27. package/dist/authority/AuthorityType.mjs +13 -13
  28. package/dist/authority/AzureRegion.d.ts +1 -1
  29. package/dist/authority/AzureRegionConfiguration.d.ts +5 -5
  30. package/dist/authority/CloudDiscoveryMetadata.d.ts +5 -5
  31. package/dist/authority/CloudInstanceDiscoveryErrorResponse.d.ts +13 -13
  32. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +8 -8
  33. package/dist/authority/CloudInstanceDiscoveryResponse.d.ts +9 -9
  34. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +8 -8
  35. package/dist/authority/ImdsOptions.d.ts +5 -5
  36. package/dist/authority/OIDCOptions.d.ts +8 -8
  37. package/dist/authority/OpenIdConfigResponse.d.ts +11 -11
  38. package/dist/authority/OpenIdConfigResponse.mjs +10 -10
  39. package/dist/authority/ProtocolMode.d.ts +8 -8
  40. package/dist/authority/ProtocolMode.mjs +11 -11
  41. package/dist/authority/RegionDiscovery.d.ts +32 -30
  42. package/dist/authority/RegionDiscovery.d.ts.map +1 -1
  43. package/dist/authority/RegionDiscovery.mjs +107 -108
  44. package/dist/authority/RegionDiscovery.mjs.map +1 -1
  45. package/dist/authority/RegionDiscoveryMetadata.d.ts +6 -6
  46. package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts +15 -15
  47. package/dist/cache/CacheManager.d.ts +446 -446
  48. package/dist/cache/CacheManager.d.ts.map +1 -1
  49. package/dist/cache/CacheManager.mjs +1000 -1024
  50. package/dist/cache/CacheManager.mjs.map +1 -1
  51. package/dist/cache/entities/AccessTokenEntity.d.ts +56 -56
  52. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  53. package/dist/cache/entities/AccessTokenEntity.mjs +111 -110
  54. package/dist/cache/entities/AccessTokenEntity.mjs.map +1 -1
  55. package/dist/cache/entities/AccountEntity.d.ts +101 -101
  56. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  57. package/dist/cache/entities/AccountEntity.mjs +222 -221
  58. package/dist/cache/entities/AccountEntity.mjs.map +1 -1
  59. package/dist/cache/entities/AppMetadataEntity.d.ts +39 -39
  60. package/dist/cache/entities/AppMetadataEntity.mjs +66 -66
  61. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +48 -48
  62. package/dist/cache/entities/AuthorityMetadataEntity.mjs +78 -78
  63. package/dist/cache/entities/CacheRecord.d.ts +14 -14
  64. package/dist/cache/entities/CacheRecord.mjs +14 -14
  65. package/dist/cache/entities/CredentialEntity.d.ts +88 -88
  66. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  67. package/dist/cache/entities/CredentialEntity.mjs +138 -137
  68. package/dist/cache/entities/CredentialEntity.mjs.map +1 -1
  69. package/dist/cache/entities/IdTokenEntity.d.ts +34 -34
  70. package/dist/cache/entities/IdTokenEntity.mjs +56 -56
  71. package/dist/cache/entities/RefreshTokenEntity.d.ts +36 -36
  72. package/dist/cache/entities/RefreshTokenEntity.mjs +59 -59
  73. package/dist/cache/entities/ServerTelemetryEntity.d.ts +12 -12
  74. package/dist/cache/entities/ServerTelemetryEntity.mjs +27 -27
  75. package/dist/cache/entities/ThrottlingEntity.d.ts +13 -13
  76. package/dist/cache/entities/ThrottlingEntity.mjs +23 -23
  77. package/dist/cache/interface/ICacheManager.d.ts +166 -166
  78. package/dist/cache/interface/ICachePlugin.d.ts +5 -5
  79. package/dist/cache/interface/ISerializableTokenCache.d.ts +4 -4
  80. package/dist/cache/persistence/TokenCacheContext.d.ts +23 -23
  81. package/dist/cache/persistence/TokenCacheContext.mjs +25 -25
  82. package/dist/cache/utils/CacheTypes.d.ts +69 -69
  83. package/dist/client/AuthorizationCodeClient.d.ts +73 -73
  84. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  85. package/dist/client/AuthorizationCodeClient.mjs +411 -410
  86. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  87. package/dist/client/BaseClient.d.ts +51 -51
  88. package/dist/client/BaseClient.d.ts.map +1 -1
  89. package/dist/client/BaseClient.mjs +100 -99
  90. package/dist/client/BaseClient.mjs.map +1 -1
  91. package/dist/client/RefreshTokenClient.d.ts +35 -35
  92. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  93. package/dist/client/RefreshTokenClient.mjs +185 -234
  94. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  95. package/dist/client/SilentFlowClient.d.ts +26 -25
  96. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  97. package/dist/client/SilentFlowClient.mjs +127 -103
  98. package/dist/client/SilentFlowClient.mjs.map +1 -1
  99. package/dist/config/AppTokenProvider.d.ts +38 -38
  100. package/dist/config/ClientConfiguration.d.ts +150 -150
  101. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  102. package/dist/config/ClientConfiguration.mjs +99 -100
  103. package/dist/config/ClientConfiguration.mjs.map +1 -1
  104. package/dist/crypto/ICrypto.d.ts +62 -62
  105. package/dist/crypto/ICrypto.d.ts.map +1 -1
  106. package/dist/crypto/ICrypto.mjs +35 -43
  107. package/dist/crypto/ICrypto.mjs.map +1 -1
  108. package/dist/crypto/IGuidGenerator.d.ts +4 -4
  109. package/dist/crypto/JoseHeader.d.ts +22 -22
  110. package/dist/crypto/JoseHeader.d.ts.map +1 -1
  111. package/dist/crypto/JoseHeader.mjs +39 -38
  112. package/dist/crypto/JoseHeader.mjs.map +1 -1
  113. package/dist/crypto/PopTokenGenerator.d.ts +60 -59
  114. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  115. package/dist/crypto/PopTokenGenerator.mjs +83 -83
  116. package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
  117. package/dist/crypto/SignedHttpRequest.d.ts +11 -11
  118. package/dist/error/AuthError.d.ts +44 -47
  119. package/dist/error/AuthError.d.ts.map +1 -1
  120. package/dist/error/AuthError.mjs +50 -52
  121. package/dist/error/AuthError.mjs.map +1 -1
  122. package/dist/error/AuthErrorCodes.d.ts +6 -0
  123. package/dist/error/AuthErrorCodes.d.ts.map +1 -0
  124. package/dist/error/AuthErrorCodes.mjs +14 -0
  125. package/dist/error/AuthErrorCodes.mjs.map +1 -0
  126. package/dist/error/ClientAuthError.d.ts +232 -412
  127. package/dist/error/ClientAuthError.d.ts.map +1 -1
  128. package/dist/error/ClientAuthError.mjs +248 -520
  129. package/dist/error/ClientAuthError.mjs.map +1 -1
  130. package/dist/error/ClientAuthErrorCodes.d.ts +44 -0
  131. package/dist/error/ClientAuthErrorCodes.d.ts.map +1 -0
  132. package/dist/error/ClientAuthErrorCodes.mjs +52 -0
  133. package/dist/error/ClientAuthErrorCodes.mjs.map +1 -0
  134. package/dist/error/ClientConfigurationError.d.ts +128 -222
  135. package/dist/error/ClientConfigurationError.d.ts.map +1 -1
  136. package/dist/error/ClientConfigurationError.mjs +140 -281
  137. package/dist/error/ClientConfigurationError.mjs.map +1 -1
  138. package/dist/error/ClientConfigurationErrorCodes.d.ts +23 -0
  139. package/dist/error/ClientConfigurationErrorCodes.d.ts.map +1 -0
  140. package/dist/error/ClientConfigurationErrorCodes.mjs +31 -0
  141. package/dist/error/ClientConfigurationErrorCodes.mjs.map +1 -0
  142. package/dist/error/InteractionRequiredAuthError.d.ts +57 -59
  143. package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
  144. package/dist/error/InteractionRequiredAuthError.mjs +80 -79
  145. package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
  146. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts +6 -0
  147. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts.map +1 -0
  148. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +16 -0
  149. package/dist/error/InteractionRequiredAuthErrorCodes.mjs.map +1 -0
  150. package/dist/error/JoseHeaderError.d.ts +15 -28
  151. package/dist/error/JoseHeaderError.d.ts.map +1 -1
  152. package/dist/error/JoseHeaderError.mjs +24 -40
  153. package/dist/error/JoseHeaderError.mjs.map +1 -1
  154. package/dist/error/JoseHeaderErrorCodes.d.ts +3 -0
  155. package/dist/error/JoseHeaderErrorCodes.d.ts.map +1 -0
  156. package/dist/error/JoseHeaderErrorCodes.mjs +11 -0
  157. package/dist/error/JoseHeaderErrorCodes.mjs.map +1 -0
  158. package/dist/error/ServerError.d.ts +7 -7
  159. package/dist/error/ServerError.mjs +14 -14
  160. package/dist/index.cjs +8715 -9047
  161. package/dist/index.cjs.map +1 -1
  162. package/dist/index.d.ts +96 -96
  163. package/dist/index.d.ts.map +1 -1
  164. package/dist/index.mjs +13 -5
  165. package/dist/index.mjs.map +1 -1
  166. package/dist/logger/Logger.d.ts +95 -95
  167. package/dist/logger/Logger.mjs +188 -188
  168. package/dist/network/INetworkModule.d.ts +29 -29
  169. package/dist/network/INetworkModule.d.ts.map +1 -1
  170. package/dist/network/INetworkModule.mjs +14 -15
  171. package/dist/network/INetworkModule.mjs.map +1 -1
  172. package/dist/network/NetworkManager.d.ts +33 -33
  173. package/dist/network/NetworkManager.d.ts.map +1 -1
  174. package/dist/network/NetworkManager.mjs +36 -35
  175. package/dist/network/NetworkManager.mjs.map +1 -1
  176. package/dist/network/RequestThumbprint.d.ts +16 -16
  177. package/dist/network/ThrottlingUtils.d.ts +42 -42
  178. package/dist/network/ThrottlingUtils.mjs +95 -95
  179. package/dist/packageMetadata.d.ts +2 -2
  180. package/dist/packageMetadata.mjs +3 -3
  181. package/dist/request/AuthenticationHeaderParser.d.ts +19 -19
  182. package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -1
  183. package/dist/request/AuthenticationHeaderParser.mjs +58 -57
  184. package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
  185. package/dist/request/BaseAuthRequest.d.ts +40 -40
  186. package/dist/request/CommonAuthorizationCodeRequest.d.ts +27 -27
  187. package/dist/request/CommonAuthorizationUrlRequest.d.ts +50 -50
  188. package/dist/request/CommonClientCredentialRequest.d.ts +17 -17
  189. package/dist/request/CommonDeviceCodeRequest.d.ts +21 -21
  190. package/dist/request/CommonEndSessionRequest.d.ts +21 -21
  191. package/dist/request/CommonOnBehalfOfRequest.d.ts +13 -13
  192. package/dist/request/CommonRefreshTokenRequest.d.ts +19 -19
  193. package/dist/request/CommonSilentFlowRequest.d.ts +18 -18
  194. package/dist/request/CommonUsernamePasswordRequest.d.ts +17 -17
  195. package/dist/request/NativeRequest.d.ts +19 -19
  196. package/dist/request/NativeSignOutRequest.d.ts +5 -5
  197. package/dist/request/RequestParameterBuilder.d.ts +217 -217
  198. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  199. package/dist/request/RequestParameterBuilder.mjs +383 -382
  200. package/dist/request/RequestParameterBuilder.mjs.map +1 -1
  201. package/dist/request/RequestValidator.d.ts +33 -33
  202. package/dist/request/RequestValidator.d.ts.map +1 -1
  203. package/dist/request/RequestValidator.mjs +83 -82
  204. package/dist/request/RequestValidator.mjs.map +1 -1
  205. package/dist/request/ScopeSet.d.ts +88 -88
  206. package/dist/request/ScopeSet.d.ts.map +1 -1
  207. package/dist/request/ScopeSet.mjs +201 -199
  208. package/dist/request/ScopeSet.mjs.map +1 -1
  209. package/dist/request/StoreInCache.d.ts +8 -8
  210. package/dist/response/AuthenticationResult.d.ts +41 -41
  211. package/dist/response/AuthorizationCodePayload.d.ts +13 -13
  212. package/dist/response/DeviceCodeResponse.d.ts +25 -25
  213. package/dist/response/ExternalTokenResponse.d.ts +15 -15
  214. package/dist/response/IMDSBadResponse.d.ts +4 -4
  215. package/dist/response/ResponseHandler.d.ts +67 -67
  216. package/dist/response/ResponseHandler.d.ts.map +1 -1
  217. package/dist/response/ResponseHandler.mjs +314 -313
  218. package/dist/response/ResponseHandler.mjs.map +1 -1
  219. package/dist/response/ServerAuthorizationCodeResponse.d.ts +25 -25
  220. package/dist/response/ServerAuthorizationTokenResponse.d.ts +46 -46
  221. package/dist/telemetry/performance/IPerformanceClient.d.ts +51 -51
  222. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +5 -5
  223. package/dist/telemetry/performance/PerformanceClient.d.ts +191 -191
  224. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  225. package/dist/telemetry/performance/PerformanceClient.mjs +409 -408
  226. package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
  227. package/dist/telemetry/performance/PerformanceEvent.d.ts +433 -433
  228. package/dist/telemetry/performance/PerformanceEvent.mjs +234 -234
  229. package/dist/telemetry/performance/StubPerformanceClient.d.ts +24 -24
  230. package/dist/telemetry/performance/StubPerformanceClient.mjs +76 -76
  231. package/dist/telemetry/server/ServerTelemetryManager.d.ts +66 -66
  232. package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
  233. package/dist/telemetry/server/ServerTelemetryManager.mjs +197 -197
  234. package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
  235. package/dist/telemetry/server/ServerTelemetryRequest.d.ts +8 -8
  236. package/dist/url/IUri.d.ts +12 -12
  237. package/dist/url/UrlString.d.ts +83 -83
  238. package/dist/url/UrlString.d.ts.map +1 -1
  239. package/dist/url/UrlString.mjs +283 -281
  240. package/dist/url/UrlString.mjs.map +1 -1
  241. package/dist/utils/Constants.d.ts +366 -363
  242. package/dist/utils/Constants.d.ts.map +1 -1
  243. package/dist/utils/Constants.mjs +376 -368
  244. package/dist/utils/Constants.mjs.map +1 -1
  245. package/dist/utils/FunctionWrappers.d.ts +27 -27
  246. package/dist/utils/FunctionWrappers.mjs +85 -85
  247. package/dist/utils/MsalTypes.d.ts +6 -6
  248. package/dist/utils/ProtocolUtils.d.ts +42 -42
  249. package/dist/utils/ProtocolUtils.d.ts.map +1 -1
  250. package/dist/utils/ProtocolUtils.mjs +71 -70
  251. package/dist/utils/ProtocolUtils.mjs.map +1 -1
  252. package/dist/utils/StringUtils.d.ts +40 -40
  253. package/dist/utils/StringUtils.mjs +95 -95
  254. package/dist/utils/TimeUtils.d.ts +27 -27
  255. package/dist/utils/TimeUtils.mjs +45 -45
  256. package/package.json +1 -1
  257. package/src/account/AuthToken.ts +8 -7
  258. package/src/account/ClientInfo.ts +9 -6
  259. package/src/authority/Authority.ts +76 -94
  260. package/src/authority/AuthorityFactory.ts +21 -9
  261. package/src/authority/RegionDiscovery.ts +21 -18
  262. package/src/cache/CacheManager.ts +37 -77
  263. package/src/cache/entities/AccessTokenEntity.ts +7 -2
  264. package/src/cache/entities/AccountEntity.ts +7 -2
  265. package/src/cache/entities/CredentialEntity.ts +7 -2
  266. package/src/client/AuthorizationCodeClient.ts +32 -10
  267. package/src/client/BaseClient.ts +7 -4
  268. package/src/client/RefreshTokenClient.ts +81 -124
  269. package/src/client/SilentFlowClient.ts +72 -19
  270. package/src/config/ClientConfiguration.ts +6 -7
  271. package/src/crypto/ICrypto.ts +13 -28
  272. package/src/crypto/JoseHeader.ts +6 -3
  273. package/src/crypto/PopTokenGenerator.ts +10 -5
  274. package/src/error/AuthError.ts +24 -26
  275. package/src/error/AuthErrorCodes.ts +10 -0
  276. package/src/error/ClientAuthError.ts +227 -632
  277. package/src/error/ClientAuthErrorCodes.ts +51 -0
  278. package/src/error/ClientConfigurationError.ts +146 -332
  279. package/src/error/ClientConfigurationErrorCodes.ts +28 -0
  280. package/src/error/InteractionRequiredAuthError.ts +60 -55
  281. package/src/error/InteractionRequiredAuthErrorCodes.ts +13 -0
  282. package/src/error/JoseHeaderError.ts +11 -31
  283. package/src/error/JoseHeaderErrorCodes.ts +7 -0
  284. package/src/index.ts +12 -1
  285. package/src/network/INetworkModule.ts +10 -7
  286. package/src/network/NetworkManager.ts +5 -5
  287. package/src/request/AuthenticationHeaderParser.ts +11 -8
  288. package/src/request/RequestParameterBuilder.ts +10 -3
  289. package/src/request/RequestValidator.ts +19 -6
  290. package/src/request/ScopeSet.ts +23 -7
  291. package/src/response/ResponseHandler.ts +37 -17
  292. package/src/telemetry/performance/PerformanceClient.ts +2 -1
  293. package/src/telemetry/server/ServerTelemetryManager.ts +1 -1
  294. package/src/url/UrlString.ts +26 -16
  295. package/src/utils/Constants.ts +11 -3
  296. package/src/utils/ProtocolUtils.ts +8 -12
@@ -1,1034 +1,1010 @@
1
- /*! @azure/msal-common v14.0.3 2023-09-05 */
1
+ /*! @azure/msal-common v14.1.0-alpha.0 2023-09-20 */
2
2
  'use strict';
3
3
  import { Separators, CredentialType, AuthenticationScheme, THE_FAMILY_ID, APP_METADATA, AUTHORITY_METADATA_CONSTANTS } from '../utils/Constants.mjs';
4
4
  import { ScopeSet } from '../request/ScopeSet.mjs';
5
5
  import { AccountEntity } from './entities/AccountEntity.mjs';
6
- import { AuthError } from '../error/AuthError.mjs';
7
- import { ClientAuthError } from '../error/ClientAuthError.mjs';
6
+ import { createClientAuthError } from '../error/ClientAuthError.mjs';
8
7
  import { extractTokenClaims } from '../account/AuthToken.mjs';
9
8
  import { name, version } from '../packageMetadata.mjs';
9
+ import { invalidCacheRecord, bindingKeyNotRemoved, multipleMatchingAppMetadata, methodNotImplemented } from '../error/ClientAuthErrorCodes.mjs';
10
10
 
11
- /*
12
- * Copyright (c) Microsoft Corporation. All rights reserved.
13
- * Licensed under the MIT License.
14
- */
15
- /**
16
- * Interface class which implement cache storage functions used by MSAL to perform validity checks, and store tokens.
17
- * @internal
18
- */
19
- class CacheManager {
20
- constructor(clientId, cryptoImpl, logger) {
21
- this.clientId = clientId;
22
- this.cryptoImpl = cryptoImpl;
23
- this.commonLogger = logger.clone(name, version);
24
- }
25
- /**
26
- * Returns all accounts in cache
27
- */
28
- getAllAccounts() {
29
- const allAccountKeys = this.getAccountKeys();
30
- if (allAccountKeys.length < 1) {
31
- return [];
32
- }
33
- const accountEntities = allAccountKeys.reduce((accounts, key) => {
34
- const entity = this.getAccount(key);
35
- if (!entity) {
36
- return accounts;
37
- }
38
- accounts.push(entity);
39
- return accounts;
40
- }, []);
41
- if (accountEntities.length < 1) {
42
- return [];
43
- }
44
- else {
45
- const allAccounts = accountEntities.map((accountEntity) => {
46
- return this.getAccountInfoFromEntity(accountEntity);
47
- });
48
- return allAccounts;
49
- }
50
- }
51
- /**
52
- * Gets accountInfo object based on provided filters
53
- */
54
- getAccountInfoFilteredBy(accountFilter) {
55
- const allAccounts = this.getAccountsFilteredBy(accountFilter);
56
- if (allAccounts.length > 0) {
57
- return this.getAccountInfoFromEntity(allAccounts[0]);
58
- }
59
- else {
60
- return null;
61
- }
62
- }
63
- getAccountInfoFromEntity(accountEntity) {
64
- const accountInfo = accountEntity.getAccountInfo();
65
- const idToken = this.getIdToken(accountInfo);
66
- if (idToken) {
67
- accountInfo.idToken = idToken.secret;
68
- accountInfo.idTokenClaims = extractTokenClaims(idToken.secret, this.cryptoImpl.base64Decode);
69
- }
70
- return accountInfo;
71
- }
72
- /**
73
- * saves a cache record
74
- * @param cacheRecord
75
- */
76
- async saveCacheRecord(cacheRecord, storeInCache) {
77
- if (!cacheRecord) {
78
- throw ClientAuthError.createNullOrUndefinedCacheRecord();
79
- }
80
- if (!!cacheRecord.account) {
81
- this.setAccount(cacheRecord.account);
82
- }
83
- if (!!cacheRecord.idToken && storeInCache?.idToken !== false) {
84
- this.setIdTokenCredential(cacheRecord.idToken);
85
- }
86
- if (!!cacheRecord.accessToken && storeInCache?.accessToken !== false) {
87
- await this.saveAccessToken(cacheRecord.accessToken);
88
- }
89
- if (!!cacheRecord.refreshToken &&
90
- storeInCache?.refreshToken !== false) {
91
- this.setRefreshTokenCredential(cacheRecord.refreshToken);
92
- }
93
- if (!!cacheRecord.appMetadata) {
94
- this.setAppMetadata(cacheRecord.appMetadata);
95
- }
96
- }
97
- /**
98
- * saves access token credential
99
- * @param credential
100
- */
101
- async saveAccessToken(credential) {
102
- const accessTokenFilter = {
103
- clientId: credential.clientId,
104
- credentialType: credential.credentialType,
105
- environment: credential.environment,
106
- homeAccountId: credential.homeAccountId,
107
- realm: credential.realm,
108
- tokenType: credential.tokenType,
109
- requestedClaimsHash: credential.requestedClaimsHash,
110
- };
111
- const tokenKeys = this.getTokenKeys();
112
- const currentScopes = ScopeSet.fromString(credential.target);
113
- const removedAccessTokens = [];
114
- tokenKeys.accessToken.forEach((key) => {
115
- if (!this.accessTokenKeyMatchesFilter(key, accessTokenFilter, false)) {
116
- return;
117
- }
118
- const tokenEntity = this.getAccessTokenCredential(key);
119
- if (tokenEntity &&
120
- this.credentialMatchesFilter(tokenEntity, accessTokenFilter)) {
121
- const tokenScopeSet = ScopeSet.fromString(tokenEntity.target);
122
- if (tokenScopeSet.intersectingScopeSets(currentScopes)) {
123
- removedAccessTokens.push(this.removeAccessToken(key));
124
- }
125
- }
126
- });
127
- await Promise.all(removedAccessTokens);
128
- this.setAccessTokenCredential(credential);
129
- }
130
- /**
131
- * retrieve accounts matching all provided filters; if no filter is set, get all accounts
132
- * not checking for casing as keys are all generated in lower case, remember to convert to lower case if object properties are compared
133
- * @param homeAccountId
134
- * @param environment
135
- * @param realm
136
- */
137
- getAccountsFilteredBy(accountFilter) {
138
- const allAccountKeys = this.getAccountKeys();
139
- const matchingAccounts = [];
140
- allAccountKeys.forEach((cacheKey) => {
141
- if (!this.isAccountKey(cacheKey, accountFilter.homeAccountId, accountFilter.realm)) {
142
- // Don't parse value if the key doesn't match the account filters
143
- return;
144
- }
145
- const entity = this.getAccount(cacheKey);
146
- if (!entity) {
147
- return;
148
- }
149
- if (!!accountFilter.homeAccountId &&
150
- !this.matchHomeAccountId(entity, accountFilter.homeAccountId)) {
151
- return;
152
- }
153
- if (!!accountFilter.localAccountId &&
154
- !this.matchLocalAccountId(entity, accountFilter.localAccountId)) {
155
- return;
156
- }
157
- if (!!accountFilter.username &&
158
- !this.matchUsername(entity, accountFilter.username)) {
159
- return;
160
- }
161
- if (!!accountFilter.environment &&
162
- !this.matchEnvironment(entity, accountFilter.environment)) {
163
- return;
164
- }
165
- if (!!accountFilter.realm &&
166
- !this.matchRealm(entity, accountFilter.realm)) {
167
- return;
168
- }
169
- if (!!accountFilter.nativeAccountId &&
170
- !this.matchNativeAccountId(entity, accountFilter.nativeAccountId)) {
171
- return;
172
- }
173
- matchingAccounts.push(entity);
174
- });
175
- return matchingAccounts;
176
- }
177
- /**
178
- * Returns true if the given key matches our account key schema. Also matches homeAccountId and/or tenantId if provided
179
- * @param key
180
- * @param homeAccountId
181
- * @param tenantId
182
- * @returns
183
- */
184
- isAccountKey(key, homeAccountId, tenantId) {
185
- if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 3) {
186
- // Account cache keys contain 3 items separated by '-' (each item may also contain '-')
187
- return false;
188
- }
189
- if (homeAccountId &&
190
- !key.toLowerCase().includes(homeAccountId.toLowerCase())) {
191
- return false;
192
- }
193
- if (tenantId && !key.toLowerCase().includes(tenantId.toLowerCase())) {
194
- return false;
195
- }
196
- // Do not check environment as aliasing can cause false negatives
197
- return true;
198
- }
199
- /**
200
- * Returns true if the given key matches our credential key schema.
201
- * @param key
202
- */
203
- isCredentialKey(key) {
204
- if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 6) {
205
- // Credential cache keys contain 6 items separated by '-' (each item may also contain '-')
206
- return false;
207
- }
208
- const lowerCaseKey = key.toLowerCase();
209
- // Credential keys must indicate what credential type they represent
210
- if (lowerCaseKey.indexOf(CredentialType.ID_TOKEN.toLowerCase()) ===
211
- -1 &&
212
- lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN.toLowerCase()) ===
213
- -1 &&
214
- lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()) === -1 &&
215
- lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) ===
216
- -1) {
217
- return false;
218
- }
219
- if (lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) >
220
- -1) {
221
- // Refresh tokens must contain the client id or family id
222
- const clientIdValidation = `${CredentialType.REFRESH_TOKEN}${Separators.CACHE_KEY_SEPARATOR}${this.clientId}${Separators.CACHE_KEY_SEPARATOR}`;
223
- const familyIdValidation = `${CredentialType.REFRESH_TOKEN}${Separators.CACHE_KEY_SEPARATOR}${THE_FAMILY_ID}${Separators.CACHE_KEY_SEPARATOR}`;
224
- if (lowerCaseKey.indexOf(clientIdValidation.toLowerCase()) === -1 &&
225
- lowerCaseKey.indexOf(familyIdValidation.toLowerCase()) === -1) {
226
- return false;
227
- }
228
- }
229
- else if (lowerCaseKey.indexOf(this.clientId.toLowerCase()) === -1) {
230
- // Tokens must contain the clientId
231
- return false;
232
- }
233
- return true;
234
- }
235
- /**
236
- * Returns whether or not the given credential entity matches the filter
237
- * @param entity
238
- * @param filter
239
- * @returns
240
- */
241
- credentialMatchesFilter(entity, filter) {
242
- if (!!filter.clientId && !this.matchClientId(entity, filter.clientId)) {
243
- return false;
244
- }
245
- if (!!filter.userAssertionHash &&
246
- !this.matchUserAssertionHash(entity, filter.userAssertionHash)) {
247
- return false;
248
- }
249
- /*
250
- * homeAccountId can be undefined, and we want to filter out cached items that have a homeAccountId of ""
251
- * because we don't want a client_credential request to return a cached token that has a homeAccountId
252
- */
253
- if (typeof filter.homeAccountId === "string" &&
254
- !this.matchHomeAccountId(entity, filter.homeAccountId)) {
255
- return false;
256
- }
257
- if (!!filter.environment &&
258
- !this.matchEnvironment(entity, filter.environment)) {
259
- return false;
260
- }
261
- if (!!filter.realm && !this.matchRealm(entity, filter.realm)) {
262
- return false;
263
- }
264
- if (!!filter.credentialType &&
265
- !this.matchCredentialType(entity, filter.credentialType)) {
266
- return false;
267
- }
268
- if (!!filter.familyId && !this.matchFamilyId(entity, filter.familyId)) {
269
- return false;
270
- }
271
- /*
272
- * idTokens do not have "target", target specific refreshTokens do exist for some types of authentication
273
- * Resource specific refresh tokens case will be added when the support is deemed necessary
274
- */
275
- if (!!filter.target && !this.matchTarget(entity, filter.target)) {
276
- return false;
277
- }
278
- // If request OR cached entity has requested Claims Hash, check if they match
279
- if (filter.requestedClaimsHash || entity.requestedClaimsHash) {
280
- // Don't match if either is undefined or they are different
281
- if (entity.requestedClaimsHash !== filter.requestedClaimsHash) {
282
- return false;
283
- }
284
- }
285
- // Access Token with Auth Scheme specific matching
286
- if (entity.credentialType ===
287
- CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
288
- if (!!filter.tokenType &&
289
- !this.matchTokenType(entity, filter.tokenType)) {
290
- return false;
291
- }
292
- // KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
293
- if (filter.tokenType === AuthenticationScheme.SSH) {
294
- if (filter.keyId && !this.matchKeyId(entity, filter.keyId)) {
295
- return false;
296
- }
297
- }
298
- }
299
- return true;
300
- }
301
- /**
302
- * retrieve appMetadata matching all provided filters; if no filter is set, get all appMetadata
303
- * @param filter
304
- */
305
- getAppMetadataFilteredBy(filter) {
306
- return this.getAppMetadataFilteredByInternal(filter.environment, filter.clientId);
307
- }
308
- /**
309
- * Support function to help match appMetadata
310
- * @param environment
311
- * @param clientId
312
- */
313
- getAppMetadataFilteredByInternal(environment, clientId) {
314
- const allCacheKeys = this.getKeys();
315
- const matchingAppMetadata = {};
316
- allCacheKeys.forEach((cacheKey) => {
317
- // don't parse any non-appMetadata type cache entities
318
- if (!this.isAppMetadata(cacheKey)) {
319
- return;
320
- }
321
- // Attempt retrieval
322
- const entity = this.getAppMetadata(cacheKey);
323
- if (!entity) {
324
- return;
325
- }
326
- if (!!environment && !this.matchEnvironment(entity, environment)) {
327
- return;
328
- }
329
- if (!!clientId && !this.matchClientId(entity, clientId)) {
330
- return;
331
- }
332
- matchingAppMetadata[cacheKey] = entity;
333
- });
334
- return matchingAppMetadata;
335
- }
336
- /**
337
- * retrieve authorityMetadata that contains a matching alias
338
- * @param filter
339
- */
340
- getAuthorityMetadataByAlias(host) {
341
- const allCacheKeys = this.getAuthorityMetadataKeys();
342
- let matchedEntity = null;
343
- allCacheKeys.forEach((cacheKey) => {
344
- // don't parse any non-authorityMetadata type cache entities
345
- if (!this.isAuthorityMetadata(cacheKey) ||
346
- cacheKey.indexOf(this.clientId) === -1) {
347
- return;
348
- }
349
- // Attempt retrieval
350
- const entity = this.getAuthorityMetadata(cacheKey);
351
- if (!entity) {
352
- return;
353
- }
354
- if (entity.aliases.indexOf(host) === -1) {
355
- return;
356
- }
357
- matchedEntity = entity;
358
- });
359
- return matchedEntity;
360
- }
361
- /**
362
- * Removes all accounts and related tokens from cache.
363
- */
364
- async removeAllAccounts() {
365
- const allAccountKeys = this.getAccountKeys();
366
- const removedAccounts = [];
367
- allAccountKeys.forEach((cacheKey) => {
368
- removedAccounts.push(this.removeAccount(cacheKey));
369
- });
370
- await Promise.all(removedAccounts);
371
- }
372
- /**
373
- * Removes the account and related tokens for a given account key
374
- * @param account
375
- */
376
- async removeAccount(accountKey) {
377
- const account = this.getAccount(accountKey);
378
- if (!account) {
379
- return;
380
- }
381
- await this.removeAccountContext(account);
382
- this.removeItem(accountKey);
383
- }
384
- /**
385
- * Removes credentials associated with the provided account
386
- * @param account
387
- */
388
- async removeAccountContext(account) {
389
- const allTokenKeys = this.getTokenKeys();
390
- const accountId = account.generateAccountId();
391
- const removedCredentials = [];
392
- allTokenKeys.idToken.forEach((key) => {
393
- if (key.indexOf(accountId) === 0) {
394
- this.removeIdToken(key);
395
- }
396
- });
397
- allTokenKeys.accessToken.forEach((key) => {
398
- if (key.indexOf(accountId) === 0) {
399
- removedCredentials.push(this.removeAccessToken(key));
400
- }
401
- });
402
- allTokenKeys.refreshToken.forEach((key) => {
403
- if (key.indexOf(accountId) === 0) {
404
- this.removeRefreshToken(key);
405
- }
406
- });
407
- await Promise.all(removedCredentials);
408
- }
409
- /**
410
- * returns a boolean if the given credential is removed
411
- * @param credential
412
- */
413
- async removeAccessToken(key) {
414
- const credential = this.getAccessTokenCredential(key);
415
- if (!credential) {
416
- return;
417
- }
418
- // Remove Token Binding Key from key store for PoP Tokens Credentials
419
- if (credential.credentialType.toLowerCase() ===
420
- CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()) {
421
- if (credential.tokenType === AuthenticationScheme.POP) {
422
- const accessTokenWithAuthSchemeEntity = credential;
423
- const kid = accessTokenWithAuthSchemeEntity.keyId;
424
- if (kid) {
425
- try {
426
- await this.cryptoImpl.removeTokenBindingKey(kid);
427
- }
428
- catch (error) {
429
- throw ClientAuthError.createBindingKeyNotRemovedError();
430
- }
431
- }
432
- }
433
- }
434
- return this.removeItem(key);
435
- }
436
- /**
437
- * Removes all app metadata objects from cache.
438
- */
439
- removeAppMetadata() {
440
- const allCacheKeys = this.getKeys();
441
- allCacheKeys.forEach((cacheKey) => {
442
- if (this.isAppMetadata(cacheKey)) {
443
- this.removeItem(cacheKey);
444
- }
445
- });
446
- return true;
447
- }
448
- /**
449
- * Retrieve the cached credentials into a cacherecord
450
- * @param account
451
- * @param clientId
452
- * @param scopes
453
- * @param environment
454
- * @param authScheme
455
- */
456
- readCacheRecord(account, request, environment) {
457
- const tokenKeys = this.getTokenKeys();
458
- const cachedAccount = this.readAccountFromCache(account);
459
- const cachedIdToken = this.getIdToken(account, tokenKeys);
460
- const cachedAccessToken = this.getAccessToken(account, request, tokenKeys);
461
- const cachedRefreshToken = this.getRefreshToken(account, false, tokenKeys);
462
- const cachedAppMetadata = this.readAppMetadataFromCache(environment);
463
- if (cachedAccount && cachedIdToken) {
464
- cachedAccount.idTokenClaims = extractTokenClaims(cachedIdToken.secret, this.cryptoImpl.base64Decode);
465
- }
466
- return {
467
- account: cachedAccount,
468
- idToken: cachedIdToken,
469
- accessToken: cachedAccessToken,
470
- refreshToken: cachedRefreshToken,
471
- appMetadata: cachedAppMetadata,
472
- };
473
- }
474
- /**
475
- * Retrieve AccountEntity from cache
476
- * @param account
477
- */
478
- readAccountFromCache(account) {
479
- const accountKey = AccountEntity.generateAccountCacheKey(account);
480
- return this.getAccount(accountKey);
481
- }
482
- /**
483
- * Retrieve IdTokenEntity from cache
484
- * @param clientId
485
- * @param account
486
- * @param inputRealm
487
- */
488
- getIdToken(account, tokenKeys) {
489
- this.commonLogger.trace("CacheManager - getIdToken called");
490
- const idTokenFilter = {
491
- homeAccountId: account.homeAccountId,
492
- environment: account.environment,
493
- credentialType: CredentialType.ID_TOKEN,
494
- clientId: this.clientId,
495
- realm: account.tenantId,
496
- };
497
- const idTokens = this.getIdTokensByFilter(idTokenFilter, tokenKeys);
498
- const numIdTokens = idTokens.length;
499
- if (numIdTokens < 1) {
500
- this.commonLogger.info("CacheManager:getIdToken - No token found");
501
- return null;
502
- }
503
- else if (numIdTokens > 1) {
504
- this.commonLogger.info("CacheManager:getIdToken - Multiple id tokens found, clearing them");
505
- idTokens.forEach((idToken) => {
506
- this.removeIdToken(idToken.generateCredentialKey());
507
- });
508
- return null;
509
- }
510
- this.commonLogger.info("CacheManager:getIdToken - Returning id token");
511
- return idTokens[0];
512
- }
513
- /**
514
- * Gets all idTokens matching the given filter
515
- * @param filter
516
- * @returns
517
- */
518
- getIdTokensByFilter(filter, tokenKeys) {
519
- const idTokenKeys = (tokenKeys && tokenKeys.idToken) || this.getTokenKeys().idToken;
520
- const idTokens = [];
521
- idTokenKeys.forEach((key) => {
522
- if (!this.idTokenKeyMatchesFilter(key, {
523
- clientId: this.clientId,
524
- ...filter,
525
- })) {
526
- return;
527
- }
528
- const idToken = this.getIdTokenCredential(key);
529
- if (idToken && this.credentialMatchesFilter(idToken, filter)) {
530
- idTokens.push(idToken);
531
- }
532
- });
533
- return idTokens;
534
- }
535
- /**
536
- * Validate the cache key against filter before retrieving and parsing cache value
537
- * @param key
538
- * @param filter
539
- * @returns
540
- */
541
- idTokenKeyMatchesFilter(inputKey, filter) {
542
- const key = inputKey.toLowerCase();
543
- if (filter.clientId &&
544
- key.indexOf(filter.clientId.toLowerCase()) === -1) {
545
- return false;
546
- }
547
- if (filter.homeAccountId &&
548
- key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
549
- return false;
550
- }
551
- return true;
552
- }
553
- /**
554
- * Removes idToken from the cache
555
- * @param key
556
- */
557
- removeIdToken(key) {
558
- this.removeItem(key);
559
- }
560
- /**
561
- * Removes refresh token from the cache
562
- * @param key
563
- */
564
- removeRefreshToken(key) {
565
- this.removeItem(key);
566
- }
567
- /**
568
- * Retrieve AccessTokenEntity from cache
569
- * @param clientId
570
- * @param account
571
- * @param scopes
572
- * @param authScheme
573
- */
574
- getAccessToken(account, request, tokenKeys) {
575
- this.commonLogger.trace("CacheManager - getAccessToken called");
576
- const scopes = ScopeSet.createSearchScopes(request.scopes);
577
- const authScheme = request.authenticationScheme || AuthenticationScheme.BEARER;
578
- /*
579
- * Distinguish between Bearer and PoP/SSH token cache types
580
- * Cast to lowercase to handle "bearer" from ADFS
581
- */
582
- const credentialType = authScheme &&
583
- authScheme.toLowerCase() !==
584
- AuthenticationScheme.BEARER.toLowerCase()
585
- ? CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME
586
- : CredentialType.ACCESS_TOKEN;
587
- const accessTokenFilter = {
588
- homeAccountId: account.homeAccountId,
589
- environment: account.environment,
590
- credentialType: credentialType,
591
- clientId: this.clientId,
592
- realm: account.tenantId,
593
- target: scopes,
594
- tokenType: authScheme,
595
- keyId: request.sshKid,
596
- requestedClaimsHash: request.requestedClaimsHash,
597
- };
598
- const accessTokenKeys = (tokenKeys && tokenKeys.accessToken) ||
599
- this.getTokenKeys().accessToken;
600
- const accessTokens = [];
601
- accessTokenKeys.forEach((key) => {
602
- // Validate key
603
- if (this.accessTokenKeyMatchesFilter(key, accessTokenFilter, true)) {
604
- const accessToken = this.getAccessTokenCredential(key);
605
- // Validate value
606
- if (accessToken &&
607
- this.credentialMatchesFilter(accessToken, accessTokenFilter)) {
608
- accessTokens.push(accessToken);
609
- }
610
- }
611
- });
612
- const numAccessTokens = accessTokens.length;
613
- if (numAccessTokens < 1) {
614
- this.commonLogger.info("CacheManager:getAccessToken - No token found");
615
- return null;
616
- }
617
- else if (numAccessTokens > 1) {
618
- this.commonLogger.info("CacheManager:getAccessToken - Multiple access tokens found, clearing them");
619
- accessTokens.forEach((accessToken) => {
620
- void this.removeAccessToken(accessToken.generateCredentialKey());
621
- });
622
- return null;
623
- }
624
- this.commonLogger.info("CacheManager:getAccessToken - Returning access token");
625
- return accessTokens[0];
626
- }
627
- /**
628
- * Validate the cache key against filter before retrieving and parsing cache value
629
- * @param key
630
- * @param filter
631
- * @param keyMustContainAllScopes
632
- * @returns
633
- */
634
- accessTokenKeyMatchesFilter(inputKey, filter, keyMustContainAllScopes) {
635
- const key = inputKey.toLowerCase();
636
- if (filter.clientId &&
637
- key.indexOf(filter.clientId.toLowerCase()) === -1) {
638
- return false;
639
- }
640
- if (filter.homeAccountId &&
641
- key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
642
- return false;
643
- }
644
- if (filter.realm && key.indexOf(filter.realm.toLowerCase()) === -1) {
645
- return false;
646
- }
647
- if (filter.requestedClaimsHash &&
648
- key.indexOf(filter.requestedClaimsHash.toLowerCase()) === -1) {
649
- return false;
650
- }
651
- if (filter.target) {
652
- const scopes = filter.target.asArray();
653
- for (let i = 0; i < scopes.length; i++) {
654
- if (keyMustContainAllScopes &&
655
- !key.includes(scopes[i].toLowerCase())) {
656
- // When performing a cache lookup a missing scope would be a cache miss
657
- return false;
658
- }
659
- else if (!keyMustContainAllScopes &&
660
- key.includes(scopes[i].toLowerCase())) {
661
- // When performing a cache write, any token with a subset of requested scopes should be replaced
662
- return true;
663
- }
664
- }
665
- }
666
- return true;
667
- }
668
- /**
669
- * Gets all access tokens matching the filter
670
- * @param filter
671
- * @returns
672
- */
673
- getAccessTokensByFilter(filter) {
674
- const tokenKeys = this.getTokenKeys();
675
- const accessTokens = [];
676
- tokenKeys.accessToken.forEach((key) => {
677
- if (!this.accessTokenKeyMatchesFilter(key, filter, true)) {
678
- return;
679
- }
680
- const accessToken = this.getAccessTokenCredential(key);
681
- if (accessToken &&
682
- this.credentialMatchesFilter(accessToken, filter)) {
683
- accessTokens.push(accessToken);
684
- }
685
- });
686
- return accessTokens;
687
- }
688
- /**
689
- * Helper to retrieve the appropriate refresh token from cache
690
- * @param clientId
691
- * @param account
692
- * @param familyRT
693
- */
694
- getRefreshToken(account, familyRT, tokenKeys) {
695
- this.commonLogger.trace("CacheManager - getRefreshToken called");
696
- const id = familyRT ? THE_FAMILY_ID : undefined;
697
- const refreshTokenFilter = {
698
- homeAccountId: account.homeAccountId,
699
- environment: account.environment,
700
- credentialType: CredentialType.REFRESH_TOKEN,
701
- clientId: this.clientId,
702
- familyId: id,
703
- };
704
- const refreshTokenKeys = (tokenKeys && tokenKeys.refreshToken) ||
705
- this.getTokenKeys().refreshToken;
706
- const refreshTokens = [];
707
- refreshTokenKeys.forEach((key) => {
708
- // Validate key
709
- if (this.refreshTokenKeyMatchesFilter(key, refreshTokenFilter)) {
710
- const refreshToken = this.getRefreshTokenCredential(key);
711
- // Validate value
712
- if (refreshToken &&
713
- this.credentialMatchesFilter(refreshToken, refreshTokenFilter)) {
714
- refreshTokens.push(refreshToken);
715
- }
716
- }
717
- });
718
- const numRefreshTokens = refreshTokens.length;
719
- if (numRefreshTokens < 1) {
720
- this.commonLogger.info("CacheManager:getRefreshToken - No refresh token found.");
721
- return null;
722
- }
723
- // address the else case after remove functions address environment aliases
724
- this.commonLogger.info("CacheManager:getRefreshToken - returning refresh token");
725
- return refreshTokens[0];
726
- }
727
- /**
728
- * Validate the cache key against filter before retrieving and parsing cache value
729
- * @param key
730
- * @param filter
731
- */
732
- refreshTokenKeyMatchesFilter(inputKey, filter) {
733
- const key = inputKey.toLowerCase();
734
- if (filter.familyId &&
735
- key.indexOf(filter.familyId.toLowerCase()) === -1) {
736
- return false;
737
- }
738
- // If familyId is used, clientId is not in the key
739
- if (!filter.familyId &&
740
- filter.clientId &&
741
- key.indexOf(filter.clientId.toLowerCase()) === -1) {
742
- return false;
743
- }
744
- if (filter.homeAccountId &&
745
- key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
746
- return false;
747
- }
748
- return true;
749
- }
750
- /**
751
- * Retrieve AppMetadataEntity from cache
752
- */
753
- readAppMetadataFromCache(environment) {
754
- const appMetadataFilter = {
755
- environment,
756
- clientId: this.clientId,
757
- };
758
- const appMetadata = this.getAppMetadataFilteredBy(appMetadataFilter);
759
- const appMetadataEntries = Object.keys(appMetadata).map((key) => appMetadata[key]);
760
- const numAppMetadata = appMetadataEntries.length;
761
- if (numAppMetadata < 1) {
762
- return null;
763
- }
764
- else if (numAppMetadata > 1) {
765
- throw ClientAuthError.createMultipleMatchingAppMetadataInCacheError();
766
- }
767
- return appMetadataEntries[0];
768
- }
769
- /**
770
- * Return the family_id value associated with FOCI
771
- * @param environment
772
- * @param clientId
773
- */
774
- isAppMetadataFOCI(environment) {
775
- const appMetadata = this.readAppMetadataFromCache(environment);
776
- return !!(appMetadata && appMetadata.familyId === THE_FAMILY_ID);
777
- }
778
- /**
779
- * helper to match account ids
780
- * @param value
781
- * @param homeAccountId
782
- */
783
- matchHomeAccountId(entity, homeAccountId) {
784
- return !!(typeof entity.homeAccountId === "string" &&
785
- homeAccountId === entity.homeAccountId);
786
- }
787
- /**
788
- * helper to match account ids
789
- * @param entity
790
- * @param localAccountId
791
- * @returns
792
- */
793
- matchLocalAccountId(entity, localAccountId) {
794
- return !!(typeof entity.localAccountId === "string" &&
795
- localAccountId === entity.localAccountId);
796
- }
797
- /**
798
- * helper to match usernames
799
- * @param entity
800
- * @param username
801
- * @returns
802
- */
803
- matchUsername(entity, username) {
804
- return !!(typeof entity.username === "string" &&
805
- username.toLowerCase() === entity.username.toLowerCase());
806
- }
807
- /**
808
- * helper to match assertion
809
- * @param value
810
- * @param oboAssertion
811
- */
812
- matchUserAssertionHash(entity, userAssertionHash) {
813
- return !!(entity.userAssertionHash &&
814
- userAssertionHash === entity.userAssertionHash);
815
- }
816
- /**
817
- * helper to match environment
818
- * @param value
819
- * @param environment
820
- */
821
- matchEnvironment(entity, environment) {
822
- const cloudMetadata = this.getAuthorityMetadataByAlias(environment);
823
- if (cloudMetadata &&
824
- cloudMetadata.aliases.indexOf(entity.environment) > -1) {
825
- return true;
826
- }
827
- return false;
828
- }
829
- /**
830
- * helper to match credential type
831
- * @param entity
832
- * @param credentialType
833
- */
834
- matchCredentialType(entity, credentialType) {
835
- return (entity.credentialType &&
836
- credentialType.toLowerCase() === entity.credentialType.toLowerCase());
837
- }
838
- /**
839
- * helper to match client ids
840
- * @param entity
841
- * @param clientId
842
- */
843
- matchClientId(entity, clientId) {
844
- return !!(entity.clientId && clientId === entity.clientId);
845
- }
846
- /**
847
- * helper to match family ids
848
- * @param entity
849
- * @param familyId
850
- */
851
- matchFamilyId(entity, familyId) {
852
- return !!(entity.familyId && familyId === entity.familyId);
853
- }
854
- /**
855
- * helper to match realm
856
- * @param entity
857
- * @param realm
858
- */
859
- matchRealm(entity, realm) {
860
- return !!(entity.realm && realm === entity.realm);
861
- }
862
- /**
863
- * helper to match nativeAccountId
864
- * @param entity
865
- * @param nativeAccountId
866
- * @returns boolean indicating the match result
867
- */
868
- matchNativeAccountId(entity, nativeAccountId) {
869
- return !!(entity.nativeAccountId && nativeAccountId === entity.nativeAccountId);
870
- }
871
- /**
872
- * Returns true if the target scopes are a subset of the current entity's scopes, false otherwise.
873
- * @param entity
874
- * @param target
875
- */
876
- matchTarget(entity, target) {
877
- const isNotAccessTokenCredential = entity.credentialType !== CredentialType.ACCESS_TOKEN &&
878
- entity.credentialType !==
879
- CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;
880
- if (isNotAccessTokenCredential || !entity.target) {
881
- return false;
882
- }
883
- const entityScopeSet = ScopeSet.fromString(entity.target);
884
- return entityScopeSet.containsScopeSet(target);
885
- }
886
- /**
887
- * Returns true if the credential's tokenType or Authentication Scheme matches the one in the request, false otherwise
888
- * @param entity
889
- * @param tokenType
890
- */
891
- matchTokenType(entity, tokenType) {
892
- return !!(entity.tokenType && entity.tokenType === tokenType);
893
- }
894
- /**
895
- * Returns true if the credential's keyId matches the one in the request, false otherwise
896
- * @param entity
897
- * @param tokenType
898
- */
899
- matchKeyId(entity, keyId) {
900
- return !!(entity.keyId && entity.keyId === keyId);
901
- }
902
- /**
903
- * returns if a given cache entity is of the type appmetadata
904
- * @param key
905
- */
906
- isAppMetadata(key) {
907
- return key.indexOf(APP_METADATA) !== -1;
908
- }
909
- /**
910
- * returns if a given cache entity is of the type authoritymetadata
911
- * @param key
912
- */
913
- isAuthorityMetadata(key) {
914
- return key.indexOf(AUTHORITY_METADATA_CONSTANTS.CACHE_KEY) !== -1;
915
- }
916
- /**
917
- * returns cache key used for cloud instance metadata
918
- */
919
- generateAuthorityMetadataCacheKey(authority) {
920
- return `${AUTHORITY_METADATA_CONSTANTS.CACHE_KEY}-${this.clientId}-${authority}`;
921
- }
922
- /**
923
- * Helper to convert serialized data to object
924
- * @param obj
925
- * @param json
926
- */
927
- static toObject(obj, json) {
928
- for (const propertyName in json) {
929
- obj[propertyName] = json[propertyName];
930
- }
931
- return obj;
932
- }
933
- }
934
- /** @internal */
935
- class DefaultStorageClass extends CacheManager {
936
- setAccount() {
937
- const notImplErr = "Storage interface - setAccount() has not been implemented for the cacheStorage interface.";
938
- throw AuthError.createUnexpectedError(notImplErr);
939
- }
940
- getAccount() {
941
- const notImplErr = "Storage interface - getAccount() has not been implemented for the cacheStorage interface.";
942
- throw AuthError.createUnexpectedError(notImplErr);
943
- }
944
- setIdTokenCredential() {
945
- const notImplErr = "Storage interface - setIdTokenCredential() has not been implemented for the cacheStorage interface.";
946
- throw AuthError.createUnexpectedError(notImplErr);
947
- }
948
- getIdTokenCredential() {
949
- const notImplErr = "Storage interface - getIdTokenCredential() has not been implemented for the cacheStorage interface.";
950
- throw AuthError.createUnexpectedError(notImplErr);
951
- }
952
- setAccessTokenCredential() {
953
- const notImplErr = "Storage interface - setAccessTokenCredential() has not been implemented for the cacheStorage interface.";
954
- throw AuthError.createUnexpectedError(notImplErr);
955
- }
956
- getAccessTokenCredential() {
957
- const notImplErr = "Storage interface - getAccessTokenCredential() has not been implemented for the cacheStorage interface.";
958
- throw AuthError.createUnexpectedError(notImplErr);
959
- }
960
- setRefreshTokenCredential() {
961
- const notImplErr = "Storage interface - setRefreshTokenCredential() has not been implemented for the cacheStorage interface.";
962
- throw AuthError.createUnexpectedError(notImplErr);
963
- }
964
- getRefreshTokenCredential() {
965
- const notImplErr = "Storage interface - getRefreshTokenCredential() has not been implemented for the cacheStorage interface.";
966
- throw AuthError.createUnexpectedError(notImplErr);
967
- }
968
- setAppMetadata() {
969
- const notImplErr = "Storage interface - setAppMetadata() has not been implemented for the cacheStorage interface.";
970
- throw AuthError.createUnexpectedError(notImplErr);
971
- }
972
- getAppMetadata() {
973
- const notImplErr = "Storage interface - getAppMetadata() has not been implemented for the cacheStorage interface.";
974
- throw AuthError.createUnexpectedError(notImplErr);
975
- }
976
- setServerTelemetry() {
977
- const notImplErr = "Storage interface - setServerTelemetry() has not been implemented for the cacheStorage interface.";
978
- throw AuthError.createUnexpectedError(notImplErr);
979
- }
980
- getServerTelemetry() {
981
- const notImplErr = "Storage interface - getServerTelemetry() has not been implemented for the cacheStorage interface.";
982
- throw AuthError.createUnexpectedError(notImplErr);
983
- }
984
- setAuthorityMetadata() {
985
- const notImplErr = "Storage interface - setAuthorityMetadata() has not been implemented for the cacheStorage interface.";
986
- throw AuthError.createUnexpectedError(notImplErr);
987
- }
988
- getAuthorityMetadata() {
989
- const notImplErr = "Storage interface - getAuthorityMetadata() has not been implemented for the cacheStorage interface.";
990
- throw AuthError.createUnexpectedError(notImplErr);
991
- }
992
- getAuthorityMetadataKeys() {
993
- const notImplErr = "Storage interface - getAuthorityMetadataKeys() has not been implemented for the cacheStorage interface.";
994
- throw AuthError.createUnexpectedError(notImplErr);
995
- }
996
- setThrottlingCache() {
997
- const notImplErr = "Storage interface - setThrottlingCache() has not been implemented for the cacheStorage interface.";
998
- throw AuthError.createUnexpectedError(notImplErr);
999
- }
1000
- getThrottlingCache() {
1001
- const notImplErr = "Storage interface - getThrottlingCache() has not been implemented for the cacheStorage interface.";
1002
- throw AuthError.createUnexpectedError(notImplErr);
1003
- }
1004
- removeItem() {
1005
- const notImplErr = "Storage interface - removeItem() has not been implemented for the cacheStorage interface.";
1006
- throw AuthError.createUnexpectedError(notImplErr);
1007
- }
1008
- containsKey() {
1009
- const notImplErr = "Storage interface - containsKey() has not been implemented for the cacheStorage interface.";
1010
- throw AuthError.createUnexpectedError(notImplErr);
1011
- }
1012
- getKeys() {
1013
- const notImplErr = "Storage interface - getKeys() has not been implemented for the cacheStorage interface.";
1014
- throw AuthError.createUnexpectedError(notImplErr);
1015
- }
1016
- getAccountKeys() {
1017
- const notImplErr = "Storage interface - getAccountKeys() has not been implemented for the cacheStorage interface.";
1018
- throw AuthError.createUnexpectedError(notImplErr);
1019
- }
1020
- getTokenKeys() {
1021
- const notImplErr = "Storage interface - getTokenKeys() has not been implemented for the cacheStorage interface.";
1022
- throw AuthError.createUnexpectedError(notImplErr);
1023
- }
1024
- async clear() {
1025
- const notImplErr = "Storage interface - clear() has not been implemented for the cacheStorage interface.";
1026
- throw AuthError.createUnexpectedError(notImplErr);
1027
- }
1028
- updateCredentialCacheKey() {
1029
- const notImplErr = "Storage interface - updateCredentialCacheKey() has not been implemented for the cacheStorage interface.";
1030
- throw AuthError.createUnexpectedError(notImplErr);
1031
- }
11
+ /*
12
+ * Copyright (c) Microsoft Corporation. All rights reserved.
13
+ * Licensed under the MIT License.
14
+ */
15
+ /**
16
+ * Interface class which implement cache storage functions used by MSAL to perform validity checks, and store tokens.
17
+ * @internal
18
+ */
19
+ class CacheManager {
20
+ constructor(clientId, cryptoImpl, logger) {
21
+ this.clientId = clientId;
22
+ this.cryptoImpl = cryptoImpl;
23
+ this.commonLogger = logger.clone(name, version);
24
+ }
25
+ /**
26
+ * Returns all accounts in cache
27
+ */
28
+ getAllAccounts() {
29
+ const allAccountKeys = this.getAccountKeys();
30
+ if (allAccountKeys.length < 1) {
31
+ return [];
32
+ }
33
+ const accountEntities = allAccountKeys.reduce((accounts, key) => {
34
+ const entity = this.getAccount(key);
35
+ if (!entity) {
36
+ return accounts;
37
+ }
38
+ accounts.push(entity);
39
+ return accounts;
40
+ }, []);
41
+ if (accountEntities.length < 1) {
42
+ return [];
43
+ }
44
+ else {
45
+ const allAccounts = accountEntities.map((accountEntity) => {
46
+ return this.getAccountInfoFromEntity(accountEntity);
47
+ });
48
+ return allAccounts;
49
+ }
50
+ }
51
+ /**
52
+ * Gets accountInfo object based on provided filters
53
+ */
54
+ getAccountInfoFilteredBy(accountFilter) {
55
+ const allAccounts = this.getAccountsFilteredBy(accountFilter);
56
+ if (allAccounts.length > 0) {
57
+ return this.getAccountInfoFromEntity(allAccounts[0]);
58
+ }
59
+ else {
60
+ return null;
61
+ }
62
+ }
63
+ getAccountInfoFromEntity(accountEntity) {
64
+ const accountInfo = accountEntity.getAccountInfo();
65
+ const idToken = this.getIdToken(accountInfo);
66
+ if (idToken) {
67
+ accountInfo.idToken = idToken.secret;
68
+ accountInfo.idTokenClaims = extractTokenClaims(idToken.secret, this.cryptoImpl.base64Decode);
69
+ }
70
+ return accountInfo;
71
+ }
72
+ /**
73
+ * saves a cache record
74
+ * @param cacheRecord
75
+ */
76
+ async saveCacheRecord(cacheRecord, storeInCache) {
77
+ if (!cacheRecord) {
78
+ throw createClientAuthError(invalidCacheRecord);
79
+ }
80
+ if (!!cacheRecord.account) {
81
+ this.setAccount(cacheRecord.account);
82
+ }
83
+ if (!!cacheRecord.idToken && storeInCache?.idToken !== false) {
84
+ this.setIdTokenCredential(cacheRecord.idToken);
85
+ }
86
+ if (!!cacheRecord.accessToken && storeInCache?.accessToken !== false) {
87
+ await this.saveAccessToken(cacheRecord.accessToken);
88
+ }
89
+ if (!!cacheRecord.refreshToken &&
90
+ storeInCache?.refreshToken !== false) {
91
+ this.setRefreshTokenCredential(cacheRecord.refreshToken);
92
+ }
93
+ if (!!cacheRecord.appMetadata) {
94
+ this.setAppMetadata(cacheRecord.appMetadata);
95
+ }
96
+ }
97
+ /**
98
+ * saves access token credential
99
+ * @param credential
100
+ */
101
+ async saveAccessToken(credential) {
102
+ const accessTokenFilter = {
103
+ clientId: credential.clientId,
104
+ credentialType: credential.credentialType,
105
+ environment: credential.environment,
106
+ homeAccountId: credential.homeAccountId,
107
+ realm: credential.realm,
108
+ tokenType: credential.tokenType,
109
+ requestedClaimsHash: credential.requestedClaimsHash,
110
+ };
111
+ const tokenKeys = this.getTokenKeys();
112
+ const currentScopes = ScopeSet.fromString(credential.target);
113
+ const removedAccessTokens = [];
114
+ tokenKeys.accessToken.forEach((key) => {
115
+ if (!this.accessTokenKeyMatchesFilter(key, accessTokenFilter, false)) {
116
+ return;
117
+ }
118
+ const tokenEntity = this.getAccessTokenCredential(key);
119
+ if (tokenEntity &&
120
+ this.credentialMatchesFilter(tokenEntity, accessTokenFilter)) {
121
+ const tokenScopeSet = ScopeSet.fromString(tokenEntity.target);
122
+ if (tokenScopeSet.intersectingScopeSets(currentScopes)) {
123
+ removedAccessTokens.push(this.removeAccessToken(key));
124
+ }
125
+ }
126
+ });
127
+ await Promise.all(removedAccessTokens);
128
+ this.setAccessTokenCredential(credential);
129
+ }
130
+ /**
131
+ * retrieve accounts matching all provided filters; if no filter is set, get all accounts
132
+ * not checking for casing as keys are all generated in lower case, remember to convert to lower case if object properties are compared
133
+ * @param homeAccountId
134
+ * @param environment
135
+ * @param realm
136
+ */
137
+ getAccountsFilteredBy(accountFilter) {
138
+ const allAccountKeys = this.getAccountKeys();
139
+ const matchingAccounts = [];
140
+ allAccountKeys.forEach((cacheKey) => {
141
+ if (!this.isAccountKey(cacheKey, accountFilter.homeAccountId, accountFilter.realm)) {
142
+ // Don't parse value if the key doesn't match the account filters
143
+ return;
144
+ }
145
+ const entity = this.getAccount(cacheKey);
146
+ if (!entity) {
147
+ return;
148
+ }
149
+ if (!!accountFilter.homeAccountId &&
150
+ !this.matchHomeAccountId(entity, accountFilter.homeAccountId)) {
151
+ return;
152
+ }
153
+ if (!!accountFilter.localAccountId &&
154
+ !this.matchLocalAccountId(entity, accountFilter.localAccountId)) {
155
+ return;
156
+ }
157
+ if (!!accountFilter.username &&
158
+ !this.matchUsername(entity, accountFilter.username)) {
159
+ return;
160
+ }
161
+ if (!!accountFilter.environment &&
162
+ !this.matchEnvironment(entity, accountFilter.environment)) {
163
+ return;
164
+ }
165
+ if (!!accountFilter.realm &&
166
+ !this.matchRealm(entity, accountFilter.realm)) {
167
+ return;
168
+ }
169
+ if (!!accountFilter.nativeAccountId &&
170
+ !this.matchNativeAccountId(entity, accountFilter.nativeAccountId)) {
171
+ return;
172
+ }
173
+ matchingAccounts.push(entity);
174
+ });
175
+ return matchingAccounts;
176
+ }
177
+ /**
178
+ * Returns true if the given key matches our account key schema. Also matches homeAccountId and/or tenantId if provided
179
+ * @param key
180
+ * @param homeAccountId
181
+ * @param tenantId
182
+ * @returns
183
+ */
184
+ isAccountKey(key, homeAccountId, tenantId) {
185
+ if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 3) {
186
+ // Account cache keys contain 3 items separated by '-' (each item may also contain '-')
187
+ return false;
188
+ }
189
+ if (homeAccountId &&
190
+ !key.toLowerCase().includes(homeAccountId.toLowerCase())) {
191
+ return false;
192
+ }
193
+ if (tenantId && !key.toLowerCase().includes(tenantId.toLowerCase())) {
194
+ return false;
195
+ }
196
+ // Do not check environment as aliasing can cause false negatives
197
+ return true;
198
+ }
199
+ /**
200
+ * Returns true if the given key matches our credential key schema.
201
+ * @param key
202
+ */
203
+ isCredentialKey(key) {
204
+ if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 6) {
205
+ // Credential cache keys contain 6 items separated by '-' (each item may also contain '-')
206
+ return false;
207
+ }
208
+ const lowerCaseKey = key.toLowerCase();
209
+ // Credential keys must indicate what credential type they represent
210
+ if (lowerCaseKey.indexOf(CredentialType.ID_TOKEN.toLowerCase()) ===
211
+ -1 &&
212
+ lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN.toLowerCase()) ===
213
+ -1 &&
214
+ lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()) === -1 &&
215
+ lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) ===
216
+ -1) {
217
+ return false;
218
+ }
219
+ if (lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) >
220
+ -1) {
221
+ // Refresh tokens must contain the client id or family id
222
+ const clientIdValidation = `${CredentialType.REFRESH_TOKEN}${Separators.CACHE_KEY_SEPARATOR}${this.clientId}${Separators.CACHE_KEY_SEPARATOR}`;
223
+ const familyIdValidation = `${CredentialType.REFRESH_TOKEN}${Separators.CACHE_KEY_SEPARATOR}${THE_FAMILY_ID}${Separators.CACHE_KEY_SEPARATOR}`;
224
+ if (lowerCaseKey.indexOf(clientIdValidation.toLowerCase()) === -1 &&
225
+ lowerCaseKey.indexOf(familyIdValidation.toLowerCase()) === -1) {
226
+ return false;
227
+ }
228
+ }
229
+ else if (lowerCaseKey.indexOf(this.clientId.toLowerCase()) === -1) {
230
+ // Tokens must contain the clientId
231
+ return false;
232
+ }
233
+ return true;
234
+ }
235
+ /**
236
+ * Returns whether or not the given credential entity matches the filter
237
+ * @param entity
238
+ * @param filter
239
+ * @returns
240
+ */
241
+ credentialMatchesFilter(entity, filter) {
242
+ if (!!filter.clientId && !this.matchClientId(entity, filter.clientId)) {
243
+ return false;
244
+ }
245
+ if (!!filter.userAssertionHash &&
246
+ !this.matchUserAssertionHash(entity, filter.userAssertionHash)) {
247
+ return false;
248
+ }
249
+ /*
250
+ * homeAccountId can be undefined, and we want to filter out cached items that have a homeAccountId of ""
251
+ * because we don't want a client_credential request to return a cached token that has a homeAccountId
252
+ */
253
+ if (typeof filter.homeAccountId === "string" &&
254
+ !this.matchHomeAccountId(entity, filter.homeAccountId)) {
255
+ return false;
256
+ }
257
+ if (!!filter.environment &&
258
+ !this.matchEnvironment(entity, filter.environment)) {
259
+ return false;
260
+ }
261
+ if (!!filter.realm && !this.matchRealm(entity, filter.realm)) {
262
+ return false;
263
+ }
264
+ if (!!filter.credentialType &&
265
+ !this.matchCredentialType(entity, filter.credentialType)) {
266
+ return false;
267
+ }
268
+ if (!!filter.familyId && !this.matchFamilyId(entity, filter.familyId)) {
269
+ return false;
270
+ }
271
+ /*
272
+ * idTokens do not have "target", target specific refreshTokens do exist for some types of authentication
273
+ * Resource specific refresh tokens case will be added when the support is deemed necessary
274
+ */
275
+ if (!!filter.target && !this.matchTarget(entity, filter.target)) {
276
+ return false;
277
+ }
278
+ // If request OR cached entity has requested Claims Hash, check if they match
279
+ if (filter.requestedClaimsHash || entity.requestedClaimsHash) {
280
+ // Don't match if either is undefined or they are different
281
+ if (entity.requestedClaimsHash !== filter.requestedClaimsHash) {
282
+ return false;
283
+ }
284
+ }
285
+ // Access Token with Auth Scheme specific matching
286
+ if (entity.credentialType ===
287
+ CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
288
+ if (!!filter.tokenType &&
289
+ !this.matchTokenType(entity, filter.tokenType)) {
290
+ return false;
291
+ }
292
+ // KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
293
+ if (filter.tokenType === AuthenticationScheme.SSH) {
294
+ if (filter.keyId && !this.matchKeyId(entity, filter.keyId)) {
295
+ return false;
296
+ }
297
+ }
298
+ }
299
+ return true;
300
+ }
301
+ /**
302
+ * retrieve appMetadata matching all provided filters; if no filter is set, get all appMetadata
303
+ * @param filter
304
+ */
305
+ getAppMetadataFilteredBy(filter) {
306
+ return this.getAppMetadataFilteredByInternal(filter.environment, filter.clientId);
307
+ }
308
+ /**
309
+ * Support function to help match appMetadata
310
+ * @param environment
311
+ * @param clientId
312
+ */
313
+ getAppMetadataFilteredByInternal(environment, clientId) {
314
+ const allCacheKeys = this.getKeys();
315
+ const matchingAppMetadata = {};
316
+ allCacheKeys.forEach((cacheKey) => {
317
+ // don't parse any non-appMetadata type cache entities
318
+ if (!this.isAppMetadata(cacheKey)) {
319
+ return;
320
+ }
321
+ // Attempt retrieval
322
+ const entity = this.getAppMetadata(cacheKey);
323
+ if (!entity) {
324
+ return;
325
+ }
326
+ if (!!environment && !this.matchEnvironment(entity, environment)) {
327
+ return;
328
+ }
329
+ if (!!clientId && !this.matchClientId(entity, clientId)) {
330
+ return;
331
+ }
332
+ matchingAppMetadata[cacheKey] = entity;
333
+ });
334
+ return matchingAppMetadata;
335
+ }
336
+ /**
337
+ * retrieve authorityMetadata that contains a matching alias
338
+ * @param filter
339
+ */
340
+ getAuthorityMetadataByAlias(host) {
341
+ const allCacheKeys = this.getAuthorityMetadataKeys();
342
+ let matchedEntity = null;
343
+ allCacheKeys.forEach((cacheKey) => {
344
+ // don't parse any non-authorityMetadata type cache entities
345
+ if (!this.isAuthorityMetadata(cacheKey) ||
346
+ cacheKey.indexOf(this.clientId) === -1) {
347
+ return;
348
+ }
349
+ // Attempt retrieval
350
+ const entity = this.getAuthorityMetadata(cacheKey);
351
+ if (!entity) {
352
+ return;
353
+ }
354
+ if (entity.aliases.indexOf(host) === -1) {
355
+ return;
356
+ }
357
+ matchedEntity = entity;
358
+ });
359
+ return matchedEntity;
360
+ }
361
+ /**
362
+ * Removes all accounts and related tokens from cache.
363
+ */
364
+ async removeAllAccounts() {
365
+ const allAccountKeys = this.getAccountKeys();
366
+ const removedAccounts = [];
367
+ allAccountKeys.forEach((cacheKey) => {
368
+ removedAccounts.push(this.removeAccount(cacheKey));
369
+ });
370
+ await Promise.all(removedAccounts);
371
+ }
372
+ /**
373
+ * Removes the account and related tokens for a given account key
374
+ * @param account
375
+ */
376
+ async removeAccount(accountKey) {
377
+ const account = this.getAccount(accountKey);
378
+ if (!account) {
379
+ return;
380
+ }
381
+ await this.removeAccountContext(account);
382
+ this.removeItem(accountKey);
383
+ }
384
+ /**
385
+ * Removes credentials associated with the provided account
386
+ * @param account
387
+ */
388
+ async removeAccountContext(account) {
389
+ const allTokenKeys = this.getTokenKeys();
390
+ const accountId = account.generateAccountId();
391
+ const removedCredentials = [];
392
+ allTokenKeys.idToken.forEach((key) => {
393
+ if (key.indexOf(accountId) === 0) {
394
+ this.removeIdToken(key);
395
+ }
396
+ });
397
+ allTokenKeys.accessToken.forEach((key) => {
398
+ if (key.indexOf(accountId) === 0) {
399
+ removedCredentials.push(this.removeAccessToken(key));
400
+ }
401
+ });
402
+ allTokenKeys.refreshToken.forEach((key) => {
403
+ if (key.indexOf(accountId) === 0) {
404
+ this.removeRefreshToken(key);
405
+ }
406
+ });
407
+ await Promise.all(removedCredentials);
408
+ }
409
+ /**
410
+ * returns a boolean if the given credential is removed
411
+ * @param credential
412
+ */
413
+ async removeAccessToken(key) {
414
+ const credential = this.getAccessTokenCredential(key);
415
+ if (!credential) {
416
+ return;
417
+ }
418
+ // Remove Token Binding Key from key store for PoP Tokens Credentials
419
+ if (credential.credentialType.toLowerCase() ===
420
+ CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()) {
421
+ if (credential.tokenType === AuthenticationScheme.POP) {
422
+ const accessTokenWithAuthSchemeEntity = credential;
423
+ const kid = accessTokenWithAuthSchemeEntity.keyId;
424
+ if (kid) {
425
+ try {
426
+ await this.cryptoImpl.removeTokenBindingKey(kid);
427
+ }
428
+ catch (error) {
429
+ throw createClientAuthError(bindingKeyNotRemoved);
430
+ }
431
+ }
432
+ }
433
+ }
434
+ return this.removeItem(key);
435
+ }
436
+ /**
437
+ * Removes all app metadata objects from cache.
438
+ */
439
+ removeAppMetadata() {
440
+ const allCacheKeys = this.getKeys();
441
+ allCacheKeys.forEach((cacheKey) => {
442
+ if (this.isAppMetadata(cacheKey)) {
443
+ this.removeItem(cacheKey);
444
+ }
445
+ });
446
+ return true;
447
+ }
448
+ /**
449
+ * Retrieve the cached credentials into a cacherecord
450
+ * @param account
451
+ * @param clientId
452
+ * @param scopes
453
+ * @param environment
454
+ * @param authScheme
455
+ */
456
+ readCacheRecord(account, request, environment) {
457
+ const tokenKeys = this.getTokenKeys();
458
+ const cachedAccount = this.readAccountFromCache(account);
459
+ const cachedIdToken = this.getIdToken(account, tokenKeys);
460
+ const cachedAccessToken = this.getAccessToken(account, request, tokenKeys);
461
+ const cachedRefreshToken = this.getRefreshToken(account, false, tokenKeys);
462
+ const cachedAppMetadata = this.readAppMetadataFromCache(environment);
463
+ if (cachedAccount && cachedIdToken) {
464
+ cachedAccount.idTokenClaims = extractTokenClaims(cachedIdToken.secret, this.cryptoImpl.base64Decode);
465
+ }
466
+ return {
467
+ account: cachedAccount,
468
+ idToken: cachedIdToken,
469
+ accessToken: cachedAccessToken,
470
+ refreshToken: cachedRefreshToken,
471
+ appMetadata: cachedAppMetadata,
472
+ };
473
+ }
474
+ /**
475
+ * Retrieve AccountEntity from cache
476
+ * @param account
477
+ */
478
+ readAccountFromCache(account) {
479
+ const accountKey = AccountEntity.generateAccountCacheKey(account);
480
+ return this.getAccount(accountKey);
481
+ }
482
+ /**
483
+ * Retrieve IdTokenEntity from cache
484
+ * @param clientId
485
+ * @param account
486
+ * @param inputRealm
487
+ */
488
+ getIdToken(account, tokenKeys) {
489
+ this.commonLogger.trace("CacheManager - getIdToken called");
490
+ const idTokenFilter = {
491
+ homeAccountId: account.homeAccountId,
492
+ environment: account.environment,
493
+ credentialType: CredentialType.ID_TOKEN,
494
+ clientId: this.clientId,
495
+ realm: account.tenantId,
496
+ };
497
+ const idTokens = this.getIdTokensByFilter(idTokenFilter, tokenKeys);
498
+ const numIdTokens = idTokens.length;
499
+ if (numIdTokens < 1) {
500
+ this.commonLogger.info("CacheManager:getIdToken - No token found");
501
+ return null;
502
+ }
503
+ else if (numIdTokens > 1) {
504
+ this.commonLogger.info("CacheManager:getIdToken - Multiple id tokens found, clearing them");
505
+ idTokens.forEach((idToken) => {
506
+ this.removeIdToken(idToken.generateCredentialKey());
507
+ });
508
+ return null;
509
+ }
510
+ this.commonLogger.info("CacheManager:getIdToken - Returning id token");
511
+ return idTokens[0];
512
+ }
513
+ /**
514
+ * Gets all idTokens matching the given filter
515
+ * @param filter
516
+ * @returns
517
+ */
518
+ getIdTokensByFilter(filter, tokenKeys) {
519
+ const idTokenKeys = (tokenKeys && tokenKeys.idToken) || this.getTokenKeys().idToken;
520
+ const idTokens = [];
521
+ idTokenKeys.forEach((key) => {
522
+ if (!this.idTokenKeyMatchesFilter(key, {
523
+ clientId: this.clientId,
524
+ ...filter,
525
+ })) {
526
+ return;
527
+ }
528
+ const idToken = this.getIdTokenCredential(key);
529
+ if (idToken && this.credentialMatchesFilter(idToken, filter)) {
530
+ idTokens.push(idToken);
531
+ }
532
+ });
533
+ return idTokens;
534
+ }
535
+ /**
536
+ * Validate the cache key against filter before retrieving and parsing cache value
537
+ * @param key
538
+ * @param filter
539
+ * @returns
540
+ */
541
+ idTokenKeyMatchesFilter(inputKey, filter) {
542
+ const key = inputKey.toLowerCase();
543
+ if (filter.clientId &&
544
+ key.indexOf(filter.clientId.toLowerCase()) === -1) {
545
+ return false;
546
+ }
547
+ if (filter.homeAccountId &&
548
+ key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
549
+ return false;
550
+ }
551
+ return true;
552
+ }
553
+ /**
554
+ * Removes idToken from the cache
555
+ * @param key
556
+ */
557
+ removeIdToken(key) {
558
+ this.removeItem(key);
559
+ }
560
+ /**
561
+ * Removes refresh token from the cache
562
+ * @param key
563
+ */
564
+ removeRefreshToken(key) {
565
+ this.removeItem(key);
566
+ }
567
+ /**
568
+ * Retrieve AccessTokenEntity from cache
569
+ * @param clientId
570
+ * @param account
571
+ * @param scopes
572
+ * @param authScheme
573
+ */
574
+ getAccessToken(account, request, tokenKeys) {
575
+ this.commonLogger.trace("CacheManager - getAccessToken called");
576
+ const scopes = ScopeSet.createSearchScopes(request.scopes);
577
+ const authScheme = request.authenticationScheme || AuthenticationScheme.BEARER;
578
+ /*
579
+ * Distinguish between Bearer and PoP/SSH token cache types
580
+ * Cast to lowercase to handle "bearer" from ADFS
581
+ */
582
+ const credentialType = authScheme &&
583
+ authScheme.toLowerCase() !==
584
+ AuthenticationScheme.BEARER.toLowerCase()
585
+ ? CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME
586
+ : CredentialType.ACCESS_TOKEN;
587
+ const accessTokenFilter = {
588
+ homeAccountId: account.homeAccountId,
589
+ environment: account.environment,
590
+ credentialType: credentialType,
591
+ clientId: this.clientId,
592
+ realm: account.tenantId,
593
+ target: scopes,
594
+ tokenType: authScheme,
595
+ keyId: request.sshKid,
596
+ requestedClaimsHash: request.requestedClaimsHash,
597
+ };
598
+ const accessTokenKeys = (tokenKeys && tokenKeys.accessToken) ||
599
+ this.getTokenKeys().accessToken;
600
+ const accessTokens = [];
601
+ accessTokenKeys.forEach((key) => {
602
+ // Validate key
603
+ if (this.accessTokenKeyMatchesFilter(key, accessTokenFilter, true)) {
604
+ const accessToken = this.getAccessTokenCredential(key);
605
+ // Validate value
606
+ if (accessToken &&
607
+ this.credentialMatchesFilter(accessToken, accessTokenFilter)) {
608
+ accessTokens.push(accessToken);
609
+ }
610
+ }
611
+ });
612
+ const numAccessTokens = accessTokens.length;
613
+ if (numAccessTokens < 1) {
614
+ this.commonLogger.info("CacheManager:getAccessToken - No token found");
615
+ return null;
616
+ }
617
+ else if (numAccessTokens > 1) {
618
+ this.commonLogger.info("CacheManager:getAccessToken - Multiple access tokens found, clearing them");
619
+ accessTokens.forEach((accessToken) => {
620
+ void this.removeAccessToken(accessToken.generateCredentialKey());
621
+ });
622
+ return null;
623
+ }
624
+ this.commonLogger.info("CacheManager:getAccessToken - Returning access token");
625
+ return accessTokens[0];
626
+ }
627
+ /**
628
+ * Validate the cache key against filter before retrieving and parsing cache value
629
+ * @param key
630
+ * @param filter
631
+ * @param keyMustContainAllScopes
632
+ * @returns
633
+ */
634
+ accessTokenKeyMatchesFilter(inputKey, filter, keyMustContainAllScopes) {
635
+ const key = inputKey.toLowerCase();
636
+ if (filter.clientId &&
637
+ key.indexOf(filter.clientId.toLowerCase()) === -1) {
638
+ return false;
639
+ }
640
+ if (filter.homeAccountId &&
641
+ key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
642
+ return false;
643
+ }
644
+ if (filter.realm && key.indexOf(filter.realm.toLowerCase()) === -1) {
645
+ return false;
646
+ }
647
+ if (filter.requestedClaimsHash &&
648
+ key.indexOf(filter.requestedClaimsHash.toLowerCase()) === -1) {
649
+ return false;
650
+ }
651
+ if (filter.target) {
652
+ const scopes = filter.target.asArray();
653
+ for (let i = 0; i < scopes.length; i++) {
654
+ if (keyMustContainAllScopes &&
655
+ !key.includes(scopes[i].toLowerCase())) {
656
+ // When performing a cache lookup a missing scope would be a cache miss
657
+ return false;
658
+ }
659
+ else if (!keyMustContainAllScopes &&
660
+ key.includes(scopes[i].toLowerCase())) {
661
+ // When performing a cache write, any token with a subset of requested scopes should be replaced
662
+ return true;
663
+ }
664
+ }
665
+ }
666
+ return true;
667
+ }
668
+ /**
669
+ * Gets all access tokens matching the filter
670
+ * @param filter
671
+ * @returns
672
+ */
673
+ getAccessTokensByFilter(filter) {
674
+ const tokenKeys = this.getTokenKeys();
675
+ const accessTokens = [];
676
+ tokenKeys.accessToken.forEach((key) => {
677
+ if (!this.accessTokenKeyMatchesFilter(key, filter, true)) {
678
+ return;
679
+ }
680
+ const accessToken = this.getAccessTokenCredential(key);
681
+ if (accessToken &&
682
+ this.credentialMatchesFilter(accessToken, filter)) {
683
+ accessTokens.push(accessToken);
684
+ }
685
+ });
686
+ return accessTokens;
687
+ }
688
+ /**
689
+ * Helper to retrieve the appropriate refresh token from cache
690
+ * @param clientId
691
+ * @param account
692
+ * @param familyRT
693
+ */
694
+ getRefreshToken(account, familyRT, tokenKeys) {
695
+ this.commonLogger.trace("CacheManager - getRefreshToken called");
696
+ const id = familyRT ? THE_FAMILY_ID : undefined;
697
+ const refreshTokenFilter = {
698
+ homeAccountId: account.homeAccountId,
699
+ environment: account.environment,
700
+ credentialType: CredentialType.REFRESH_TOKEN,
701
+ clientId: this.clientId,
702
+ familyId: id,
703
+ };
704
+ const refreshTokenKeys = (tokenKeys && tokenKeys.refreshToken) ||
705
+ this.getTokenKeys().refreshToken;
706
+ const refreshTokens = [];
707
+ refreshTokenKeys.forEach((key) => {
708
+ // Validate key
709
+ if (this.refreshTokenKeyMatchesFilter(key, refreshTokenFilter)) {
710
+ const refreshToken = this.getRefreshTokenCredential(key);
711
+ // Validate value
712
+ if (refreshToken &&
713
+ this.credentialMatchesFilter(refreshToken, refreshTokenFilter)) {
714
+ refreshTokens.push(refreshToken);
715
+ }
716
+ }
717
+ });
718
+ const numRefreshTokens = refreshTokens.length;
719
+ if (numRefreshTokens < 1) {
720
+ this.commonLogger.info("CacheManager:getRefreshToken - No refresh token found.");
721
+ return null;
722
+ }
723
+ // address the else case after remove functions address environment aliases
724
+ this.commonLogger.info("CacheManager:getRefreshToken - returning refresh token");
725
+ return refreshTokens[0];
726
+ }
727
+ /**
728
+ * Validate the cache key against filter before retrieving and parsing cache value
729
+ * @param key
730
+ * @param filter
731
+ */
732
+ refreshTokenKeyMatchesFilter(inputKey, filter) {
733
+ const key = inputKey.toLowerCase();
734
+ if (filter.familyId &&
735
+ key.indexOf(filter.familyId.toLowerCase()) === -1) {
736
+ return false;
737
+ }
738
+ // If familyId is used, clientId is not in the key
739
+ if (!filter.familyId &&
740
+ filter.clientId &&
741
+ key.indexOf(filter.clientId.toLowerCase()) === -1) {
742
+ return false;
743
+ }
744
+ if (filter.homeAccountId &&
745
+ key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
746
+ return false;
747
+ }
748
+ return true;
749
+ }
750
+ /**
751
+ * Retrieve AppMetadataEntity from cache
752
+ */
753
+ readAppMetadataFromCache(environment) {
754
+ const appMetadataFilter = {
755
+ environment,
756
+ clientId: this.clientId,
757
+ };
758
+ const appMetadata = this.getAppMetadataFilteredBy(appMetadataFilter);
759
+ const appMetadataEntries = Object.keys(appMetadata).map((key) => appMetadata[key]);
760
+ const numAppMetadata = appMetadataEntries.length;
761
+ if (numAppMetadata < 1) {
762
+ return null;
763
+ }
764
+ else if (numAppMetadata > 1) {
765
+ throw createClientAuthError(multipleMatchingAppMetadata);
766
+ }
767
+ return appMetadataEntries[0];
768
+ }
769
+ /**
770
+ * Return the family_id value associated with FOCI
771
+ * @param environment
772
+ * @param clientId
773
+ */
774
+ isAppMetadataFOCI(environment) {
775
+ const appMetadata = this.readAppMetadataFromCache(environment);
776
+ return !!(appMetadata && appMetadata.familyId === THE_FAMILY_ID);
777
+ }
778
+ /**
779
+ * helper to match account ids
780
+ * @param value
781
+ * @param homeAccountId
782
+ */
783
+ matchHomeAccountId(entity, homeAccountId) {
784
+ return !!(typeof entity.homeAccountId === "string" &&
785
+ homeAccountId === entity.homeAccountId);
786
+ }
787
+ /**
788
+ * helper to match account ids
789
+ * @param entity
790
+ * @param localAccountId
791
+ * @returns
792
+ */
793
+ matchLocalAccountId(entity, localAccountId) {
794
+ return !!(typeof entity.localAccountId === "string" &&
795
+ localAccountId === entity.localAccountId);
796
+ }
797
+ /**
798
+ * helper to match usernames
799
+ * @param entity
800
+ * @param username
801
+ * @returns
802
+ */
803
+ matchUsername(entity, username) {
804
+ return !!(typeof entity.username === "string" &&
805
+ username.toLowerCase() === entity.username.toLowerCase());
806
+ }
807
+ /**
808
+ * helper to match assertion
809
+ * @param value
810
+ * @param oboAssertion
811
+ */
812
+ matchUserAssertionHash(entity, userAssertionHash) {
813
+ return !!(entity.userAssertionHash &&
814
+ userAssertionHash === entity.userAssertionHash);
815
+ }
816
+ /**
817
+ * helper to match environment
818
+ * @param value
819
+ * @param environment
820
+ */
821
+ matchEnvironment(entity, environment) {
822
+ const cloudMetadata = this.getAuthorityMetadataByAlias(environment);
823
+ if (cloudMetadata &&
824
+ cloudMetadata.aliases.indexOf(entity.environment) > -1) {
825
+ return true;
826
+ }
827
+ return false;
828
+ }
829
+ /**
830
+ * helper to match credential type
831
+ * @param entity
832
+ * @param credentialType
833
+ */
834
+ matchCredentialType(entity, credentialType) {
835
+ return (entity.credentialType &&
836
+ credentialType.toLowerCase() === entity.credentialType.toLowerCase());
837
+ }
838
+ /**
839
+ * helper to match client ids
840
+ * @param entity
841
+ * @param clientId
842
+ */
843
+ matchClientId(entity, clientId) {
844
+ return !!(entity.clientId && clientId === entity.clientId);
845
+ }
846
+ /**
847
+ * helper to match family ids
848
+ * @param entity
849
+ * @param familyId
850
+ */
851
+ matchFamilyId(entity, familyId) {
852
+ return !!(entity.familyId && familyId === entity.familyId);
853
+ }
854
+ /**
855
+ * helper to match realm
856
+ * @param entity
857
+ * @param realm
858
+ */
859
+ matchRealm(entity, realm) {
860
+ return !!(entity.realm && realm === entity.realm);
861
+ }
862
+ /**
863
+ * helper to match nativeAccountId
864
+ * @param entity
865
+ * @param nativeAccountId
866
+ * @returns boolean indicating the match result
867
+ */
868
+ matchNativeAccountId(entity, nativeAccountId) {
869
+ return !!(entity.nativeAccountId && nativeAccountId === entity.nativeAccountId);
870
+ }
871
+ /**
872
+ * Returns true if the target scopes are a subset of the current entity's scopes, false otherwise.
873
+ * @param entity
874
+ * @param target
875
+ */
876
+ matchTarget(entity, target) {
877
+ const isNotAccessTokenCredential = entity.credentialType !== CredentialType.ACCESS_TOKEN &&
878
+ entity.credentialType !==
879
+ CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;
880
+ if (isNotAccessTokenCredential || !entity.target) {
881
+ return false;
882
+ }
883
+ const entityScopeSet = ScopeSet.fromString(entity.target);
884
+ return entityScopeSet.containsScopeSet(target);
885
+ }
886
+ /**
887
+ * Returns true if the credential's tokenType or Authentication Scheme matches the one in the request, false otherwise
888
+ * @param entity
889
+ * @param tokenType
890
+ */
891
+ matchTokenType(entity, tokenType) {
892
+ return !!(entity.tokenType && entity.tokenType === tokenType);
893
+ }
894
+ /**
895
+ * Returns true if the credential's keyId matches the one in the request, false otherwise
896
+ * @param entity
897
+ * @param tokenType
898
+ */
899
+ matchKeyId(entity, keyId) {
900
+ return !!(entity.keyId && entity.keyId === keyId);
901
+ }
902
+ /**
903
+ * returns if a given cache entity is of the type appmetadata
904
+ * @param key
905
+ */
906
+ isAppMetadata(key) {
907
+ return key.indexOf(APP_METADATA) !== -1;
908
+ }
909
+ /**
910
+ * returns if a given cache entity is of the type authoritymetadata
911
+ * @param key
912
+ */
913
+ isAuthorityMetadata(key) {
914
+ return key.indexOf(AUTHORITY_METADATA_CONSTANTS.CACHE_KEY) !== -1;
915
+ }
916
+ /**
917
+ * returns cache key used for cloud instance metadata
918
+ */
919
+ generateAuthorityMetadataCacheKey(authority) {
920
+ return `${AUTHORITY_METADATA_CONSTANTS.CACHE_KEY}-${this.clientId}-${authority}`;
921
+ }
922
+ /**
923
+ * Helper to convert serialized data to object
924
+ * @param obj
925
+ * @param json
926
+ */
927
+ static toObject(obj, json) {
928
+ for (const propertyName in json) {
929
+ obj[propertyName] = json[propertyName];
930
+ }
931
+ return obj;
932
+ }
933
+ }
934
+ /** @internal */
935
+ class DefaultStorageClass extends CacheManager {
936
+ setAccount() {
937
+ throw createClientAuthError(methodNotImplemented);
938
+ }
939
+ getAccount() {
940
+ throw createClientAuthError(methodNotImplemented);
941
+ }
942
+ setIdTokenCredential() {
943
+ throw createClientAuthError(methodNotImplemented);
944
+ }
945
+ getIdTokenCredential() {
946
+ throw createClientAuthError(methodNotImplemented);
947
+ }
948
+ setAccessTokenCredential() {
949
+ throw createClientAuthError(methodNotImplemented);
950
+ }
951
+ getAccessTokenCredential() {
952
+ throw createClientAuthError(methodNotImplemented);
953
+ }
954
+ setRefreshTokenCredential() {
955
+ throw createClientAuthError(methodNotImplemented);
956
+ }
957
+ getRefreshTokenCredential() {
958
+ throw createClientAuthError(methodNotImplemented);
959
+ }
960
+ setAppMetadata() {
961
+ throw createClientAuthError(methodNotImplemented);
962
+ }
963
+ getAppMetadata() {
964
+ throw createClientAuthError(methodNotImplemented);
965
+ }
966
+ setServerTelemetry() {
967
+ throw createClientAuthError(methodNotImplemented);
968
+ }
969
+ getServerTelemetry() {
970
+ throw createClientAuthError(methodNotImplemented);
971
+ }
972
+ setAuthorityMetadata() {
973
+ throw createClientAuthError(methodNotImplemented);
974
+ }
975
+ getAuthorityMetadata() {
976
+ throw createClientAuthError(methodNotImplemented);
977
+ }
978
+ getAuthorityMetadataKeys() {
979
+ throw createClientAuthError(methodNotImplemented);
980
+ }
981
+ setThrottlingCache() {
982
+ throw createClientAuthError(methodNotImplemented);
983
+ }
984
+ getThrottlingCache() {
985
+ throw createClientAuthError(methodNotImplemented);
986
+ }
987
+ removeItem() {
988
+ throw createClientAuthError(methodNotImplemented);
989
+ }
990
+ containsKey() {
991
+ throw createClientAuthError(methodNotImplemented);
992
+ }
993
+ getKeys() {
994
+ throw createClientAuthError(methodNotImplemented);
995
+ }
996
+ getAccountKeys() {
997
+ throw createClientAuthError(methodNotImplemented);
998
+ }
999
+ getTokenKeys() {
1000
+ throw createClientAuthError(methodNotImplemented);
1001
+ }
1002
+ async clear() {
1003
+ throw createClientAuthError(methodNotImplemented);
1004
+ }
1005
+ updateCredentialCacheKey() {
1006
+ throw createClientAuthError(methodNotImplemented);
1007
+ }
1032
1008
  }
1033
1009
 
1034
1010
  export { CacheManager, DefaultStorageClass };