@azure/msal-common 13.0.0 → 14.0.0-alpha.2

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