@azure/msal-common 0.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (333) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -0
  3. package/dist/_virtual/_tslib.js +90 -0
  4. package/dist/_virtual/_tslib.js.map +1 -0
  5. package/dist/account/AccountInfo.d.ts +30 -0
  6. package/dist/account/AccountInfo.d.ts.map +1 -0
  7. package/dist/account/AuthToken.d.ts +17 -0
  8. package/dist/account/AuthToken.d.ts.map +1 -0
  9. package/dist/account/AuthToken.js +43 -0
  10. package/dist/account/AuthToken.js.map +1 -0
  11. package/dist/account/CcsCredential.d.ts +9 -0
  12. package/dist/account/CcsCredential.d.ts.map +1 -0
  13. package/dist/account/CcsCredential.js +14 -0
  14. package/dist/account/CcsCredential.js.map +1 -0
  15. package/dist/account/ClientCredentials.d.ts +15 -0
  16. package/dist/account/ClientCredentials.d.ts.map +1 -0
  17. package/dist/account/ClientInfo.d.ts +20 -0
  18. package/dist/account/ClientInfo.d.ts.map +1 -0
  19. package/dist/account/ClientInfo.js +44 -0
  20. package/dist/account/ClientInfo.js.map +1 -0
  21. package/dist/account/DecodedAuthToken.d.ts +9 -0
  22. package/dist/account/DecodedAuthToken.d.ts.map +1 -0
  23. package/dist/account/TokenClaims.d.ts +60 -0
  24. package/dist/account/TokenClaims.d.ts.map +1 -0
  25. package/dist/authority/Authority.d.ts +200 -0
  26. package/dist/authority/Authority.d.ts.map +1 -0
  27. package/dist/authority/Authority.js +678 -0
  28. package/dist/authority/Authority.js.map +1 -0
  29. package/dist/authority/AuthorityFactory.d.ts +29 -0
  30. package/dist/authority/AuthorityFactory.d.ts.map +1 -0
  31. package/dist/authority/AuthorityFactory.js +69 -0
  32. package/dist/authority/AuthorityFactory.js.map +1 -0
  33. package/dist/authority/AuthorityMetadata.d.ts +623 -0
  34. package/dist/authority/AuthorityMetadata.d.ts.map +1 -0
  35. package/dist/authority/AuthorityMetadata.js +12 -0
  36. package/dist/authority/AuthorityMetadata.js.map +1 -0
  37. package/dist/authority/AuthorityOptions.d.ts +19 -0
  38. package/dist/authority/AuthorityOptions.d.ts.map +1 -0
  39. package/dist/authority/AuthorityOptions.js +24 -0
  40. package/dist/authority/AuthorityOptions.js.map +1 -0
  41. package/dist/authority/AuthorityType.d.ts +8 -0
  42. package/dist/authority/AuthorityType.d.ts.map +1 -0
  43. package/dist/authority/AuthorityType.js +17 -0
  44. package/dist/authority/AuthorityType.js.map +1 -0
  45. package/dist/authority/AzureRegion.d.ts +2 -0
  46. package/dist/authority/AzureRegion.d.ts.map +1 -0
  47. package/dist/authority/AzureRegionConfiguration.d.ts +6 -0
  48. package/dist/authority/AzureRegionConfiguration.d.ts.map +1 -0
  49. package/dist/authority/CloudDiscoveryMetadata.d.ts +6 -0
  50. package/dist/authority/CloudDiscoveryMetadata.d.ts.map +1 -0
  51. package/dist/authority/CloudInstanceDiscoveryResponse.d.ts +10 -0
  52. package/dist/authority/CloudInstanceDiscoveryResponse.d.ts.map +1 -0
  53. package/dist/authority/CloudInstanceDiscoveryResponse.js +13 -0
  54. package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -0
  55. package/dist/authority/ImdsOptions.d.ts +7 -0
  56. package/dist/authority/ImdsOptions.d.ts.map +1 -0
  57. package/dist/authority/OpenIdConfigResponse.d.ts +12 -0
  58. package/dist/authority/OpenIdConfigResponse.d.ts.map +1 -0
  59. package/dist/authority/OpenIdConfigResponse.js +15 -0
  60. package/dist/authority/OpenIdConfigResponse.js.map +1 -0
  61. package/dist/authority/ProtocolMode.d.ts +8 -0
  62. package/dist/authority/ProtocolMode.d.ts.map +1 -0
  63. package/dist/authority/ProtocolMode.js +17 -0
  64. package/dist/authority/ProtocolMode.js.map +1 -0
  65. package/dist/authority/RegionDiscovery.d.ts +28 -0
  66. package/dist/authority/RegionDiscovery.d.ts.map +1 -0
  67. package/dist/authority/RegionDiscovery.js +127 -0
  68. package/dist/authority/RegionDiscovery.js.map +1 -0
  69. package/dist/authority/RegionDiscoveryMetadata.d.ts +7 -0
  70. package/dist/authority/RegionDiscoveryMetadata.d.ts.map +1 -0
  71. package/dist/cache/CacheManager.d.ts +393 -0
  72. package/dist/cache/CacheManager.d.ts.map +1 -0
  73. package/dist/cache/CacheManager.js +885 -0
  74. package/dist/cache/CacheManager.js.map +1 -0
  75. package/dist/cache/entities/AccessTokenEntity.d.ts +57 -0
  76. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -0
  77. package/dist/cache/entities/AccessTokenEntity.js +124 -0
  78. package/dist/cache/entities/AccessTokenEntity.js.map +1 -0
  79. package/dist/cache/entities/AccountEntity.d.ts +100 -0
  80. package/dist/cache/entities/AccountEntity.d.ts.map +1 -0
  81. package/dist/cache/entities/AccountEntity.js +243 -0
  82. package/dist/cache/entities/AccountEntity.js.map +1 -0
  83. package/dist/cache/entities/AppMetadataEntity.d.ts +40 -0
  84. package/dist/cache/entities/AppMetadataEntity.d.ts.map +1 -0
  85. package/dist/cache/entities/AppMetadataEntity.js +74 -0
  86. package/dist/cache/entities/AppMetadataEntity.js.map +1 -0
  87. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +48 -0
  88. package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -0
  89. package/dist/cache/entities/AuthorityMetadataEntity.js +82 -0
  90. package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -0
  91. package/dist/cache/entities/CacheRecord.d.ts +14 -0
  92. package/dist/cache/entities/CacheRecord.d.ts.map +1 -0
  93. package/dist/cache/entities/CacheRecord.js +19 -0
  94. package/dist/cache/entities/CacheRecord.js.map +1 -0
  95. package/dist/cache/entities/CredentialEntity.d.ts +94 -0
  96. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -0
  97. package/dist/cache/entities/CredentialEntity.js +164 -0
  98. package/dist/cache/entities/CredentialEntity.js.map +1 -0
  99. package/dist/cache/entities/IdTokenEntity.d.ts +35 -0
  100. package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -0
  101. package/dist/cache/entities/IdTokenEntity.js +70 -0
  102. package/dist/cache/entities/IdTokenEntity.js.map +1 -0
  103. package/dist/cache/entities/RefreshTokenEntity.d.ts +37 -0
  104. package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -0
  105. package/dist/cache/entities/RefreshTokenEntity.js +73 -0
  106. package/dist/cache/entities/RefreshTokenEntity.js.map +1 -0
  107. package/dist/cache/entities/ServerTelemetryEntity.d.ts +13 -0
  108. package/dist/cache/entities/ServerTelemetryEntity.d.ts.map +1 -0
  109. package/dist/cache/entities/ServerTelemetryEntity.js +35 -0
  110. package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -0
  111. package/dist/cache/entities/ThrottlingEntity.d.ts +14 -0
  112. package/dist/cache/entities/ThrottlingEntity.d.ts.map +1 -0
  113. package/dist/cache/entities/ThrottlingEntity.js +32 -0
  114. package/dist/cache/entities/ThrottlingEntity.js.map +1 -0
  115. package/dist/cache/interface/ICacheManager.d.ts +157 -0
  116. package/dist/cache/interface/ICacheManager.d.ts.map +1 -0
  117. package/dist/cache/interface/ICachePlugin.d.ts +6 -0
  118. package/dist/cache/interface/ICachePlugin.d.ts.map +1 -0
  119. package/dist/cache/interface/ISerializableTokenCache.d.ts +5 -0
  120. package/dist/cache/interface/ISerializableTokenCache.d.ts.map +1 -0
  121. package/dist/cache/persistence/TokenCacheContext.d.ts +24 -0
  122. package/dist/cache/persistence/TokenCacheContext.d.ts.map +1 -0
  123. package/dist/cache/persistence/TokenCacheContext.js +39 -0
  124. package/dist/cache/persistence/TokenCacheContext.js.map +1 -0
  125. package/dist/cache/utils/CacheTypes.d.ts +60 -0
  126. package/dist/cache/utils/CacheTypes.d.ts.map +1 -0
  127. package/dist/client/AuthorizationCodeClient.d.ts +76 -0
  128. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -0
  129. package/dist/client/AuthorizationCodeClient.js +468 -0
  130. package/dist/client/AuthorizationCodeClient.js.map +1 -0
  131. package/dist/client/BaseClient.d.ts +45 -0
  132. package/dist/client/BaseClient.d.ts.map +1 -0
  133. package/dist/client/BaseClient.js +103 -0
  134. package/dist/client/BaseClient.js.map +1 -0
  135. package/dist/client/ClientCredentialClient.d.ts +39 -0
  136. package/dist/client/ClientCredentialClient.d.ts.map +1 -0
  137. package/dist/client/ClientCredentialClient.js +202 -0
  138. package/dist/client/ClientCredentialClient.js.map +1 -0
  139. package/dist/client/DeviceCodeClient.d.ts +52 -0
  140. package/dist/client/DeviceCodeClient.d.ts.map +1 -0
  141. package/dist/client/DeviceCodeClient.js +232 -0
  142. package/dist/client/DeviceCodeClient.js.map +1 -0
  143. package/dist/client/OnBehalfOfClient.d.ts +51 -0
  144. package/dist/client/OnBehalfOfClient.d.ts.map +1 -0
  145. package/dist/client/OnBehalfOfClient.js +244 -0
  146. package/dist/client/OnBehalfOfClient.js.map +1 -0
  147. package/dist/client/RefreshTokenClient.d.ts +40 -0
  148. package/dist/client/RefreshTokenClient.d.ts.map +1 -0
  149. package/dist/client/RefreshTokenClient.js +255 -0
  150. package/dist/client/RefreshTokenClient.js.map +1 -0
  151. package/dist/client/SilentFlowClient.d.ts +25 -0
  152. package/dist/client/SilentFlowClient.d.ts.map +1 -0
  153. package/dist/client/SilentFlowClient.js +128 -0
  154. package/dist/client/SilentFlowClient.js.map +1 -0
  155. package/dist/client/UsernamePasswordClient.d.ts +29 -0
  156. package/dist/client/UsernamePasswordClient.d.ts.map +1 -0
  157. package/dist/client/UsernamePasswordClient.js +120 -0
  158. package/dist/client/UsernamePasswordClient.js.map +1 -0
  159. package/dist/config/AppTokenProvider.d.ts +39 -0
  160. package/dist/config/AppTokenProvider.d.ts.map +1 -0
  161. package/dist/config/ClientConfiguration.d.ts +135 -0
  162. package/dist/config/ClientConfiguration.d.ts.map +1 -0
  163. package/dist/config/ClientConfiguration.js +105 -0
  164. package/dist/config/ClientConfiguration.js.map +1 -0
  165. package/dist/crypto/ICrypto.d.ts +63 -0
  166. package/dist/crypto/ICrypto.d.ts.map +1 -0
  167. package/dist/crypto/ICrypto.js +80 -0
  168. package/dist/crypto/ICrypto.js.map +1 -0
  169. package/dist/crypto/IGuidGenerator.d.ts +5 -0
  170. package/dist/crypto/IGuidGenerator.d.ts.map +1 -0
  171. package/dist/crypto/JoseHeader.d.ts +22 -0
  172. package/dist/crypto/JoseHeader.d.ts.map +1 -0
  173. package/dist/crypto/JoseHeader.js +45 -0
  174. package/dist/crypto/JoseHeader.js.map +1 -0
  175. package/dist/crypto/PopTokenGenerator.d.ts +56 -0
  176. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -0
  177. package/dist/crypto/PopTokenGenerator.js +107 -0
  178. package/dist/crypto/PopTokenGenerator.js.map +1 -0
  179. package/dist/crypto/SignedHttpRequest.d.ts +12 -0
  180. package/dist/crypto/SignedHttpRequest.d.ts.map +1 -0
  181. package/dist/error/AuthError.d.ts +48 -0
  182. package/dist/error/AuthError.d.ts.map +1 -0
  183. package/dist/error/AuthError.js +61 -0
  184. package/dist/error/AuthError.js.map +1 -0
  185. package/dist/error/ClientAuthError.d.ts +372 -0
  186. package/dist/error/ClientAuthError.d.ts.map +1 -0
  187. package/dist/error/ClientAuthError.js +477 -0
  188. package/dist/error/ClientAuthError.js.map +1 -0
  189. package/dist/error/ClientConfigurationError.d.ts +199 -0
  190. package/dist/error/ClientConfigurationError.d.ts.map +1 -0
  191. package/dist/error/ClientConfigurationError.js +260 -0
  192. package/dist/error/ClientConfigurationError.js.map +1 -0
  193. package/dist/error/InteractionRequiredAuthError.d.ts +42 -0
  194. package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -0
  195. package/dist/error/InteractionRequiredAuthError.js +80 -0
  196. package/dist/error/InteractionRequiredAuthError.js.map +1 -0
  197. package/dist/error/JoseHeaderError.d.ts +29 -0
  198. package/dist/error/JoseHeaderError.d.ts.map +1 -0
  199. package/dist/error/JoseHeaderError.js +50 -0
  200. package/dist/error/JoseHeaderError.js.map +1 -0
  201. package/dist/error/ServerError.d.ts +8 -0
  202. package/dist/error/ServerError.d.ts.map +1 -0
  203. package/dist/error/ServerError.js +25 -0
  204. package/dist/error/ServerError.js.map +1 -0
  205. package/dist/index.cjs.js +8441 -0
  206. package/dist/index.cjs.js.map +1 -0
  207. package/dist/index.d.ts +90 -0
  208. package/dist/index.d.ts.map +1 -0
  209. package/dist/index.js +53 -0
  210. package/dist/index.js.map +1 -0
  211. package/dist/logger/Logger.d.ts +95 -0
  212. package/dist/logger/Logger.d.ts.map +1 -0
  213. package/dist/logger/Logger.js +185 -0
  214. package/dist/logger/Logger.js.map +1 -0
  215. package/dist/network/INetworkModule.d.ts +31 -0
  216. package/dist/network/INetworkModule.d.ts.map +1 -0
  217. package/dist/network/INetworkModule.js +21 -0
  218. package/dist/network/INetworkModule.js.map +1 -0
  219. package/dist/network/NetworkManager.d.ts +21 -0
  220. package/dist/network/NetworkManager.d.ts.map +1 -0
  221. package/dist/network/NetworkManager.js +56 -0
  222. package/dist/network/NetworkManager.js.map +1 -0
  223. package/dist/network/RequestThumbprint.d.ts +17 -0
  224. package/dist/network/RequestThumbprint.d.ts.map +1 -0
  225. package/dist/network/ThrottlingUtils.d.ts +42 -0
  226. package/dist/network/ThrottlingUtils.d.ts.map +1 -0
  227. package/dist/network/ThrottlingUtils.js +101 -0
  228. package/dist/network/ThrottlingUtils.js.map +1 -0
  229. package/dist/packageMetadata.d.ts +3 -0
  230. package/dist/packageMetadata.d.ts.map +1 -0
  231. package/dist/packageMetadata.js +8 -0
  232. package/dist/packageMetadata.js.map +1 -0
  233. package/dist/request/AuthenticationHeaderParser.d.ts +20 -0
  234. package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -0
  235. package/dist/request/AuthenticationHeaderParser.js +64 -0
  236. package/dist/request/AuthenticationHeaderParser.js.map +1 -0
  237. package/dist/request/BaseAuthRequest.d.ts +34 -0
  238. package/dist/request/BaseAuthRequest.d.ts.map +1 -0
  239. package/dist/request/CommonAuthorizationCodeRequest.d.ts +28 -0
  240. package/dist/request/CommonAuthorizationCodeRequest.d.ts.map +1 -0
  241. package/dist/request/CommonAuthorizationUrlRequest.d.ts +51 -0
  242. package/dist/request/CommonAuthorizationUrlRequest.d.ts.map +1 -0
  243. package/dist/request/CommonClientCredentialRequest.d.ts +17 -0
  244. package/dist/request/CommonClientCredentialRequest.d.ts.map +1 -0
  245. package/dist/request/CommonDeviceCodeRequest.d.ts +19 -0
  246. package/dist/request/CommonDeviceCodeRequest.d.ts.map +1 -0
  247. package/dist/request/CommonEndSessionRequest.d.ts +21 -0
  248. package/dist/request/CommonEndSessionRequest.d.ts.map +1 -0
  249. package/dist/request/CommonOnBehalfOfRequest.d.ts +13 -0
  250. package/dist/request/CommonOnBehalfOfRequest.d.ts.map +1 -0
  251. package/dist/request/CommonRefreshTokenRequest.d.ts +21 -0
  252. package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -0
  253. package/dist/request/CommonSilentFlowRequest.d.ts +20 -0
  254. package/dist/request/CommonSilentFlowRequest.d.ts.map +1 -0
  255. package/dist/request/CommonUsernamePasswordRequest.d.ts +17 -0
  256. package/dist/request/CommonUsernamePasswordRequest.d.ts.map +1 -0
  257. package/dist/request/RequestParameterBuilder.d.ts +217 -0
  258. package/dist/request/RequestParameterBuilder.d.ts.map +1 -0
  259. package/dist/request/RequestParameterBuilder.js +387 -0
  260. package/dist/request/RequestParameterBuilder.js.map +1 -0
  261. package/dist/request/RequestValidator.d.ts +34 -0
  262. package/dist/request/RequestValidator.d.ts.map +1 -0
  263. package/dist/request/RequestValidator.js +92 -0
  264. package/dist/request/RequestValidator.js.map +1 -0
  265. package/dist/request/ScopeSet.d.ts +83 -0
  266. package/dist/request/ScopeSet.d.ts.map +1 -0
  267. package/dist/request/ScopeSet.js +192 -0
  268. package/dist/request/ScopeSet.js.map +1 -0
  269. package/dist/response/AuthenticationResult.d.ts +38 -0
  270. package/dist/response/AuthenticationResult.d.ts.map +1 -0
  271. package/dist/response/AuthorizationCodePayload.d.ts +14 -0
  272. package/dist/response/AuthorizationCodePayload.d.ts.map +1 -0
  273. package/dist/response/DeviceCodeResponse.d.ts +26 -0
  274. package/dist/response/DeviceCodeResponse.d.ts.map +1 -0
  275. package/dist/response/ExternalTokenResponse.d.ts +15 -0
  276. package/dist/response/ExternalTokenResponse.d.ts.map +1 -0
  277. package/dist/response/IMDSBadResponse.d.ts +5 -0
  278. package/dist/response/IMDSBadResponse.d.ts.map +1 -0
  279. package/dist/response/ResponseHandler.d.ts +71 -0
  280. package/dist/response/ResponseHandler.d.ts.map +1 -0
  281. package/dist/response/ResponseHandler.js +293 -0
  282. package/dist/response/ResponseHandler.js.map +1 -0
  283. package/dist/response/ServerAuthorizationCodeResponse.d.ts +22 -0
  284. package/dist/response/ServerAuthorizationCodeResponse.d.ts.map +1 -0
  285. package/dist/response/ServerAuthorizationTokenResponse.d.ts +43 -0
  286. package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -0
  287. package/dist/telemetry/performance/IPerformanceClient.d.ts +22 -0
  288. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -0
  289. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +6 -0
  290. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts.map +1 -0
  291. package/dist/telemetry/performance/PerformanceClient.d.ts +125 -0
  292. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -0
  293. package/dist/telemetry/performance/PerformanceClient.js +281 -0
  294. package/dist/telemetry/performance/PerformanceClient.js.map +1 -0
  295. package/dist/telemetry/performance/PerformanceEvent.d.ts +249 -0
  296. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -0
  297. package/dist/telemetry/performance/PerformanceEvent.js +121 -0
  298. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -0
  299. package/dist/telemetry/performance/StubPerformanceClient.d.ts +13 -0
  300. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -0
  301. package/dist/telemetry/performance/StubPerformanceClient.js +37 -0
  302. package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -0
  303. package/dist/telemetry/server/ServerTelemetryManager.d.ts +67 -0
  304. package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -0
  305. package/dist/telemetry/server/ServerTelemetryManager.js +168 -0
  306. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -0
  307. package/dist/telemetry/server/ServerTelemetryRequest.d.ts +9 -0
  308. package/dist/telemetry/server/ServerTelemetryRequest.d.ts.map +1 -0
  309. package/dist/url/IUri.d.ts +13 -0
  310. package/dist/url/IUri.d.ts.map +1 -0
  311. package/dist/url/UrlString.d.ts +62 -0
  312. package/dist/url/UrlString.d.ts.map +1 -0
  313. package/dist/url/UrlString.js +208 -0
  314. package/dist/url/UrlString.js.map +1 -0
  315. package/dist/utils/Constants.d.ts +340 -0
  316. package/dist/utils/Constants.d.ts.map +1 -0
  317. package/dist/utils/Constants.js +381 -0
  318. package/dist/utils/Constants.js.map +1 -0
  319. package/dist/utils/MsalTypes.d.ts +7 -0
  320. package/dist/utils/MsalTypes.d.ts.map +1 -0
  321. package/dist/utils/ProtocolUtils.d.ts +43 -0
  322. package/dist/utils/ProtocolUtils.d.ts.map +1 -0
  323. package/dist/utils/ProtocolUtils.js +77 -0
  324. package/dist/utils/ProtocolUtils.js.map +1 -0
  325. package/dist/utils/StringUtils.d.ts +54 -0
  326. package/dist/utils/StringUtils.d.ts.map +1 -0
  327. package/dist/utils/StringUtils.js +129 -0
  328. package/dist/utils/StringUtils.js.map +1 -0
  329. package/dist/utils/TimeUtils.d.ts +28 -0
  330. package/dist/utils/TimeUtils.d.ts.map +1 -0
  331. package/dist/utils/TimeUtils.js +53 -0
  332. package/dist/utils/TimeUtils.js.map +1 -0
  333. package/package.json +76 -0
@@ -0,0 +1,885 @@
1
+ /*! @azure/msal-common v0.0.1-alpha.0 2022-08-02 */
2
+ 'use strict';
3
+ import { __awaiter, __generator, __extends } from '../_virtual/_tslib.js';
4
+ import { Constants, CredentialType, AuthenticationScheme, CacheSchemaType, THE_FAMILY_ID, APP_METADATA, AUTHORITY_METADATA_CONSTANTS } from '../utils/Constants.js';
5
+ import { CredentialEntity } from './entities/CredentialEntity.js';
6
+ import { ScopeSet } from '../request/ScopeSet.js';
7
+ import { AccountEntity } from './entities/AccountEntity.js';
8
+ import { AuthError } from '../error/AuthError.js';
9
+ import { ClientAuthError } from '../error/ClientAuthError.js';
10
+ import { AuthToken } from '../account/AuthToken.js';
11
+
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) {
21
+ this.clientId = clientId;
22
+ this.cryptoImpl = cryptoImpl;
23
+ }
24
+ /**
25
+ * Returns all accounts in cache
26
+ */
27
+ CacheManager.prototype.getAllAccounts = function () {
28
+ var _this = this;
29
+ var currentAccounts = this.getAccountsFilteredBy();
30
+ var accountValues = Object.keys(currentAccounts).map(function (accountKey) { return currentAccounts[accountKey]; });
31
+ var numAccounts = accountValues.length;
32
+ if (numAccounts < 1) {
33
+ return [];
34
+ }
35
+ else {
36
+ var allAccounts = accountValues.map(function (value) {
37
+ var accountEntity = CacheManager.toObject(new AccountEntity(), value);
38
+ var accountInfo = accountEntity.getAccountInfo();
39
+ var idToken = _this.readIdTokenFromCache(_this.clientId, accountInfo);
40
+ if (idToken && !accountInfo.idTokenClaims) {
41
+ accountInfo.idTokenClaims = new AuthToken(idToken.secret, _this.cryptoImpl).claims;
42
+ }
43
+ return accountInfo;
44
+ });
45
+ return allAccounts;
46
+ }
47
+ };
48
+ /**
49
+ * saves a cache record
50
+ * @param cacheRecord
51
+ */
52
+ CacheManager.prototype.saveCacheRecord = function (cacheRecord) {
53
+ return __awaiter(this, void 0, void 0, function () {
54
+ return __generator(this, function (_a) {
55
+ switch (_a.label) {
56
+ case 0:
57
+ if (!cacheRecord) {
58
+ throw ClientAuthError.createNullOrUndefinedCacheRecord();
59
+ }
60
+ if (!!cacheRecord.account) {
61
+ this.setAccount(cacheRecord.account);
62
+ }
63
+ if (!!cacheRecord.idToken) {
64
+ this.setIdTokenCredential(cacheRecord.idToken);
65
+ }
66
+ if (!!!cacheRecord.accessToken) return [3 /*break*/, 2];
67
+ return [4 /*yield*/, this.saveAccessToken(cacheRecord.accessToken)];
68
+ case 1:
69
+ _a.sent();
70
+ _a.label = 2;
71
+ case 2:
72
+ if (!!cacheRecord.refreshToken) {
73
+ this.setRefreshTokenCredential(cacheRecord.refreshToken);
74
+ }
75
+ if (!!cacheRecord.appMetadata) {
76
+ this.setAppMetadata(cacheRecord.appMetadata);
77
+ }
78
+ return [2 /*return*/];
79
+ }
80
+ });
81
+ });
82
+ };
83
+ /**
84
+ * saves access token credential
85
+ * @param credential
86
+ */
87
+ CacheManager.prototype.saveAccessToken = function (credential) {
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ var currentTokenCache, currentScopes, currentAccessTokens, removedAccessTokens_1;
90
+ var _this = this;
91
+ return __generator(this, function (_a) {
92
+ switch (_a.label) {
93
+ case 0:
94
+ currentTokenCache = this.getCredentialsFilteredBy({
95
+ clientId: credential.clientId,
96
+ credentialType: credential.credentialType,
97
+ environment: credential.environment,
98
+ homeAccountId: credential.homeAccountId,
99
+ realm: credential.realm,
100
+ tokenType: credential.tokenType,
101
+ requestedClaimsHash: credential.requestedClaimsHash
102
+ });
103
+ currentScopes = ScopeSet.fromString(credential.target);
104
+ currentAccessTokens = Object.keys(currentTokenCache.accessTokens).map(function (key) { return currentTokenCache.accessTokens[key]; });
105
+ if (!currentAccessTokens) return [3 /*break*/, 2];
106
+ removedAccessTokens_1 = [];
107
+ currentAccessTokens.forEach(function (tokenEntity) {
108
+ var tokenScopeSet = ScopeSet.fromString(tokenEntity.target);
109
+ if (tokenScopeSet.intersectingScopeSets(currentScopes)) {
110
+ removedAccessTokens_1.push(_this.removeCredential(tokenEntity));
111
+ }
112
+ });
113
+ return [4 /*yield*/, Promise.all(removedAccessTokens_1)];
114
+ case 1:
115
+ _a.sent();
116
+ _a.label = 2;
117
+ case 2:
118
+ this.setAccessTokenCredential(credential);
119
+ return [2 /*return*/];
120
+ }
121
+ });
122
+ });
123
+ };
124
+ /**
125
+ * retrieve accounts matching all provided filters; if no filter is set, get all accounts
126
+ * not checking for casing as keys are all generated in lower case, remember to convert to lower case if object properties are compared
127
+ * @param homeAccountId
128
+ * @param environment
129
+ * @param realm
130
+ */
131
+ CacheManager.prototype.getAccountsFilteredBy = function (accountFilter) {
132
+ return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : Constants.EMPTY_STRING, accountFilter ? accountFilter.environment : Constants.EMPTY_STRING, accountFilter ? accountFilter.realm : Constants.EMPTY_STRING, accountFilter ? accountFilter.nativeAccountId : Constants.EMPTY_STRING);
133
+ };
134
+ /**
135
+ * retrieve accounts matching all provided filters; if no filter is set, get all accounts
136
+ * not checking for casing as keys are all generated in lower case, remember to convert to lower case if object properties are compared
137
+ * @param homeAccountId
138
+ * @param environment
139
+ * @param realm
140
+ */
141
+ CacheManager.prototype.getAccountsFilteredByInternal = function (homeAccountId, environment, realm, nativeAccountId) {
142
+ var _this = this;
143
+ var allCacheKeys = this.getKeys();
144
+ var matchingAccounts = {};
145
+ allCacheKeys.forEach(function (cacheKey) {
146
+ var entity = _this.getAccount(cacheKey);
147
+ if (!entity) {
148
+ return;
149
+ }
150
+ if (!!homeAccountId && !_this.matchHomeAccountId(entity, homeAccountId)) {
151
+ return;
152
+ }
153
+ if (!!environment && !_this.matchEnvironment(entity, environment)) {
154
+ return;
155
+ }
156
+ if (!!realm && !_this.matchRealm(entity, realm)) {
157
+ return;
158
+ }
159
+ if (!!nativeAccountId && !_this.matchNativeAccountId(entity, nativeAccountId)) {
160
+ return;
161
+ }
162
+ matchingAccounts[cacheKey] = entity;
163
+ });
164
+ return matchingAccounts;
165
+ };
166
+ /**
167
+ * retrieve credentails matching all provided filters; if no filter is set, get all credentials
168
+ * @param homeAccountId
169
+ * @param environment
170
+ * @param credentialType
171
+ * @param clientId
172
+ * @param realm
173
+ * @param target
174
+ */
175
+ CacheManager.prototype.getCredentialsFilteredBy = function (filter) {
176
+ return this.getCredentialsFilteredByInternal(filter.homeAccountId, filter.environment, filter.credentialType, filter.clientId, filter.familyId, filter.realm, filter.target, filter.userAssertionHash, filter.tokenType, filter.keyId, filter.requestedClaimsHash);
177
+ };
178
+ /**
179
+ * Support function to help match credentials
180
+ * @param homeAccountId
181
+ * @param environment
182
+ * @param credentialType
183
+ * @param clientId
184
+ * @param realm
185
+ * @param target
186
+ * @param userAssertionHash
187
+ * @param tokenType
188
+ */
189
+ CacheManager.prototype.getCredentialsFilteredByInternal = function (homeAccountId, environment, credentialType, clientId, familyId, realm, target, userAssertionHash, tokenType, keyId, requestedClaimsHash) {
190
+ var _this = this;
191
+ var allCacheKeys = this.getKeys();
192
+ var matchingCredentials = {
193
+ idTokens: {},
194
+ accessTokens: {},
195
+ refreshTokens: {},
196
+ };
197
+ allCacheKeys.forEach(function (cacheKey) {
198
+ // don't parse any non-credential type cache entities
199
+ var credType = CredentialEntity.getCredentialType(cacheKey);
200
+ if (credType === Constants.NOT_DEFINED) {
201
+ return;
202
+ }
203
+ // Attempt retrieval
204
+ var entity = _this.getSpecificCredential(cacheKey, credType);
205
+ if (!entity) {
206
+ return;
207
+ }
208
+ if (!!userAssertionHash && !_this.matchUserAssertionHash(entity, userAssertionHash)) {
209
+ return;
210
+ }
211
+ if (!!homeAccountId && !_this.matchHomeAccountId(entity, homeAccountId)) {
212
+ return;
213
+ }
214
+ if (!!environment && !_this.matchEnvironment(entity, environment)) {
215
+ return;
216
+ }
217
+ if (!!realm && !_this.matchRealm(entity, realm)) {
218
+ return;
219
+ }
220
+ if (!!credentialType && !_this.matchCredentialType(entity, credentialType)) {
221
+ return;
222
+ }
223
+ if (!!clientId && !_this.matchClientId(entity, clientId)) {
224
+ return;
225
+ }
226
+ if (!!familyId && !_this.matchFamilyId(entity, familyId)) {
227
+ return;
228
+ }
229
+ /*
230
+ * idTokens do not have "target", target specific refreshTokens do exist for some types of authentication
231
+ * Resource specific refresh tokens case will be added when the support is deemed necessary
232
+ */
233
+ if (!!target && !_this.matchTarget(entity, target)) {
234
+ return;
235
+ }
236
+ // If request OR cached entity has requested Claims Hash, check if they match
237
+ if (requestedClaimsHash || entity.requestedClaimsHash) {
238
+ // Don't match if either is undefined or they are different
239
+ if (entity.requestedClaimsHash !== requestedClaimsHash) {
240
+ return;
241
+ }
242
+ }
243
+ // Access Token with Auth Scheme specific matching
244
+ if (credentialType === CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
245
+ if (!!tokenType && !_this.matchTokenType(entity, tokenType)) {
246
+ return;
247
+ }
248
+ // KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
249
+ if (tokenType === AuthenticationScheme.SSH) {
250
+ if (keyId && !_this.matchKeyId(entity, keyId)) {
251
+ return;
252
+ }
253
+ }
254
+ }
255
+ // At this point, the entity matches the request, update cache key if key schema has changed
256
+ var updatedCacheKey = _this.updateCredentialCacheKey(cacheKey, entity);
257
+ switch (credType) {
258
+ case CredentialType.ID_TOKEN:
259
+ matchingCredentials.idTokens[updatedCacheKey] = entity;
260
+ break;
261
+ case CredentialType.ACCESS_TOKEN:
262
+ case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
263
+ matchingCredentials.accessTokens[updatedCacheKey] = entity;
264
+ break;
265
+ case CredentialType.REFRESH_TOKEN:
266
+ matchingCredentials.refreshTokens[updatedCacheKey] = entity;
267
+ break;
268
+ }
269
+ });
270
+ return matchingCredentials;
271
+ };
272
+ /**
273
+ * retrieve appMetadata matching all provided filters; if no filter is set, get all appMetadata
274
+ * @param filter
275
+ */
276
+ CacheManager.prototype.getAppMetadataFilteredBy = function (filter) {
277
+ return this.getAppMetadataFilteredByInternal(filter.environment, filter.clientId);
278
+ };
279
+ /**
280
+ * Support function to help match appMetadata
281
+ * @param environment
282
+ * @param clientId
283
+ */
284
+ CacheManager.prototype.getAppMetadataFilteredByInternal = function (environment, clientId) {
285
+ var _this = this;
286
+ var allCacheKeys = this.getKeys();
287
+ var matchingAppMetadata = {};
288
+ allCacheKeys.forEach(function (cacheKey) {
289
+ // don't parse any non-appMetadata type cache entities
290
+ if (!_this.isAppMetadata(cacheKey)) {
291
+ return;
292
+ }
293
+ // Attempt retrieval
294
+ var entity = _this.getAppMetadata(cacheKey);
295
+ if (!entity) {
296
+ return;
297
+ }
298
+ if (!!environment && !_this.matchEnvironment(entity, environment)) {
299
+ return;
300
+ }
301
+ if (!!clientId && !_this.matchClientId(entity, clientId)) {
302
+ return;
303
+ }
304
+ matchingAppMetadata[cacheKey] = entity;
305
+ });
306
+ return matchingAppMetadata;
307
+ };
308
+ /**
309
+ * retrieve authorityMetadata that contains a matching alias
310
+ * @param filter
311
+ */
312
+ CacheManager.prototype.getAuthorityMetadataByAlias = function (host) {
313
+ var _this = this;
314
+ var allCacheKeys = this.getAuthorityMetadataKeys();
315
+ var matchedEntity = null;
316
+ allCacheKeys.forEach(function (cacheKey) {
317
+ // don't parse any non-authorityMetadata type cache entities
318
+ if (!_this.isAuthorityMetadata(cacheKey) || cacheKey.indexOf(_this.clientId) === -1) {
319
+ return;
320
+ }
321
+ // Attempt retrieval
322
+ var entity = _this.getAuthorityMetadata(cacheKey);
323
+ if (!entity) {
324
+ return;
325
+ }
326
+ if (entity.aliases.indexOf(host) === -1) {
327
+ return;
328
+ }
329
+ matchedEntity = entity;
330
+ });
331
+ return matchedEntity;
332
+ };
333
+ /**
334
+ * Removes all accounts and related tokens from cache.
335
+ */
336
+ CacheManager.prototype.removeAllAccounts = function () {
337
+ return __awaiter(this, void 0, void 0, function () {
338
+ var allCacheKeys, removedAccounts;
339
+ var _this = this;
340
+ return __generator(this, function (_a) {
341
+ switch (_a.label) {
342
+ case 0:
343
+ allCacheKeys = this.getKeys();
344
+ removedAccounts = [];
345
+ allCacheKeys.forEach(function (cacheKey) {
346
+ var entity = _this.getAccount(cacheKey);
347
+ if (!entity) {
348
+ return;
349
+ }
350
+ removedAccounts.push(_this.removeAccount(cacheKey));
351
+ });
352
+ return [4 /*yield*/, Promise.all(removedAccounts)];
353
+ case 1:
354
+ _a.sent();
355
+ return [2 /*return*/, true];
356
+ }
357
+ });
358
+ });
359
+ };
360
+ /**
361
+ * returns a boolean if the given account is removed
362
+ * @param account
363
+ */
364
+ CacheManager.prototype.removeAccount = function (accountKey) {
365
+ return __awaiter(this, void 0, void 0, function () {
366
+ var account;
367
+ return __generator(this, function (_a) {
368
+ switch (_a.label) {
369
+ case 0:
370
+ account = this.getAccount(accountKey);
371
+ if (!account) {
372
+ throw ClientAuthError.createNoAccountFoundError();
373
+ }
374
+ return [4 /*yield*/, this.removeAccountContext(account)];
375
+ case 1: return [2 /*return*/, ((_a.sent()) && this.removeItem(accountKey, CacheSchemaType.ACCOUNT))];
376
+ }
377
+ });
378
+ });
379
+ };
380
+ /**
381
+ * Removes credentials associated with the provided account
382
+ * @param account
383
+ */
384
+ CacheManager.prototype.removeAccountContext = function (account) {
385
+ return __awaiter(this, void 0, void 0, function () {
386
+ var allCacheKeys, accountId, removedCredentials;
387
+ var _this = this;
388
+ return __generator(this, function (_a) {
389
+ switch (_a.label) {
390
+ case 0:
391
+ allCacheKeys = this.getKeys();
392
+ accountId = account.generateAccountId();
393
+ removedCredentials = [];
394
+ allCacheKeys.forEach(function (cacheKey) {
395
+ // don't parse any non-credential type cache entities
396
+ var credType = CredentialEntity.getCredentialType(cacheKey);
397
+ if (credType === Constants.NOT_DEFINED) {
398
+ return;
399
+ }
400
+ var cacheEntity = _this.getSpecificCredential(cacheKey, credType);
401
+ if (!!cacheEntity && accountId === cacheEntity.generateAccountId()) {
402
+ removedCredentials.push(_this.removeCredential(cacheEntity));
403
+ }
404
+ });
405
+ return [4 /*yield*/, Promise.all(removedCredentials)];
406
+ case 1:
407
+ _a.sent();
408
+ return [2 /*return*/, true];
409
+ }
410
+ });
411
+ });
412
+ };
413
+ /**
414
+ * returns a boolean if the given credential is removed
415
+ * @param credential
416
+ */
417
+ CacheManager.prototype.removeCredential = function (credential) {
418
+ return __awaiter(this, void 0, void 0, function () {
419
+ var key, accessTokenWithAuthSchemeEntity, kid;
420
+ return __generator(this, function (_a) {
421
+ switch (_a.label) {
422
+ case 0:
423
+ key = credential.generateCredentialKey();
424
+ if (!(credential.credentialType.toLowerCase() === CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase())) return [3 /*break*/, 4];
425
+ if (!(credential.tokenType === AuthenticationScheme.POP)) return [3 /*break*/, 4];
426
+ accessTokenWithAuthSchemeEntity = credential;
427
+ kid = accessTokenWithAuthSchemeEntity.keyId;
428
+ if (!kid) return [3 /*break*/, 4];
429
+ _a.label = 1;
430
+ case 1:
431
+ _a.trys.push([1, 3, , 4]);
432
+ return [4 /*yield*/, this.cryptoImpl.removeTokenBindingKey(kid)];
433
+ case 2:
434
+ _a.sent();
435
+ return [3 /*break*/, 4];
436
+ case 3:
437
+ _a.sent();
438
+ throw ClientAuthError.createBindingKeyNotRemovedError();
439
+ case 4: return [2 /*return*/, this.removeItem(key, CacheSchemaType.CREDENTIAL)];
440
+ }
441
+ });
442
+ });
443
+ };
444
+ /**
445
+ * Removes all app metadata objects from cache.
446
+ */
447
+ CacheManager.prototype.removeAppMetadata = function () {
448
+ var _this = this;
449
+ var allCacheKeys = this.getKeys();
450
+ allCacheKeys.forEach(function (cacheKey) {
451
+ if (_this.isAppMetadata(cacheKey)) {
452
+ _this.removeItem(cacheKey, CacheSchemaType.APP_METADATA);
453
+ }
454
+ });
455
+ return true;
456
+ };
457
+ /**
458
+ * Retrieve the cached credentials into a cacherecord
459
+ * @param account
460
+ * @param clientId
461
+ * @param scopes
462
+ * @param environment
463
+ * @param authScheme
464
+ */
465
+ CacheManager.prototype.readCacheRecord = function (account, clientId, request, environment) {
466
+ var cachedAccount = this.readAccountFromCache(account);
467
+ var cachedIdToken = this.readIdTokenFromCache(clientId, account);
468
+ var cachedAccessToken = this.readAccessTokenFromCache(clientId, account, request);
469
+ var cachedRefreshToken = this.readRefreshTokenFromCache(clientId, account, false);
470
+ var cachedAppMetadata = this.readAppMetadataFromCache(environment, clientId);
471
+ if (cachedAccount && cachedIdToken) {
472
+ cachedAccount.idTokenClaims = new AuthToken(cachedIdToken.secret, this.cryptoImpl).claims;
473
+ }
474
+ return {
475
+ account: cachedAccount,
476
+ idToken: cachedIdToken,
477
+ accessToken: cachedAccessToken,
478
+ refreshToken: cachedRefreshToken,
479
+ appMetadata: cachedAppMetadata,
480
+ };
481
+ };
482
+ /**
483
+ * Retrieve AccountEntity from cache
484
+ * @param account
485
+ */
486
+ CacheManager.prototype.readAccountFromCache = function (account) {
487
+ var accountKey = AccountEntity.generateAccountCacheKey(account);
488
+ return this.getAccount(accountKey);
489
+ };
490
+ /**
491
+ * Retrieve AccountEntity from cache
492
+ * @param nativeAccountId
493
+ * @returns AccountEntity or Null
494
+ */
495
+ CacheManager.prototype.readAccountFromCacheWithNativeAccountId = function (nativeAccountId) {
496
+ // fetch account from memory
497
+ var accountFilter = {
498
+ nativeAccountId: nativeAccountId
499
+ };
500
+ var accountCache = this.getAccountsFilteredBy(accountFilter);
501
+ var accounts = Object.keys(accountCache).map(function (key) { return accountCache[key]; });
502
+ if (accounts.length < 1) {
503
+ return null;
504
+ }
505
+ else if (accounts.length > 1) {
506
+ throw ClientAuthError.createMultipleMatchingAccountsInCacheError();
507
+ }
508
+ return accountCache[0];
509
+ };
510
+ /**
511
+ * Retrieve IdTokenEntity from cache
512
+ * @param clientId
513
+ * @param account
514
+ * @param inputRealm
515
+ */
516
+ CacheManager.prototype.readIdTokenFromCache = function (clientId, account) {
517
+ var idTokenFilter = {
518
+ homeAccountId: account.homeAccountId,
519
+ environment: account.environment,
520
+ credentialType: CredentialType.ID_TOKEN,
521
+ clientId: clientId,
522
+ realm: account.tenantId,
523
+ };
524
+ var credentialCache = this.getCredentialsFilteredBy(idTokenFilter);
525
+ var idTokens = Object.keys(credentialCache.idTokens).map(function (key) { return credentialCache.idTokens[key]; });
526
+ var numIdTokens = idTokens.length;
527
+ if (numIdTokens < 1) {
528
+ return null;
529
+ }
530
+ else if (numIdTokens > 1) {
531
+ throw ClientAuthError.createMultipleMatchingTokensInCacheError();
532
+ }
533
+ return idTokens[0];
534
+ };
535
+ /**
536
+ * Retrieve AccessTokenEntity from cache
537
+ * @param clientId
538
+ * @param account
539
+ * @param scopes
540
+ * @param authScheme
541
+ */
542
+ CacheManager.prototype.readAccessTokenFromCache = function (clientId, account, request) {
543
+ var scopes = new ScopeSet(request.scopes || []);
544
+ var authScheme = request.authenticationScheme || AuthenticationScheme.BEARER;
545
+ /*
546
+ * Distinguish between Bearer and PoP/SSH token cache types
547
+ * Cast to lowercase to handle "bearer" from ADFS
548
+ */
549
+ var credentialType = (authScheme && authScheme.toLowerCase() !== AuthenticationScheme.BEARER.toLowerCase()) ? CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : CredentialType.ACCESS_TOKEN;
550
+ var accessTokenFilter = {
551
+ homeAccountId: account.homeAccountId,
552
+ environment: account.environment,
553
+ credentialType: credentialType,
554
+ clientId: clientId,
555
+ realm: account.tenantId,
556
+ target: scopes.printScopesLowerCase(),
557
+ tokenType: authScheme,
558
+ keyId: request.sshKid,
559
+ requestedClaimsHash: request.requestedClaimsHash,
560
+ };
561
+ var credentialCache = this.getCredentialsFilteredBy(accessTokenFilter);
562
+ var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
563
+ var numAccessTokens = accessTokens.length;
564
+ if (numAccessTokens < 1) {
565
+ return null;
566
+ }
567
+ else if (numAccessTokens > 1) {
568
+ throw ClientAuthError.createMultipleMatchingTokensInCacheError();
569
+ }
570
+ return accessTokens[0];
571
+ };
572
+ /**
573
+ * Helper to retrieve the appropriate refresh token from cache
574
+ * @param clientId
575
+ * @param account
576
+ * @param familyRT
577
+ */
578
+ CacheManager.prototype.readRefreshTokenFromCache = function (clientId, account, familyRT) {
579
+ var id = familyRT ? THE_FAMILY_ID : undefined;
580
+ var refreshTokenFilter = {
581
+ homeAccountId: account.homeAccountId,
582
+ environment: account.environment,
583
+ credentialType: CredentialType.REFRESH_TOKEN,
584
+ clientId: clientId,
585
+ familyId: id,
586
+ };
587
+ var credentialCache = this.getCredentialsFilteredBy(refreshTokenFilter);
588
+ var refreshTokens = Object.keys(credentialCache.refreshTokens).map(function (key) { return credentialCache.refreshTokens[key]; });
589
+ var numRefreshTokens = refreshTokens.length;
590
+ if (numRefreshTokens < 1) {
591
+ return null;
592
+ }
593
+ // address the else case after remove functions address environment aliases
594
+ return refreshTokens[0];
595
+ };
596
+ /**
597
+ * Retrieve AppMetadataEntity from cache
598
+ */
599
+ CacheManager.prototype.readAppMetadataFromCache = function (environment, clientId) {
600
+ var appMetadataFilter = {
601
+ environment: environment,
602
+ clientId: clientId,
603
+ };
604
+ var appMetadata = this.getAppMetadataFilteredBy(appMetadataFilter);
605
+ var appMetadataEntries = Object.keys(appMetadata).map(function (key) { return appMetadata[key]; });
606
+ var numAppMetadata = appMetadataEntries.length;
607
+ if (numAppMetadata < 1) {
608
+ return null;
609
+ }
610
+ else if (numAppMetadata > 1) {
611
+ throw ClientAuthError.createMultipleMatchingAppMetadataInCacheError();
612
+ }
613
+ return appMetadataEntries[0];
614
+ };
615
+ /**
616
+ * Return the family_id value associated with FOCI
617
+ * @param environment
618
+ * @param clientId
619
+ */
620
+ CacheManager.prototype.isAppMetadataFOCI = function (environment, clientId) {
621
+ var appMetadata = this.readAppMetadataFromCache(environment, clientId);
622
+ return !!(appMetadata && appMetadata.familyId === THE_FAMILY_ID);
623
+ };
624
+ /**
625
+ * helper to match account ids
626
+ * @param value
627
+ * @param homeAccountId
628
+ */
629
+ CacheManager.prototype.matchHomeAccountId = function (entity, homeAccountId) {
630
+ return !!(entity.homeAccountId && homeAccountId === entity.homeAccountId);
631
+ };
632
+ /**
633
+ * helper to match assertion
634
+ * @param value
635
+ * @param oboAssertion
636
+ */
637
+ CacheManager.prototype.matchUserAssertionHash = function (entity, userAssertionHash) {
638
+ return !!(entity.userAssertionHash && userAssertionHash === entity.userAssertionHash);
639
+ };
640
+ /**
641
+ * helper to match environment
642
+ * @param value
643
+ * @param environment
644
+ */
645
+ CacheManager.prototype.matchEnvironment = function (entity, environment) {
646
+ var cloudMetadata = this.getAuthorityMetadataByAlias(environment);
647
+ if (cloudMetadata && cloudMetadata.aliases.indexOf(entity.environment) > -1) {
648
+ return true;
649
+ }
650
+ return false;
651
+ };
652
+ /**
653
+ * helper to match credential type
654
+ * @param entity
655
+ * @param credentialType
656
+ */
657
+ CacheManager.prototype.matchCredentialType = function (entity, credentialType) {
658
+ return (entity.credentialType && credentialType.toLowerCase() === entity.credentialType.toLowerCase());
659
+ };
660
+ /**
661
+ * helper to match client ids
662
+ * @param entity
663
+ * @param clientId
664
+ */
665
+ CacheManager.prototype.matchClientId = function (entity, clientId) {
666
+ return !!(entity.clientId && clientId === entity.clientId);
667
+ };
668
+ /**
669
+ * helper to match family ids
670
+ * @param entity
671
+ * @param familyId
672
+ */
673
+ CacheManager.prototype.matchFamilyId = function (entity, familyId) {
674
+ return !!(entity.familyId && familyId === entity.familyId);
675
+ };
676
+ /**
677
+ * helper to match realm
678
+ * @param entity
679
+ * @param realm
680
+ */
681
+ CacheManager.prototype.matchRealm = function (entity, realm) {
682
+ return !!(entity.realm && realm === entity.realm);
683
+ };
684
+ /**
685
+ * helper to match nativeAccountId
686
+ * @param entity
687
+ * @param nativeAccountId
688
+ * @returns boolean indicating the match result
689
+ */
690
+ CacheManager.prototype.matchNativeAccountId = function (entity, nativeAccountId) {
691
+ return !!(entity.nativeAccountId && nativeAccountId === entity.nativeAccountId);
692
+ };
693
+ /**
694
+ * Returns true if the target scopes are a subset of the current entity's scopes, false otherwise.
695
+ * @param entity
696
+ * @param target
697
+ */
698
+ CacheManager.prototype.matchTarget = function (entity, target) {
699
+ var isNotAccessTokenCredential = (entity.credentialType !== CredentialType.ACCESS_TOKEN && entity.credentialType !== CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME);
700
+ if (isNotAccessTokenCredential || !entity.target) {
701
+ return false;
702
+ }
703
+ var entityScopeSet = ScopeSet.fromString(entity.target);
704
+ var requestTargetScopeSet = ScopeSet.fromString(target);
705
+ if (!requestTargetScopeSet.containsOnlyOIDCScopes()) {
706
+ requestTargetScopeSet.removeOIDCScopes(); // ignore OIDC scopes
707
+ }
708
+ else {
709
+ requestTargetScopeSet.removeScope(Constants.OFFLINE_ACCESS_SCOPE);
710
+ }
711
+ return entityScopeSet.containsScopeSet(requestTargetScopeSet);
712
+ };
713
+ /**
714
+ * Returns true if the credential's tokenType or Authentication Scheme matches the one in the request, false otherwise
715
+ * @param entity
716
+ * @param tokenType
717
+ */
718
+ CacheManager.prototype.matchTokenType = function (entity, tokenType) {
719
+ return !!(entity.tokenType && entity.tokenType === tokenType);
720
+ };
721
+ /**
722
+ * Returns true if the credential's keyId matches the one in the request, false otherwise
723
+ * @param entity
724
+ * @param tokenType
725
+ */
726
+ CacheManager.prototype.matchKeyId = function (entity, keyId) {
727
+ return !!(entity.keyId && entity.keyId === keyId);
728
+ };
729
+ /**
730
+ * returns if a given cache entity is of the type appmetadata
731
+ * @param key
732
+ */
733
+ CacheManager.prototype.isAppMetadata = function (key) {
734
+ return key.indexOf(APP_METADATA) !== -1;
735
+ };
736
+ /**
737
+ * returns if a given cache entity is of the type authoritymetadata
738
+ * @param key
739
+ */
740
+ CacheManager.prototype.isAuthorityMetadata = function (key) {
741
+ return key.indexOf(AUTHORITY_METADATA_CONSTANTS.CACHE_KEY) !== -1;
742
+ };
743
+ /**
744
+ * returns cache key used for cloud instance metadata
745
+ */
746
+ CacheManager.prototype.generateAuthorityMetadataCacheKey = function (authority) {
747
+ return AUTHORITY_METADATA_CONSTANTS.CACHE_KEY + "-" + this.clientId + "-" + authority;
748
+ };
749
+ /**
750
+ * Returns the specific credential (IdToken/AccessToken/RefreshToken) from the cache
751
+ * @param key
752
+ * @param credType
753
+ */
754
+ CacheManager.prototype.getSpecificCredential = function (key, credType) {
755
+ switch (credType) {
756
+ case CredentialType.ID_TOKEN: {
757
+ return this.getIdTokenCredential(key);
758
+ }
759
+ case CredentialType.ACCESS_TOKEN:
760
+ case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME: {
761
+ return this.getAccessTokenCredential(key);
762
+ }
763
+ case CredentialType.REFRESH_TOKEN: {
764
+ return this.getRefreshTokenCredential(key);
765
+ }
766
+ default:
767
+ return null;
768
+ }
769
+ };
770
+ /**
771
+ * Helper to convert serialized data to object
772
+ * @param obj
773
+ * @param json
774
+ */
775
+ CacheManager.toObject = function (obj, json) {
776
+ for (var propertyName in json) {
777
+ obj[propertyName] = json[propertyName];
778
+ }
779
+ return obj;
780
+ };
781
+ return CacheManager;
782
+ }());
783
+ var DefaultStorageClass = /** @class */ (function (_super) {
784
+ __extends(DefaultStorageClass, _super);
785
+ function DefaultStorageClass() {
786
+ return _super !== null && _super.apply(this, arguments) || this;
787
+ }
788
+ DefaultStorageClass.prototype.setAccount = function () {
789
+ var notImplErr = "Storage interface - setAccount() has not been implemented for the cacheStorage interface.";
790
+ throw AuthError.createUnexpectedError(notImplErr);
791
+ };
792
+ DefaultStorageClass.prototype.getAccount = function () {
793
+ var notImplErr = "Storage interface - getAccount() has not been implemented for the cacheStorage interface.";
794
+ throw AuthError.createUnexpectedError(notImplErr);
795
+ };
796
+ DefaultStorageClass.prototype.setIdTokenCredential = function () {
797
+ var notImplErr = "Storage interface - setIdTokenCredential() has not been implemented for the cacheStorage interface.";
798
+ throw AuthError.createUnexpectedError(notImplErr);
799
+ };
800
+ DefaultStorageClass.prototype.getIdTokenCredential = function () {
801
+ var notImplErr = "Storage interface - getIdTokenCredential() has not been implemented for the cacheStorage interface.";
802
+ throw AuthError.createUnexpectedError(notImplErr);
803
+ };
804
+ DefaultStorageClass.prototype.setAccessTokenCredential = function () {
805
+ var notImplErr = "Storage interface - setAccessTokenCredential() has not been implemented for the cacheStorage interface.";
806
+ throw AuthError.createUnexpectedError(notImplErr);
807
+ };
808
+ DefaultStorageClass.prototype.getAccessTokenCredential = function () {
809
+ var notImplErr = "Storage interface - getAccessTokenCredential() has not been implemented for the cacheStorage interface.";
810
+ throw AuthError.createUnexpectedError(notImplErr);
811
+ };
812
+ DefaultStorageClass.prototype.setRefreshTokenCredential = function () {
813
+ var notImplErr = "Storage interface - setRefreshTokenCredential() has not been implemented for the cacheStorage interface.";
814
+ throw AuthError.createUnexpectedError(notImplErr);
815
+ };
816
+ DefaultStorageClass.prototype.getRefreshTokenCredential = function () {
817
+ var notImplErr = "Storage interface - getRefreshTokenCredential() has not been implemented for the cacheStorage interface.";
818
+ throw AuthError.createUnexpectedError(notImplErr);
819
+ };
820
+ DefaultStorageClass.prototype.setAppMetadata = function () {
821
+ var notImplErr = "Storage interface - setAppMetadata() has not been implemented for the cacheStorage interface.";
822
+ throw AuthError.createUnexpectedError(notImplErr);
823
+ };
824
+ DefaultStorageClass.prototype.getAppMetadata = function () {
825
+ var notImplErr = "Storage interface - getAppMetadata() has not been implemented for the cacheStorage interface.";
826
+ throw AuthError.createUnexpectedError(notImplErr);
827
+ };
828
+ DefaultStorageClass.prototype.setServerTelemetry = function () {
829
+ var notImplErr = "Storage interface - setServerTelemetry() has not been implemented for the cacheStorage interface.";
830
+ throw AuthError.createUnexpectedError(notImplErr);
831
+ };
832
+ DefaultStorageClass.prototype.getServerTelemetry = function () {
833
+ var notImplErr = "Storage interface - getServerTelemetry() has not been implemented for the cacheStorage interface.";
834
+ throw AuthError.createUnexpectedError(notImplErr);
835
+ };
836
+ DefaultStorageClass.prototype.setAuthorityMetadata = function () {
837
+ var notImplErr = "Storage interface - setAuthorityMetadata() has not been implemented for the cacheStorage interface.";
838
+ throw AuthError.createUnexpectedError(notImplErr);
839
+ };
840
+ DefaultStorageClass.prototype.getAuthorityMetadata = function () {
841
+ var notImplErr = "Storage interface - getAuthorityMetadata() has not been implemented for the cacheStorage interface.";
842
+ throw AuthError.createUnexpectedError(notImplErr);
843
+ };
844
+ DefaultStorageClass.prototype.getAuthorityMetadataKeys = function () {
845
+ var notImplErr = "Storage interface - getAuthorityMetadataKeys() has not been implemented for the cacheStorage interface.";
846
+ throw AuthError.createUnexpectedError(notImplErr);
847
+ };
848
+ DefaultStorageClass.prototype.setThrottlingCache = function () {
849
+ var notImplErr = "Storage interface - setThrottlingCache() has not been implemented for the cacheStorage interface.";
850
+ throw AuthError.createUnexpectedError(notImplErr);
851
+ };
852
+ DefaultStorageClass.prototype.getThrottlingCache = function () {
853
+ var notImplErr = "Storage interface - getThrottlingCache() has not been implemented for the cacheStorage interface.";
854
+ throw AuthError.createUnexpectedError(notImplErr);
855
+ };
856
+ DefaultStorageClass.prototype.removeItem = function () {
857
+ var notImplErr = "Storage interface - removeItem() has not been implemented for the cacheStorage interface.";
858
+ throw AuthError.createUnexpectedError(notImplErr);
859
+ };
860
+ DefaultStorageClass.prototype.containsKey = function () {
861
+ var notImplErr = "Storage interface - containsKey() has not been implemented for the cacheStorage interface.";
862
+ throw AuthError.createUnexpectedError(notImplErr);
863
+ };
864
+ DefaultStorageClass.prototype.getKeys = function () {
865
+ var notImplErr = "Storage interface - getKeys() has not been implemented for the cacheStorage interface.";
866
+ throw AuthError.createUnexpectedError(notImplErr);
867
+ };
868
+ DefaultStorageClass.prototype.clear = function () {
869
+ return __awaiter(this, void 0, void 0, function () {
870
+ var notImplErr;
871
+ return __generator(this, function (_a) {
872
+ notImplErr = "Storage interface - clear() has not been implemented for the cacheStorage interface.";
873
+ throw AuthError.createUnexpectedError(notImplErr);
874
+ });
875
+ });
876
+ };
877
+ DefaultStorageClass.prototype.updateCredentialCacheKey = function () {
878
+ var notImplErr = "Storage interface - updateCredentialCacheKey() has not been implemented for the cacheStorage interface.";
879
+ throw AuthError.createUnexpectedError(notImplErr);
880
+ };
881
+ return DefaultStorageClass;
882
+ }(CacheManager));
883
+
884
+ export { CacheManager, DefaultStorageClass };
885
+ //# sourceMappingURL=CacheManager.js.map