@azure/msal-common 14.0.2 → 14.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (399) hide show
  1. package/dist/account/AccountInfo.d.ts +32 -32
  2. package/dist/account/AuthToken.d.ts +17 -20
  3. package/dist/account/AuthToken.d.ts.map +1 -1
  4. package/dist/account/AuthToken.mjs +61 -51
  5. package/dist/account/AuthToken.mjs.map +1 -1
  6. package/dist/account/CcsCredential.d.ts +9 -9
  7. package/dist/account/CcsCredential.mjs +8 -8
  8. package/dist/account/CcsCredential.mjs.map +1 -1
  9. package/dist/account/ClientCredentials.d.ts +14 -14
  10. package/dist/account/ClientInfo.d.ts +19 -19
  11. package/dist/account/ClientInfo.d.ts.map +1 -1
  12. package/dist/account/ClientInfo.mjs +39 -39
  13. package/dist/account/ClientInfo.mjs.map +1 -1
  14. package/dist/account/TokenClaims.d.ts +65 -65
  15. package/dist/authority/Authority.d.ts +235 -235
  16. package/dist/authority/Authority.d.ts.map +1 -1
  17. package/dist/authority/Authority.mjs +743 -765
  18. package/dist/authority/Authority.mjs.map +1 -1
  19. package/dist/authority/AuthorityFactory.d.ts +31 -31
  20. package/dist/authority/AuthorityFactory.d.ts.map +1 -1
  21. package/dist/authority/AuthorityFactory.mjs +52 -51
  22. package/dist/authority/AuthorityFactory.mjs.map +1 -1
  23. package/dist/authority/AuthorityMetadata.d.ts +623 -623
  24. package/dist/authority/AuthorityMetadata.mjs +884 -884
  25. package/dist/authority/AuthorityMetadata.mjs.map +1 -1
  26. package/dist/authority/AuthorityOptions.d.ts +21 -21
  27. package/dist/authority/AuthorityOptions.mjs +18 -18
  28. package/dist/authority/AuthorityOptions.mjs.map +1 -1
  29. package/dist/authority/AuthorityType.d.ts +10 -10
  30. package/dist/authority/AuthorityType.mjs +13 -13
  31. package/dist/authority/AuthorityType.mjs.map +1 -1
  32. package/dist/authority/AzureRegion.d.ts +1 -1
  33. package/dist/authority/AzureRegionConfiguration.d.ts +5 -5
  34. package/dist/authority/CloudDiscoveryMetadata.d.ts +5 -5
  35. package/dist/authority/CloudInstanceDiscoveryErrorResponse.d.ts +13 -13
  36. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +8 -8
  37. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs.map +1 -1
  38. package/dist/authority/CloudInstanceDiscoveryResponse.d.ts +9 -9
  39. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +8 -8
  40. package/dist/authority/CloudInstanceDiscoveryResponse.mjs.map +1 -1
  41. package/dist/authority/ImdsOptions.d.ts +5 -5
  42. package/dist/authority/OIDCOptions.d.ts +8 -8
  43. package/dist/authority/OpenIdConfigResponse.d.ts +11 -11
  44. package/dist/authority/OpenIdConfigResponse.mjs +10 -10
  45. package/dist/authority/OpenIdConfigResponse.mjs.map +1 -1
  46. package/dist/authority/ProtocolMode.d.ts +8 -8
  47. package/dist/authority/ProtocolMode.mjs +11 -11
  48. package/dist/authority/ProtocolMode.mjs.map +1 -1
  49. package/dist/authority/RegionDiscovery.d.ts +32 -30
  50. package/dist/authority/RegionDiscovery.d.ts.map +1 -1
  51. package/dist/authority/RegionDiscovery.mjs +107 -108
  52. package/dist/authority/RegionDiscovery.mjs.map +1 -1
  53. package/dist/authority/RegionDiscoveryMetadata.d.ts +6 -6
  54. package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts +15 -15
  55. package/dist/cache/CacheManager.d.ts +446 -446
  56. package/dist/cache/CacheManager.d.ts.map +1 -1
  57. package/dist/cache/CacheManager.mjs +1001 -1025
  58. package/dist/cache/CacheManager.mjs.map +1 -1
  59. package/dist/cache/entities/AccessTokenEntity.d.ts +56 -56
  60. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  61. package/dist/cache/entities/AccessTokenEntity.mjs +112 -114
  62. package/dist/cache/entities/AccessTokenEntity.mjs.map +1 -1
  63. package/dist/cache/entities/AccountEntity.d.ts +101 -101
  64. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  65. package/dist/cache/entities/AccountEntity.mjs +222 -223
  66. package/dist/cache/entities/AccountEntity.mjs.map +1 -1
  67. package/dist/cache/entities/AppMetadataEntity.d.ts +39 -39
  68. package/dist/cache/entities/AppMetadataEntity.mjs +66 -66
  69. package/dist/cache/entities/AppMetadataEntity.mjs.map +1 -1
  70. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +48 -48
  71. package/dist/cache/entities/AuthorityMetadataEntity.mjs +78 -78
  72. package/dist/cache/entities/AuthorityMetadataEntity.mjs.map +1 -1
  73. package/dist/cache/entities/CacheRecord.d.ts +14 -14
  74. package/dist/cache/entities/CacheRecord.mjs +14 -14
  75. package/dist/cache/entities/CacheRecord.mjs.map +1 -1
  76. package/dist/cache/entities/CredentialEntity.d.ts +88 -88
  77. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  78. package/dist/cache/entities/CredentialEntity.mjs +138 -137
  79. package/dist/cache/entities/CredentialEntity.mjs.map +1 -1
  80. package/dist/cache/entities/IdTokenEntity.d.ts +34 -34
  81. package/dist/cache/entities/IdTokenEntity.mjs +56 -56
  82. package/dist/cache/entities/IdTokenEntity.mjs.map +1 -1
  83. package/dist/cache/entities/RefreshTokenEntity.d.ts +36 -36
  84. package/dist/cache/entities/RefreshTokenEntity.mjs +59 -59
  85. package/dist/cache/entities/RefreshTokenEntity.mjs.map +1 -1
  86. package/dist/cache/entities/ServerTelemetryEntity.d.ts +12 -12
  87. package/dist/cache/entities/ServerTelemetryEntity.mjs +27 -27
  88. package/dist/cache/entities/ServerTelemetryEntity.mjs.map +1 -1
  89. package/dist/cache/entities/ThrottlingEntity.d.ts +13 -13
  90. package/dist/cache/entities/ThrottlingEntity.mjs +23 -23
  91. package/dist/cache/entities/ThrottlingEntity.mjs.map +1 -1
  92. package/dist/cache/interface/ICacheManager.d.ts +166 -166
  93. package/dist/cache/interface/ICachePlugin.d.ts +5 -5
  94. package/dist/cache/interface/ISerializableTokenCache.d.ts +4 -4
  95. package/dist/cache/persistence/TokenCacheContext.d.ts +23 -23
  96. package/dist/cache/persistence/TokenCacheContext.mjs +25 -25
  97. package/dist/cache/persistence/TokenCacheContext.mjs.map +1 -1
  98. package/dist/cache/utils/CacheTypes.d.ts +69 -69
  99. package/dist/client/AuthorizationCodeClient.d.ts +73 -73
  100. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  101. package/dist/client/AuthorizationCodeClient.mjs +412 -440
  102. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  103. package/dist/client/BaseClient.d.ts +51 -51
  104. package/dist/client/BaseClient.d.ts.map +1 -1
  105. package/dist/client/BaseClient.mjs +101 -94
  106. package/dist/client/BaseClient.mjs.map +1 -1
  107. package/dist/client/RefreshTokenClient.d.ts +35 -35
  108. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  109. package/dist/client/RefreshTokenClient.mjs +185 -243
  110. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  111. package/dist/client/SilentFlowClient.d.ts +26 -25
  112. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  113. package/dist/client/SilentFlowClient.mjs +128 -104
  114. package/dist/client/SilentFlowClient.mjs.map +1 -1
  115. package/dist/config/AppTokenProvider.d.ts +38 -38
  116. package/dist/config/ClientConfiguration.d.ts +150 -150
  117. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  118. package/dist/config/ClientConfiguration.mjs +99 -100
  119. package/dist/config/ClientConfiguration.mjs.map +1 -1
  120. package/dist/crypto/ICrypto.d.ts +62 -62
  121. package/dist/crypto/ICrypto.d.ts.map +1 -1
  122. package/dist/crypto/ICrypto.mjs +35 -43
  123. package/dist/crypto/ICrypto.mjs.map +1 -1
  124. package/dist/crypto/IGuidGenerator.d.ts +4 -4
  125. package/dist/crypto/JoseHeader.d.ts +22 -22
  126. package/dist/crypto/JoseHeader.d.ts.map +1 -1
  127. package/dist/crypto/JoseHeader.mjs +39 -38
  128. package/dist/crypto/JoseHeader.mjs.map +1 -1
  129. package/dist/crypto/PopTokenGenerator.d.ts +60 -59
  130. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  131. package/dist/crypto/PopTokenGenerator.mjs +83 -83
  132. package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
  133. package/dist/crypto/SignedHttpRequest.d.ts +11 -11
  134. package/dist/error/AuthError.d.ts +44 -47
  135. package/dist/error/AuthError.d.ts.map +1 -1
  136. package/dist/error/AuthError.mjs +50 -52
  137. package/dist/error/AuthError.mjs.map +1 -1
  138. package/dist/error/AuthErrorCodes.d.ts +6 -0
  139. package/dist/error/AuthErrorCodes.d.ts.map +1 -0
  140. package/dist/error/AuthErrorCodes.mjs +14 -0
  141. package/dist/error/AuthErrorCodes.mjs.map +1 -0
  142. package/dist/error/ClientAuthError.d.ts +232 -412
  143. package/dist/error/ClientAuthError.d.ts.map +1 -1
  144. package/dist/error/ClientAuthError.mjs +248 -520
  145. package/dist/error/ClientAuthError.mjs.map +1 -1
  146. package/dist/error/ClientAuthErrorCodes.d.ts +44 -0
  147. package/dist/error/ClientAuthErrorCodes.d.ts.map +1 -0
  148. package/dist/error/ClientAuthErrorCodes.mjs +52 -0
  149. package/dist/error/ClientAuthErrorCodes.mjs.map +1 -0
  150. package/dist/error/ClientConfigurationError.d.ts +128 -222
  151. package/dist/error/ClientConfigurationError.d.ts.map +1 -1
  152. package/dist/error/ClientConfigurationError.mjs +140 -281
  153. package/dist/error/ClientConfigurationError.mjs.map +1 -1
  154. package/dist/error/ClientConfigurationErrorCodes.d.ts +23 -0
  155. package/dist/error/ClientConfigurationErrorCodes.d.ts.map +1 -0
  156. package/dist/error/ClientConfigurationErrorCodes.mjs +31 -0
  157. package/dist/error/ClientConfigurationErrorCodes.mjs.map +1 -0
  158. package/dist/error/InteractionRequiredAuthError.d.ts +57 -59
  159. package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
  160. package/dist/error/InteractionRequiredAuthError.mjs +80 -79
  161. package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
  162. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts +6 -0
  163. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts.map +1 -0
  164. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +16 -0
  165. package/dist/error/InteractionRequiredAuthErrorCodes.mjs.map +1 -0
  166. package/dist/error/JoseHeaderError.d.ts +15 -28
  167. package/dist/error/JoseHeaderError.d.ts.map +1 -1
  168. package/dist/error/JoseHeaderError.mjs +24 -40
  169. package/dist/error/JoseHeaderError.mjs.map +1 -1
  170. package/dist/error/JoseHeaderErrorCodes.d.ts +3 -0
  171. package/dist/error/JoseHeaderErrorCodes.d.ts.map +1 -0
  172. package/dist/error/JoseHeaderErrorCodes.mjs +11 -0
  173. package/dist/error/JoseHeaderErrorCodes.mjs.map +1 -0
  174. package/dist/error/ServerError.d.ts +7 -7
  175. package/dist/error/ServerError.mjs +14 -14
  176. package/dist/error/ServerError.mjs.map +1 -1
  177. package/dist/index.cjs +8727 -8978
  178. package/dist/index.cjs.map +1 -1
  179. package/dist/index.d.ts +96 -96
  180. package/dist/index.d.ts.map +1 -1
  181. package/dist/index.mjs +17 -7
  182. package/dist/index.mjs.map +1 -1
  183. package/dist/logger/Logger.d.ts +95 -95
  184. package/dist/logger/Logger.d.ts.map +1 -1
  185. package/dist/logger/Logger.mjs +188 -198
  186. package/dist/logger/Logger.mjs.map +1 -1
  187. package/dist/network/INetworkModule.d.ts +29 -29
  188. package/dist/network/INetworkModule.d.ts.map +1 -1
  189. package/dist/network/INetworkModule.mjs +14 -15
  190. package/dist/network/INetworkModule.mjs.map +1 -1
  191. package/dist/network/NetworkManager.d.ts +33 -33
  192. package/dist/network/NetworkManager.d.ts.map +1 -1
  193. package/dist/network/NetworkManager.mjs +36 -35
  194. package/dist/network/NetworkManager.mjs.map +1 -1
  195. package/dist/network/RequestThumbprint.d.ts +16 -16
  196. package/dist/network/ThrottlingUtils.d.ts +42 -42
  197. package/dist/network/ThrottlingUtils.mjs +95 -95
  198. package/dist/network/ThrottlingUtils.mjs.map +1 -1
  199. package/dist/packageMetadata.d.ts +2 -2
  200. package/dist/packageMetadata.mjs +4 -4
  201. package/dist/packageMetadata.mjs.map +1 -1
  202. package/dist/request/AuthenticationHeaderParser.d.ts +19 -19
  203. package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -1
  204. package/dist/request/AuthenticationHeaderParser.mjs +58 -57
  205. package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
  206. package/dist/request/BaseAuthRequest.d.ts +40 -40
  207. package/dist/request/CommonAuthorizationCodeRequest.d.ts +27 -27
  208. package/dist/request/CommonAuthorizationUrlRequest.d.ts +50 -50
  209. package/dist/request/CommonClientCredentialRequest.d.ts +17 -17
  210. package/dist/request/CommonDeviceCodeRequest.d.ts +21 -21
  211. package/dist/request/CommonEndSessionRequest.d.ts +21 -21
  212. package/dist/request/CommonOnBehalfOfRequest.d.ts +13 -13
  213. package/dist/request/CommonRefreshTokenRequest.d.ts +19 -19
  214. package/dist/request/CommonSilentFlowRequest.d.ts +18 -18
  215. package/dist/request/CommonUsernamePasswordRequest.d.ts +17 -17
  216. package/dist/request/NativeRequest.d.ts +19 -19
  217. package/dist/request/NativeSignOutRequest.d.ts +5 -5
  218. package/dist/request/RequestParameterBuilder.d.ts +217 -217
  219. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  220. package/dist/request/RequestParameterBuilder.mjs +383 -383
  221. package/dist/request/RequestParameterBuilder.mjs.map +1 -1
  222. package/dist/request/RequestValidator.d.ts +33 -33
  223. package/dist/request/RequestValidator.d.ts.map +1 -1
  224. package/dist/request/RequestValidator.mjs +83 -84
  225. package/dist/request/RequestValidator.mjs.map +1 -1
  226. package/dist/request/ScopeSet.d.ts +88 -88
  227. package/dist/request/ScopeSet.d.ts.map +1 -1
  228. package/dist/request/ScopeSet.mjs +201 -199
  229. package/dist/request/ScopeSet.mjs.map +1 -1
  230. package/dist/request/StoreInCache.d.ts +8 -8
  231. package/dist/response/AuthenticationResult.d.ts +41 -39
  232. package/dist/response/AuthenticationResult.d.ts.map +1 -1
  233. package/dist/response/AuthorizationCodePayload.d.ts +13 -13
  234. package/dist/response/DeviceCodeResponse.d.ts +25 -25
  235. package/dist/response/ExternalTokenResponse.d.ts +15 -15
  236. package/dist/response/IMDSBadResponse.d.ts +4 -4
  237. package/dist/response/ResponseHandler.d.ts +67 -66
  238. package/dist/response/ResponseHandler.d.ts.map +1 -1
  239. package/dist/response/ResponseHandler.mjs +316 -297
  240. package/dist/response/ResponseHandler.mjs.map +1 -1
  241. package/dist/response/ServerAuthorizationCodeResponse.d.ts +25 -25
  242. package/dist/response/ServerAuthorizationTokenResponse.d.ts +46 -44
  243. package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
  244. package/dist/telemetry/performance/IPerformanceClient.d.ts +51 -51
  245. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
  246. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +5 -5
  247. package/dist/telemetry/performance/PerformanceClient.d.ts +191 -191
  248. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  249. package/dist/telemetry/performance/PerformanceClient.mjs +409 -408
  250. package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
  251. package/dist/telemetry/performance/PerformanceEvent.d.ts +433 -426
  252. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  253. package/dist/telemetry/performance/PerformanceEvent.mjs +234 -226
  254. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  255. package/dist/telemetry/performance/StubPerformanceClient.d.ts +24 -24
  256. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
  257. package/dist/telemetry/performance/StubPerformanceClient.mjs +77 -57
  258. package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -1
  259. package/dist/telemetry/server/ServerTelemetryManager.d.ts +66 -66
  260. package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
  261. package/dist/telemetry/server/ServerTelemetryManager.mjs +197 -198
  262. package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
  263. package/dist/telemetry/server/ServerTelemetryRequest.d.ts +8 -8
  264. package/dist/url/IUri.d.ts +12 -12
  265. package/dist/url/UrlString.d.ts +83 -83
  266. package/dist/url/UrlString.d.ts.map +1 -1
  267. package/dist/url/UrlString.mjs +283 -283
  268. package/dist/url/UrlString.mjs.map +1 -1
  269. package/dist/utils/Constants.d.ts +366 -353
  270. package/dist/utils/Constants.d.ts.map +1 -1
  271. package/dist/utils/Constants.mjs +377 -360
  272. package/dist/utils/Constants.mjs.map +1 -1
  273. package/dist/utils/FunctionWrappers.d.ts +28 -0
  274. package/dist/utils/FunctionWrappers.d.ts.map +1 -0
  275. package/dist/utils/FunctionWrappers.mjs +90 -0
  276. package/dist/utils/FunctionWrappers.mjs.map +1 -0
  277. package/dist/utils/MsalTypes.d.ts +6 -6
  278. package/dist/utils/ProtocolUtils.d.ts +42 -42
  279. package/dist/utils/ProtocolUtils.d.ts.map +1 -1
  280. package/dist/utils/ProtocolUtils.mjs +71 -73
  281. package/dist/utils/ProtocolUtils.mjs.map +1 -1
  282. package/dist/utils/StringUtils.d.ts +40 -53
  283. package/dist/utils/StringUtils.d.ts.map +1 -1
  284. package/dist/utils/StringUtils.mjs +95 -126
  285. package/dist/utils/StringUtils.mjs.map +1 -1
  286. package/dist/utils/TimeUtils.d.ts +27 -27
  287. package/dist/utils/TimeUtils.mjs +45 -45
  288. package/dist/utils/TimeUtils.mjs.map +1 -1
  289. package/package.json +6 -4
  290. package/src/account/AccountInfo.ts +44 -0
  291. package/src/account/AuthToken.ts +71 -0
  292. package/src/account/CcsCredential.ts +16 -0
  293. package/src/account/ClientCredentials.ts +20 -0
  294. package/src/account/ClientInfo.ts +67 -0
  295. package/src/account/TokenClaims.ts +70 -0
  296. package/src/authority/Authority.ts +1207 -0
  297. package/src/authority/AuthorityFactory.ts +118 -0
  298. package/src/authority/AuthorityMetadata.ts +953 -0
  299. package/src/authority/AuthorityOptions.ts +40 -0
  300. package/src/authority/AuthorityType.ts +15 -0
  301. package/src/authority/AzureRegion.ts +7 -0
  302. package/src/authority/AzureRegionConfiguration.ts +16 -0
  303. package/src/authority/CloudDiscoveryMetadata.ts +10 -0
  304. package/src/authority/CloudInstanceDiscoveryErrorResponse.ts +26 -0
  305. package/src/authority/CloudInstanceDiscoveryResponse.ts +21 -0
  306. package/src/authority/ImdsOptions.ts +10 -0
  307. package/src/authority/OIDCOptions.ts +14 -0
  308. package/src/authority/OpenIdConfigResponse.ts +24 -0
  309. package/src/authority/ProtocolMode.ts +13 -0
  310. package/src/authority/RegionDiscovery.ts +196 -0
  311. package/src/authority/RegionDiscoveryMetadata.ts +15 -0
  312. package/src/broker/nativeBroker/INativeBrokerPlugin.ts +29 -0
  313. package/src/cache/CacheManager.ts +1579 -0
  314. package/src/cache/entities/AccessTokenEntity.ts +167 -0
  315. package/src/cache/entities/AccountEntity.ts +314 -0
  316. package/src/cache/entities/AppMetadataEntity.ts +91 -0
  317. package/src/cache/entities/AuthorityMetadataEntity.ts +112 -0
  318. package/src/cache/entities/CacheRecord.ts +33 -0
  319. package/src/cache/entities/CredentialEntity.ts +220 -0
  320. package/src/cache/entities/IdTokenEntity.ts +74 -0
  321. package/src/cache/entities/RefreshTokenEntity.ts +78 -0
  322. package/src/cache/entities/ServerTelemetryEntity.ts +38 -0
  323. package/src/cache/entities/ThrottlingEntity.ts +36 -0
  324. package/src/cache/interface/ICacheManager.ts +218 -0
  325. package/src/cache/interface/ICachePlugin.ts +11 -0
  326. package/src/cache/interface/ISerializableTokenCache.ts +9 -0
  327. package/src/cache/persistence/TokenCacheContext.ts +39 -0
  328. package/src/cache/utils/CacheTypes.ts +93 -0
  329. package/src/client/AuthorizationCodeClient.ts +736 -0
  330. package/src/client/BaseClient.ts +208 -0
  331. package/src/client/RefreshTokenClient.ts +399 -0
  332. package/src/client/SilentFlowClient.ts +239 -0
  333. package/src/config/AppTokenProvider.ts +47 -0
  334. package/src/config/ClientConfiguration.ts +286 -0
  335. package/src/crypto/ICrypto.ts +112 -0
  336. package/src/crypto/IGuidGenerator.ts +9 -0
  337. package/src/crypto/JoseHeader.ts +58 -0
  338. package/src/crypto/PopTokenGenerator.ts +160 -0
  339. package/src/crypto/SignedHttpRequest.ts +16 -0
  340. package/src/error/AuthError.ts +83 -0
  341. package/src/error/AuthErrorCodes.ts +10 -0
  342. package/src/error/ClientAuthError.ts +333 -0
  343. package/src/error/ClientAuthErrorCodes.ts +51 -0
  344. package/src/error/ClientConfigurationError.ts +210 -0
  345. package/src/error/ClientConfigurationErrorCodes.ts +28 -0
  346. package/src/error/InteractionRequiredAuthError.ts +139 -0
  347. package/src/error/InteractionRequiredAuthErrorCodes.ts +13 -0
  348. package/src/error/JoseHeaderError.ts +32 -0
  349. package/src/error/JoseHeaderErrorCodes.ts +7 -0
  350. package/src/error/ServerError.ts +18 -0
  351. package/src/index.ts +226 -0
  352. package/src/logger/Logger.ts +272 -0
  353. package/src/network/INetworkModule.ts +60 -0
  354. package/src/network/NetworkManager.ts +76 -0
  355. package/src/network/RequestThumbprint.ts +22 -0
  356. package/src/network/ThrottlingUtils.ts +156 -0
  357. package/src/packageMetadata.ts +3 -0
  358. package/src/request/AuthenticationHeaderParser.ts +92 -0
  359. package/src/request/BaseAuthRequest.ts +46 -0
  360. package/src/request/CommonAuthorizationCodeRequest.ts +33 -0
  361. package/src/request/CommonAuthorizationUrlRequest.ts +56 -0
  362. package/src/request/CommonClientCredentialRequest.ts +23 -0
  363. package/src/request/CommonDeviceCodeRequest.ts +31 -0
  364. package/src/request/CommonEndSessionRequest.ts +27 -0
  365. package/src/request/CommonOnBehalfOfRequest.ts +19 -0
  366. package/src/request/CommonRefreshTokenRequest.ts +25 -0
  367. package/src/request/CommonSilentFlowRequest.ts +24 -0
  368. package/src/request/CommonUsernamePasswordRequest.ts +23 -0
  369. package/src/request/NativeRequest.ts +25 -0
  370. package/src/request/NativeSignOutRequest.ts +10 -0
  371. package/src/request/RequestParameterBuilder.ts +613 -0
  372. package/src/request/RequestValidator.ts +116 -0
  373. package/src/request/ScopeSet.ts +246 -0
  374. package/src/request/StoreInCache.ts +16 -0
  375. package/src/response/AuthenticationResult.ts +47 -0
  376. package/src/response/AuthorizationCodePayload.ts +18 -0
  377. package/src/response/DeviceCodeResponse.ts +31 -0
  378. package/src/response/ExternalTokenResponse.ts +24 -0
  379. package/src/response/IMDSBadResponse.ts +9 -0
  380. package/src/response/ResponseHandler.ts +634 -0
  381. package/src/response/ServerAuthorizationCodeResponse.ts +33 -0
  382. package/src/response/ServerAuthorizationTokenResponse.ts +54 -0
  383. package/src/telemetry/performance/IPerformanceClient.ts +71 -0
  384. package/src/telemetry/performance/IPerformanceMeasurement.ts +10 -0
  385. package/src/telemetry/performance/PerformanceClient.ts +636 -0
  386. package/src/telemetry/performance/PerformanceEvent.ts +542 -0
  387. package/src/telemetry/performance/StubPerformanceClient.ts +101 -0
  388. package/src/telemetry/server/ServerTelemetryManager.ts +274 -0
  389. package/src/telemetry/server/ServerTelemetryRequest.ts +13 -0
  390. package/src/url/IUri.ts +17 -0
  391. package/src/url/UrlString.ts +373 -0
  392. package/src/utils/Constants.ts +444 -0
  393. package/src/utils/FunctionWrappers.ts +105 -0
  394. package/src/utils/MsalTypes.ts +9 -0
  395. package/src/utils/ProtocolUtils.ts +120 -0
  396. package/src/utils/StringUtils.ts +106 -0
  397. package/src/utils/TimeUtils.ts +51 -0
  398. package/dist/account/DecodedAuthToken.d.ts +0 -9
  399. package/dist/account/DecodedAuthToken.d.ts.map +0 -1
@@ -0,0 +1,1579 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ AccountFilter,
8
+ CredentialFilter,
9
+ ValidCredentialType,
10
+ AppMetadataFilter,
11
+ AppMetadataCache,
12
+ TokenKeys,
13
+ } from "./utils/CacheTypes";
14
+ import { CacheRecord } from "./entities/CacheRecord";
15
+ import {
16
+ CredentialType,
17
+ APP_METADATA,
18
+ THE_FAMILY_ID,
19
+ AUTHORITY_METADATA_CONSTANTS,
20
+ AuthenticationScheme,
21
+ Separators,
22
+ } from "../utils/Constants";
23
+ import { CredentialEntity } from "./entities/CredentialEntity";
24
+ import { ScopeSet } from "../request/ScopeSet";
25
+ import { AccountEntity } from "./entities/AccountEntity";
26
+ import { AccessTokenEntity } from "./entities/AccessTokenEntity";
27
+ import { IdTokenEntity } from "./entities/IdTokenEntity";
28
+ import { RefreshTokenEntity } from "./entities/RefreshTokenEntity";
29
+ import { ICacheManager } from "./interface/ICacheManager";
30
+ import {
31
+ createClientAuthError,
32
+ ClientAuthErrorCodes,
33
+ } from "../error/ClientAuthError";
34
+ import { AccountInfo } from "../account/AccountInfo";
35
+ import { AppMetadataEntity } from "./entities/AppMetadataEntity";
36
+ import { ServerTelemetryEntity } from "./entities/ServerTelemetryEntity";
37
+ import { ThrottlingEntity } from "./entities/ThrottlingEntity";
38
+ import { extractTokenClaims } from "../account/AuthToken";
39
+ import { ICrypto } from "../crypto/ICrypto";
40
+ import { AuthorityMetadataEntity } from "./entities/AuthorityMetadataEntity";
41
+ import { BaseAuthRequest } from "../request/BaseAuthRequest";
42
+ import { Logger } from "../logger/Logger";
43
+ import { name, version } from "../packageMetadata";
44
+ import { StoreInCache } from "../request/StoreInCache";
45
+
46
+ /**
47
+ * Interface class which implement cache storage functions used by MSAL to perform validity checks, and store tokens.
48
+ * @internal
49
+ */
50
+ export abstract class CacheManager implements ICacheManager {
51
+ protected clientId: string;
52
+ protected cryptoImpl: ICrypto;
53
+ // Instance of logger for functions defined in the msal-common layer
54
+ private commonLogger: Logger;
55
+
56
+ constructor(clientId: string, cryptoImpl: ICrypto, logger: Logger) {
57
+ this.clientId = clientId;
58
+ this.cryptoImpl = cryptoImpl;
59
+ this.commonLogger = logger.clone(name, version);
60
+ }
61
+
62
+ /**
63
+ * fetch the account entity from the platform cache
64
+ * @param accountKey
65
+ */
66
+ abstract getAccount(accountKey: string): AccountEntity | null;
67
+
68
+ /**
69
+ * set account entity in the platform cache
70
+ * @param account
71
+ */
72
+ abstract setAccount(account: AccountEntity): void;
73
+
74
+ /**
75
+ * fetch the idToken entity from the platform cache
76
+ * @param idTokenKey
77
+ */
78
+ abstract getIdTokenCredential(idTokenKey: string): IdTokenEntity | null;
79
+
80
+ /**
81
+ * set idToken entity to the platform cache
82
+ * @param idToken
83
+ */
84
+ abstract setIdTokenCredential(idToken: IdTokenEntity): void;
85
+
86
+ /**
87
+ * fetch the idToken entity from the platform cache
88
+ * @param accessTokenKey
89
+ */
90
+ abstract getAccessTokenCredential(
91
+ accessTokenKey: string
92
+ ): AccessTokenEntity | null;
93
+
94
+ /**
95
+ * set idToken entity to the platform cache
96
+ * @param accessToken
97
+ */
98
+ abstract setAccessTokenCredential(accessToken: AccessTokenEntity): void;
99
+
100
+ /**
101
+ * fetch the idToken entity from the platform cache
102
+ * @param refreshTokenKey
103
+ */
104
+ abstract getRefreshTokenCredential(
105
+ refreshTokenKey: string
106
+ ): RefreshTokenEntity | null;
107
+
108
+ /**
109
+ * set idToken entity to the platform cache
110
+ * @param refreshToken
111
+ */
112
+ abstract setRefreshTokenCredential(refreshToken: RefreshTokenEntity): void;
113
+
114
+ /**
115
+ * fetch appMetadata entity from the platform cache
116
+ * @param appMetadataKey
117
+ */
118
+ abstract getAppMetadata(appMetadataKey: string): AppMetadataEntity | null;
119
+
120
+ /**
121
+ * set appMetadata entity to the platform cache
122
+ * @param appMetadata
123
+ */
124
+ abstract setAppMetadata(appMetadata: AppMetadataEntity): void;
125
+
126
+ /**
127
+ * fetch server telemetry entity from the platform cache
128
+ * @param serverTelemetryKey
129
+ */
130
+ abstract getServerTelemetry(
131
+ serverTelemetryKey: string
132
+ ): ServerTelemetryEntity | null;
133
+
134
+ /**
135
+ * set server telemetry entity to the platform cache
136
+ * @param serverTelemetryKey
137
+ * @param serverTelemetry
138
+ */
139
+ abstract setServerTelemetry(
140
+ serverTelemetryKey: string,
141
+ serverTelemetry: ServerTelemetryEntity
142
+ ): void;
143
+
144
+ /**
145
+ * fetch cloud discovery metadata entity from the platform cache
146
+ * @param key
147
+ */
148
+ abstract getAuthorityMetadata(key: string): AuthorityMetadataEntity | null;
149
+
150
+ /**
151
+ *
152
+ */
153
+ abstract getAuthorityMetadataKeys(): Array<string>;
154
+
155
+ /**
156
+ * set cloud discovery metadata entity to the platform cache
157
+ * @param key
158
+ * @param value
159
+ */
160
+ abstract setAuthorityMetadata(
161
+ key: string,
162
+ value: AuthorityMetadataEntity
163
+ ): void;
164
+
165
+ /**
166
+ * fetch throttling entity from the platform cache
167
+ * @param throttlingCacheKey
168
+ */
169
+ abstract getThrottlingCache(
170
+ throttlingCacheKey: string
171
+ ): ThrottlingEntity | null;
172
+
173
+ /**
174
+ * set throttling entity to the platform cache
175
+ * @param throttlingCacheKey
176
+ * @param throttlingCache
177
+ */
178
+ abstract setThrottlingCache(
179
+ throttlingCacheKey: string,
180
+ throttlingCache: ThrottlingEntity
181
+ ): void;
182
+
183
+ /**
184
+ * Function to remove an item from cache given its key.
185
+ * @param key
186
+ */
187
+ abstract removeItem(key: string): void;
188
+
189
+ /**
190
+ * Function which returns boolean whether cache contains a specific key.
191
+ * @param key
192
+ */
193
+ abstract containsKey(key: string, type?: string): boolean;
194
+
195
+ /**
196
+ * Function which retrieves all current keys from the cache.
197
+ */
198
+ abstract getKeys(): string[];
199
+
200
+ /**
201
+ * Function which retrieves all account keys from the cache
202
+ */
203
+ abstract getAccountKeys(): string[];
204
+
205
+ /**
206
+ * Function which retrieves all token keys from the cache
207
+ */
208
+ abstract getTokenKeys(): TokenKeys;
209
+
210
+ /**
211
+ * Function which clears cache.
212
+ */
213
+ abstract clear(): Promise<void>;
214
+
215
+ /**
216
+ * Function which updates an outdated credential cache key
217
+ */
218
+ abstract updateCredentialCacheKey(
219
+ currentCacheKey: string,
220
+ credential: ValidCredentialType
221
+ ): string;
222
+
223
+ /**
224
+ * Returns all accounts in cache
225
+ */
226
+ getAllAccounts(): AccountInfo[] {
227
+ const allAccountKeys = this.getAccountKeys();
228
+ if (allAccountKeys.length < 1) {
229
+ return [];
230
+ }
231
+
232
+ const accountEntities: AccountEntity[] = allAccountKeys.reduce(
233
+ (accounts: AccountEntity[], key: string) => {
234
+ const entity: AccountEntity | null = this.getAccount(key);
235
+
236
+ if (!entity) {
237
+ return accounts;
238
+ }
239
+ accounts.push(entity);
240
+ return accounts;
241
+ },
242
+ []
243
+ );
244
+
245
+ if (accountEntities.length < 1) {
246
+ return [];
247
+ } else {
248
+ const allAccounts = accountEntities.map<AccountInfo>(
249
+ (accountEntity) => {
250
+ return this.getAccountInfoFromEntity(accountEntity);
251
+ }
252
+ );
253
+ return allAccounts;
254
+ }
255
+ }
256
+
257
+ /**
258
+ * Gets accountInfo object based on provided filters
259
+ */
260
+ getAccountInfoFilteredBy(accountFilter: AccountFilter): AccountInfo | null {
261
+ const allAccounts = this.getAccountsFilteredBy(accountFilter);
262
+ if (allAccounts.length > 0) {
263
+ return this.getAccountInfoFromEntity(allAccounts[0]);
264
+ } else {
265
+ return null;
266
+ }
267
+ }
268
+
269
+ private getAccountInfoFromEntity(
270
+ accountEntity: AccountEntity
271
+ ): AccountInfo {
272
+ const accountInfo = accountEntity.getAccountInfo();
273
+ const idToken = this.getIdToken(accountInfo);
274
+ if (idToken) {
275
+ accountInfo.idToken = idToken.secret;
276
+ accountInfo.idTokenClaims = extractTokenClaims(
277
+ idToken.secret,
278
+ this.cryptoImpl.base64Decode
279
+ );
280
+ }
281
+ return accountInfo;
282
+ }
283
+
284
+ /**
285
+ * saves a cache record
286
+ * @param cacheRecord
287
+ */
288
+ async saveCacheRecord(
289
+ cacheRecord: CacheRecord,
290
+ storeInCache?: StoreInCache
291
+ ): Promise<void> {
292
+ if (!cacheRecord) {
293
+ throw createClientAuthError(
294
+ ClientAuthErrorCodes.invalidCacheRecord
295
+ );
296
+ }
297
+
298
+ if (!!cacheRecord.account) {
299
+ this.setAccount(cacheRecord.account);
300
+ }
301
+
302
+ if (!!cacheRecord.idToken && storeInCache?.idToken !== false) {
303
+ this.setIdTokenCredential(cacheRecord.idToken);
304
+ }
305
+
306
+ if (!!cacheRecord.accessToken && storeInCache?.accessToken !== false) {
307
+ await this.saveAccessToken(cacheRecord.accessToken);
308
+ }
309
+
310
+ if (
311
+ !!cacheRecord.refreshToken &&
312
+ storeInCache?.refreshToken !== false
313
+ ) {
314
+ this.setRefreshTokenCredential(cacheRecord.refreshToken);
315
+ }
316
+
317
+ if (!!cacheRecord.appMetadata) {
318
+ this.setAppMetadata(cacheRecord.appMetadata);
319
+ }
320
+ }
321
+
322
+ /**
323
+ * saves access token credential
324
+ * @param credential
325
+ */
326
+ private async saveAccessToken(
327
+ credential: AccessTokenEntity
328
+ ): Promise<void> {
329
+ const accessTokenFilter: CredentialFilter = {
330
+ clientId: credential.clientId,
331
+ credentialType: credential.credentialType,
332
+ environment: credential.environment,
333
+ homeAccountId: credential.homeAccountId,
334
+ realm: credential.realm,
335
+ tokenType: credential.tokenType,
336
+ requestedClaimsHash: credential.requestedClaimsHash,
337
+ };
338
+
339
+ const tokenKeys = this.getTokenKeys();
340
+ const currentScopes = ScopeSet.fromString(credential.target);
341
+
342
+ const removedAccessTokens: Array<Promise<void>> = [];
343
+ tokenKeys.accessToken.forEach((key) => {
344
+ if (
345
+ !this.accessTokenKeyMatchesFilter(key, accessTokenFilter, false)
346
+ ) {
347
+ return;
348
+ }
349
+
350
+ const tokenEntity = this.getAccessTokenCredential(key);
351
+
352
+ if (
353
+ tokenEntity &&
354
+ this.credentialMatchesFilter(tokenEntity, accessTokenFilter)
355
+ ) {
356
+ const tokenScopeSet = ScopeSet.fromString(tokenEntity.target);
357
+ if (tokenScopeSet.intersectingScopeSets(currentScopes)) {
358
+ removedAccessTokens.push(this.removeAccessToken(key));
359
+ }
360
+ }
361
+ });
362
+ await Promise.all(removedAccessTokens);
363
+ this.setAccessTokenCredential(credential);
364
+ }
365
+
366
+ /**
367
+ * retrieve accounts matching all provided filters; if no filter is set, get all accounts
368
+ * not checking for casing as keys are all generated in lower case, remember to convert to lower case if object properties are compared
369
+ * @param homeAccountId
370
+ * @param environment
371
+ * @param realm
372
+ */
373
+ getAccountsFilteredBy(accountFilter: AccountFilter): AccountEntity[] {
374
+ const allAccountKeys = this.getAccountKeys();
375
+ const matchingAccounts: AccountEntity[] = [];
376
+
377
+ allAccountKeys.forEach((cacheKey) => {
378
+ if (
379
+ !this.isAccountKey(
380
+ cacheKey,
381
+ accountFilter.homeAccountId,
382
+ accountFilter.realm
383
+ )
384
+ ) {
385
+ // Don't parse value if the key doesn't match the account filters
386
+ return;
387
+ }
388
+
389
+ const entity: AccountEntity | null = this.getAccount(cacheKey);
390
+
391
+ if (!entity) {
392
+ return;
393
+ }
394
+
395
+ if (
396
+ !!accountFilter.homeAccountId &&
397
+ !this.matchHomeAccountId(entity, accountFilter.homeAccountId)
398
+ ) {
399
+ return;
400
+ }
401
+
402
+ if (
403
+ !!accountFilter.localAccountId &&
404
+ !this.matchLocalAccountId(entity, accountFilter.localAccountId)
405
+ ) {
406
+ return;
407
+ }
408
+
409
+ if (
410
+ !!accountFilter.username &&
411
+ !this.matchUsername(entity, accountFilter.username)
412
+ ) {
413
+ return;
414
+ }
415
+
416
+ if (
417
+ !!accountFilter.environment &&
418
+ !this.matchEnvironment(entity, accountFilter.environment)
419
+ ) {
420
+ return;
421
+ }
422
+
423
+ if (
424
+ !!accountFilter.realm &&
425
+ !this.matchRealm(entity, accountFilter.realm)
426
+ ) {
427
+ return;
428
+ }
429
+
430
+ if (
431
+ !!accountFilter.nativeAccountId &&
432
+ !this.matchNativeAccountId(
433
+ entity,
434
+ accountFilter.nativeAccountId
435
+ )
436
+ ) {
437
+ return;
438
+ }
439
+
440
+ matchingAccounts.push(entity);
441
+ });
442
+
443
+ return matchingAccounts;
444
+ }
445
+
446
+ /**
447
+ * Returns true if the given key matches our account key schema. Also matches homeAccountId and/or tenantId if provided
448
+ * @param key
449
+ * @param homeAccountId
450
+ * @param tenantId
451
+ * @returns
452
+ */
453
+ isAccountKey(
454
+ key: string,
455
+ homeAccountId?: string,
456
+ tenantId?: string
457
+ ): boolean {
458
+ if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 3) {
459
+ // Account cache keys contain 3 items separated by '-' (each item may also contain '-')
460
+ return false;
461
+ }
462
+
463
+ if (
464
+ homeAccountId &&
465
+ !key.toLowerCase().includes(homeAccountId.toLowerCase())
466
+ ) {
467
+ return false;
468
+ }
469
+
470
+ if (tenantId && !key.toLowerCase().includes(tenantId.toLowerCase())) {
471
+ return false;
472
+ }
473
+
474
+ // Do not check environment as aliasing can cause false negatives
475
+
476
+ return true;
477
+ }
478
+
479
+ /**
480
+ * Returns true if the given key matches our credential key schema.
481
+ * @param key
482
+ */
483
+ isCredentialKey(key: string): boolean {
484
+ if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 6) {
485
+ // Credential cache keys contain 6 items separated by '-' (each item may also contain '-')
486
+ return false;
487
+ }
488
+
489
+ const lowerCaseKey = key.toLowerCase();
490
+ // Credential keys must indicate what credential type they represent
491
+ if (
492
+ lowerCaseKey.indexOf(CredentialType.ID_TOKEN.toLowerCase()) ===
493
+ -1 &&
494
+ lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN.toLowerCase()) ===
495
+ -1 &&
496
+ lowerCaseKey.indexOf(
497
+ CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()
498
+ ) === -1 &&
499
+ lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) ===
500
+ -1
501
+ ) {
502
+ return false;
503
+ }
504
+
505
+ if (
506
+ lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) >
507
+ -1
508
+ ) {
509
+ // Refresh tokens must contain the client id or family id
510
+ const clientIdValidation = `${CredentialType.REFRESH_TOKEN}${Separators.CACHE_KEY_SEPARATOR}${this.clientId}${Separators.CACHE_KEY_SEPARATOR}`;
511
+ const familyIdValidation = `${CredentialType.REFRESH_TOKEN}${Separators.CACHE_KEY_SEPARATOR}${THE_FAMILY_ID}${Separators.CACHE_KEY_SEPARATOR}`;
512
+ if (
513
+ lowerCaseKey.indexOf(clientIdValidation.toLowerCase()) === -1 &&
514
+ lowerCaseKey.indexOf(familyIdValidation.toLowerCase()) === -1
515
+ ) {
516
+ return false;
517
+ }
518
+ } else if (lowerCaseKey.indexOf(this.clientId.toLowerCase()) === -1) {
519
+ // Tokens must contain the clientId
520
+ return false;
521
+ }
522
+
523
+ return true;
524
+ }
525
+
526
+ /**
527
+ * Returns whether or not the given credential entity matches the filter
528
+ * @param entity
529
+ * @param filter
530
+ * @returns
531
+ */
532
+ credentialMatchesFilter(
533
+ entity: ValidCredentialType,
534
+ filter: CredentialFilter
535
+ ): boolean {
536
+ if (!!filter.clientId && !this.matchClientId(entity, filter.clientId)) {
537
+ return false;
538
+ }
539
+
540
+ if (
541
+ !!filter.userAssertionHash &&
542
+ !this.matchUserAssertionHash(entity, filter.userAssertionHash)
543
+ ) {
544
+ return false;
545
+ }
546
+
547
+ /*
548
+ * homeAccountId can be undefined, and we want to filter out cached items that have a homeAccountId of ""
549
+ * because we don't want a client_credential request to return a cached token that has a homeAccountId
550
+ */
551
+ if (
552
+ typeof filter.homeAccountId === "string" &&
553
+ !this.matchHomeAccountId(entity, filter.homeAccountId)
554
+ ) {
555
+ return false;
556
+ }
557
+
558
+ if (
559
+ !!filter.environment &&
560
+ !this.matchEnvironment(entity, filter.environment)
561
+ ) {
562
+ return false;
563
+ }
564
+
565
+ if (!!filter.realm && !this.matchRealm(entity, filter.realm)) {
566
+ return false;
567
+ }
568
+
569
+ if (
570
+ !!filter.credentialType &&
571
+ !this.matchCredentialType(entity, filter.credentialType)
572
+ ) {
573
+ return false;
574
+ }
575
+
576
+ if (!!filter.familyId && !this.matchFamilyId(entity, filter.familyId)) {
577
+ return false;
578
+ }
579
+
580
+ /*
581
+ * idTokens do not have "target", target specific refreshTokens do exist for some types of authentication
582
+ * Resource specific refresh tokens case will be added when the support is deemed necessary
583
+ */
584
+ if (!!filter.target && !this.matchTarget(entity, filter.target)) {
585
+ return false;
586
+ }
587
+
588
+ // If request OR cached entity has requested Claims Hash, check if they match
589
+ if (filter.requestedClaimsHash || entity.requestedClaimsHash) {
590
+ // Don't match if either is undefined or they are different
591
+ if (entity.requestedClaimsHash !== filter.requestedClaimsHash) {
592
+ return false;
593
+ }
594
+ }
595
+
596
+ // Access Token with Auth Scheme specific matching
597
+ if (
598
+ entity.credentialType ===
599
+ CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME
600
+ ) {
601
+ if (
602
+ !!filter.tokenType &&
603
+ !this.matchTokenType(entity, filter.tokenType)
604
+ ) {
605
+ return false;
606
+ }
607
+
608
+ // KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
609
+ if (filter.tokenType === AuthenticationScheme.SSH) {
610
+ if (filter.keyId && !this.matchKeyId(entity, filter.keyId)) {
611
+ return false;
612
+ }
613
+ }
614
+ }
615
+
616
+ return true;
617
+ }
618
+
619
+ /**
620
+ * retrieve appMetadata matching all provided filters; if no filter is set, get all appMetadata
621
+ * @param filter
622
+ */
623
+ getAppMetadataFilteredBy(filter: AppMetadataFilter): AppMetadataCache {
624
+ return this.getAppMetadataFilteredByInternal(
625
+ filter.environment,
626
+ filter.clientId
627
+ );
628
+ }
629
+
630
+ /**
631
+ * Support function to help match appMetadata
632
+ * @param environment
633
+ * @param clientId
634
+ */
635
+ private getAppMetadataFilteredByInternal(
636
+ environment?: string,
637
+ clientId?: string
638
+ ): AppMetadataCache {
639
+ const allCacheKeys = this.getKeys();
640
+ const matchingAppMetadata: AppMetadataCache = {};
641
+
642
+ allCacheKeys.forEach((cacheKey) => {
643
+ // don't parse any non-appMetadata type cache entities
644
+ if (!this.isAppMetadata(cacheKey)) {
645
+ return;
646
+ }
647
+
648
+ // Attempt retrieval
649
+ const entity = this.getAppMetadata(cacheKey);
650
+
651
+ if (!entity) {
652
+ return;
653
+ }
654
+
655
+ if (!!environment && !this.matchEnvironment(entity, environment)) {
656
+ return;
657
+ }
658
+
659
+ if (!!clientId && !this.matchClientId(entity, clientId)) {
660
+ return;
661
+ }
662
+
663
+ matchingAppMetadata[cacheKey] = entity;
664
+ });
665
+
666
+ return matchingAppMetadata;
667
+ }
668
+
669
+ /**
670
+ * retrieve authorityMetadata that contains a matching alias
671
+ * @param filter
672
+ */
673
+ getAuthorityMetadataByAlias(host: string): AuthorityMetadataEntity | null {
674
+ const allCacheKeys = this.getAuthorityMetadataKeys();
675
+ let matchedEntity = null;
676
+
677
+ allCacheKeys.forEach((cacheKey) => {
678
+ // don't parse any non-authorityMetadata type cache entities
679
+ if (
680
+ !this.isAuthorityMetadata(cacheKey) ||
681
+ cacheKey.indexOf(this.clientId) === -1
682
+ ) {
683
+ return;
684
+ }
685
+
686
+ // Attempt retrieval
687
+ const entity = this.getAuthorityMetadata(cacheKey);
688
+
689
+ if (!entity) {
690
+ return;
691
+ }
692
+
693
+ if (entity.aliases.indexOf(host) === -1) {
694
+ return;
695
+ }
696
+
697
+ matchedEntity = entity;
698
+ });
699
+
700
+ return matchedEntity;
701
+ }
702
+
703
+ /**
704
+ * Removes all accounts and related tokens from cache.
705
+ */
706
+ async removeAllAccounts(): Promise<void> {
707
+ const allAccountKeys = this.getAccountKeys();
708
+ const removedAccounts: Array<Promise<void>> = [];
709
+
710
+ allAccountKeys.forEach((cacheKey) => {
711
+ removedAccounts.push(this.removeAccount(cacheKey));
712
+ });
713
+
714
+ await Promise.all(removedAccounts);
715
+ }
716
+
717
+ /**
718
+ * Removes the account and related tokens for a given account key
719
+ * @param account
720
+ */
721
+ async removeAccount(accountKey: string): Promise<void> {
722
+ const account = this.getAccount(accountKey);
723
+ if (!account) {
724
+ return;
725
+ }
726
+ await this.removeAccountContext(account);
727
+ this.removeItem(accountKey);
728
+ }
729
+
730
+ /**
731
+ * Removes credentials associated with the provided account
732
+ * @param account
733
+ */
734
+ async removeAccountContext(account: AccountEntity): Promise<void> {
735
+ const allTokenKeys = this.getTokenKeys();
736
+ const accountId = account.generateAccountId();
737
+ const removedCredentials: Array<Promise<void>> = [];
738
+
739
+ allTokenKeys.idToken.forEach((key) => {
740
+ if (key.indexOf(accountId) === 0) {
741
+ this.removeIdToken(key);
742
+ }
743
+ });
744
+
745
+ allTokenKeys.accessToken.forEach((key) => {
746
+ if (key.indexOf(accountId) === 0) {
747
+ removedCredentials.push(this.removeAccessToken(key));
748
+ }
749
+ });
750
+
751
+ allTokenKeys.refreshToken.forEach((key) => {
752
+ if (key.indexOf(accountId) === 0) {
753
+ this.removeRefreshToken(key);
754
+ }
755
+ });
756
+
757
+ await Promise.all(removedCredentials);
758
+ }
759
+
760
+ /**
761
+ * returns a boolean if the given credential is removed
762
+ * @param credential
763
+ */
764
+ async removeAccessToken(key: string): Promise<void> {
765
+ const credential = this.getAccessTokenCredential(key);
766
+ if (!credential) {
767
+ return;
768
+ }
769
+
770
+ // Remove Token Binding Key from key store for PoP Tokens Credentials
771
+ if (
772
+ credential.credentialType.toLowerCase() ===
773
+ CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()
774
+ ) {
775
+ if (credential.tokenType === AuthenticationScheme.POP) {
776
+ const accessTokenWithAuthSchemeEntity =
777
+ credential as AccessTokenEntity;
778
+ const kid = accessTokenWithAuthSchemeEntity.keyId;
779
+
780
+ if (kid) {
781
+ try {
782
+ await this.cryptoImpl.removeTokenBindingKey(kid);
783
+ } catch (error) {
784
+ throw createClientAuthError(
785
+ ClientAuthErrorCodes.bindingKeyNotRemoved
786
+ );
787
+ }
788
+ }
789
+ }
790
+ }
791
+
792
+ return this.removeItem(key);
793
+ }
794
+
795
+ /**
796
+ * Removes all app metadata objects from cache.
797
+ */
798
+ removeAppMetadata(): boolean {
799
+ const allCacheKeys = this.getKeys();
800
+ allCacheKeys.forEach((cacheKey) => {
801
+ if (this.isAppMetadata(cacheKey)) {
802
+ this.removeItem(cacheKey);
803
+ }
804
+ });
805
+
806
+ return true;
807
+ }
808
+
809
+ /**
810
+ * Retrieve the cached credentials into a cacherecord
811
+ * @param account
812
+ * @param clientId
813
+ * @param scopes
814
+ * @param environment
815
+ * @param authScheme
816
+ */
817
+ readCacheRecord(
818
+ account: AccountInfo,
819
+ request: BaseAuthRequest,
820
+ environment: string
821
+ ): CacheRecord {
822
+ const tokenKeys = this.getTokenKeys();
823
+ const cachedAccount = this.readAccountFromCache(account);
824
+ const cachedIdToken = this.getIdToken(account, tokenKeys);
825
+ const cachedAccessToken = this.getAccessToken(
826
+ account,
827
+ request,
828
+ tokenKeys
829
+ );
830
+ const cachedRefreshToken = this.getRefreshToken(
831
+ account,
832
+ false,
833
+ tokenKeys
834
+ );
835
+ const cachedAppMetadata = this.readAppMetadataFromCache(environment);
836
+
837
+ if (cachedAccount && cachedIdToken) {
838
+ cachedAccount.idTokenClaims = extractTokenClaims(
839
+ cachedIdToken.secret,
840
+ this.cryptoImpl.base64Decode
841
+ );
842
+ }
843
+
844
+ return {
845
+ account: cachedAccount,
846
+ idToken: cachedIdToken,
847
+ accessToken: cachedAccessToken,
848
+ refreshToken: cachedRefreshToken,
849
+ appMetadata: cachedAppMetadata,
850
+ };
851
+ }
852
+
853
+ /**
854
+ * Retrieve AccountEntity from cache
855
+ * @param account
856
+ */
857
+ readAccountFromCache(account: AccountInfo): AccountEntity | null {
858
+ const accountKey: string =
859
+ AccountEntity.generateAccountCacheKey(account);
860
+ return this.getAccount(accountKey);
861
+ }
862
+
863
+ /**
864
+ * Retrieve IdTokenEntity from cache
865
+ * @param clientId
866
+ * @param account
867
+ * @param inputRealm
868
+ */
869
+ getIdToken(
870
+ account: AccountInfo,
871
+ tokenKeys?: TokenKeys
872
+ ): IdTokenEntity | null {
873
+ this.commonLogger.trace("CacheManager - getIdToken called");
874
+ const idTokenFilter: CredentialFilter = {
875
+ homeAccountId: account.homeAccountId,
876
+ environment: account.environment,
877
+ credentialType: CredentialType.ID_TOKEN,
878
+ clientId: this.clientId,
879
+ realm: account.tenantId,
880
+ };
881
+
882
+ const idTokens: IdTokenEntity[] = this.getIdTokensByFilter(
883
+ idTokenFilter,
884
+ tokenKeys
885
+ );
886
+ const numIdTokens = idTokens.length;
887
+
888
+ if (numIdTokens < 1) {
889
+ this.commonLogger.info("CacheManager:getIdToken - No token found");
890
+ return null;
891
+ } else if (numIdTokens > 1) {
892
+ this.commonLogger.info(
893
+ "CacheManager:getIdToken - Multiple id tokens found, clearing them"
894
+ );
895
+ idTokens.forEach((idToken) => {
896
+ this.removeIdToken(idToken.generateCredentialKey());
897
+ });
898
+ return null;
899
+ }
900
+
901
+ this.commonLogger.info("CacheManager:getIdToken - Returning id token");
902
+ return idTokens[0];
903
+ }
904
+
905
+ /**
906
+ * Gets all idTokens matching the given filter
907
+ * @param filter
908
+ * @returns
909
+ */
910
+ getIdTokensByFilter(
911
+ filter: CredentialFilter,
912
+ tokenKeys?: TokenKeys
913
+ ): IdTokenEntity[] {
914
+ const idTokenKeys =
915
+ (tokenKeys && tokenKeys.idToken) || this.getTokenKeys().idToken;
916
+
917
+ const idTokens: IdTokenEntity[] = [];
918
+ idTokenKeys.forEach((key) => {
919
+ if (
920
+ !this.idTokenKeyMatchesFilter(key, {
921
+ clientId: this.clientId,
922
+ ...filter,
923
+ })
924
+ ) {
925
+ return;
926
+ }
927
+
928
+ const idToken = this.getIdTokenCredential(key);
929
+ if (idToken && this.credentialMatchesFilter(idToken, filter)) {
930
+ idTokens.push(idToken);
931
+ }
932
+ });
933
+
934
+ return idTokens;
935
+ }
936
+
937
+ /**
938
+ * Validate the cache key against filter before retrieving and parsing cache value
939
+ * @param key
940
+ * @param filter
941
+ * @returns
942
+ */
943
+ idTokenKeyMatchesFilter(
944
+ inputKey: string,
945
+ filter: CredentialFilter
946
+ ): boolean {
947
+ const key = inputKey.toLowerCase();
948
+ if (
949
+ filter.clientId &&
950
+ key.indexOf(filter.clientId.toLowerCase()) === -1
951
+ ) {
952
+ return false;
953
+ }
954
+
955
+ if (
956
+ filter.homeAccountId &&
957
+ key.indexOf(filter.homeAccountId.toLowerCase()) === -1
958
+ ) {
959
+ return false;
960
+ }
961
+
962
+ return true;
963
+ }
964
+
965
+ /**
966
+ * Removes idToken from the cache
967
+ * @param key
968
+ */
969
+ removeIdToken(key: string): void {
970
+ this.removeItem(key);
971
+ }
972
+
973
+ /**
974
+ * Removes refresh token from the cache
975
+ * @param key
976
+ */
977
+ removeRefreshToken(key: string): void {
978
+ this.removeItem(key);
979
+ }
980
+
981
+ /**
982
+ * Retrieve AccessTokenEntity from cache
983
+ * @param clientId
984
+ * @param account
985
+ * @param scopes
986
+ * @param authScheme
987
+ */
988
+ getAccessToken(
989
+ account: AccountInfo,
990
+ request: BaseAuthRequest,
991
+ tokenKeys?: TokenKeys
992
+ ): AccessTokenEntity | null {
993
+ this.commonLogger.trace("CacheManager - getAccessToken called");
994
+ const scopes = ScopeSet.createSearchScopes(request.scopes);
995
+ const authScheme =
996
+ request.authenticationScheme || AuthenticationScheme.BEARER;
997
+ /*
998
+ * Distinguish between Bearer and PoP/SSH token cache types
999
+ * Cast to lowercase to handle "bearer" from ADFS
1000
+ */
1001
+ const credentialType =
1002
+ authScheme &&
1003
+ authScheme.toLowerCase() !==
1004
+ AuthenticationScheme.BEARER.toLowerCase()
1005
+ ? CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME
1006
+ : CredentialType.ACCESS_TOKEN;
1007
+
1008
+ const accessTokenFilter: CredentialFilter = {
1009
+ homeAccountId: account.homeAccountId,
1010
+ environment: account.environment,
1011
+ credentialType: credentialType,
1012
+ clientId: this.clientId,
1013
+ realm: account.tenantId,
1014
+ target: scopes,
1015
+ tokenType: authScheme,
1016
+ keyId: request.sshKid,
1017
+ requestedClaimsHash: request.requestedClaimsHash,
1018
+ };
1019
+
1020
+ const accessTokenKeys =
1021
+ (tokenKeys && tokenKeys.accessToken) ||
1022
+ this.getTokenKeys().accessToken;
1023
+ const accessTokens: AccessTokenEntity[] = [];
1024
+
1025
+ accessTokenKeys.forEach((key) => {
1026
+ // Validate key
1027
+ if (
1028
+ this.accessTokenKeyMatchesFilter(key, accessTokenFilter, true)
1029
+ ) {
1030
+ const accessToken = this.getAccessTokenCredential(key);
1031
+
1032
+ // Validate value
1033
+ if (
1034
+ accessToken &&
1035
+ this.credentialMatchesFilter(accessToken, accessTokenFilter)
1036
+ ) {
1037
+ accessTokens.push(accessToken);
1038
+ }
1039
+ }
1040
+ });
1041
+
1042
+ const numAccessTokens = accessTokens.length;
1043
+ if (numAccessTokens < 1) {
1044
+ this.commonLogger.info(
1045
+ "CacheManager:getAccessToken - No token found"
1046
+ );
1047
+ return null;
1048
+ } else if (numAccessTokens > 1) {
1049
+ this.commonLogger.info(
1050
+ "CacheManager:getAccessToken - Multiple access tokens found, clearing them"
1051
+ );
1052
+ accessTokens.forEach((accessToken) => {
1053
+ void this.removeAccessToken(
1054
+ accessToken.generateCredentialKey()
1055
+ );
1056
+ });
1057
+ return null;
1058
+ }
1059
+
1060
+ this.commonLogger.info(
1061
+ "CacheManager:getAccessToken - Returning access token"
1062
+ );
1063
+ return accessTokens[0];
1064
+ }
1065
+
1066
+ /**
1067
+ * Validate the cache key against filter before retrieving and parsing cache value
1068
+ * @param key
1069
+ * @param filter
1070
+ * @param keyMustContainAllScopes
1071
+ * @returns
1072
+ */
1073
+ accessTokenKeyMatchesFilter(
1074
+ inputKey: string,
1075
+ filter: CredentialFilter,
1076
+ keyMustContainAllScopes: boolean
1077
+ ): boolean {
1078
+ const key = inputKey.toLowerCase();
1079
+ if (
1080
+ filter.clientId &&
1081
+ key.indexOf(filter.clientId.toLowerCase()) === -1
1082
+ ) {
1083
+ return false;
1084
+ }
1085
+
1086
+ if (
1087
+ filter.homeAccountId &&
1088
+ key.indexOf(filter.homeAccountId.toLowerCase()) === -1
1089
+ ) {
1090
+ return false;
1091
+ }
1092
+
1093
+ if (filter.realm && key.indexOf(filter.realm.toLowerCase()) === -1) {
1094
+ return false;
1095
+ }
1096
+
1097
+ if (
1098
+ filter.requestedClaimsHash &&
1099
+ key.indexOf(filter.requestedClaimsHash.toLowerCase()) === -1
1100
+ ) {
1101
+ return false;
1102
+ }
1103
+
1104
+ if (filter.target) {
1105
+ const scopes = filter.target.asArray();
1106
+ for (let i = 0; i < scopes.length; i++) {
1107
+ if (
1108
+ keyMustContainAllScopes &&
1109
+ !key.includes(scopes[i].toLowerCase())
1110
+ ) {
1111
+ // When performing a cache lookup a missing scope would be a cache miss
1112
+ return false;
1113
+ } else if (
1114
+ !keyMustContainAllScopes &&
1115
+ key.includes(scopes[i].toLowerCase())
1116
+ ) {
1117
+ // When performing a cache write, any token with a subset of requested scopes should be replaced
1118
+ return true;
1119
+ }
1120
+ }
1121
+ }
1122
+
1123
+ return true;
1124
+ }
1125
+
1126
+ /**
1127
+ * Gets all access tokens matching the filter
1128
+ * @param filter
1129
+ * @returns
1130
+ */
1131
+ getAccessTokensByFilter(filter: CredentialFilter): AccessTokenEntity[] {
1132
+ const tokenKeys = this.getTokenKeys();
1133
+
1134
+ const accessTokens: AccessTokenEntity[] = [];
1135
+ tokenKeys.accessToken.forEach((key) => {
1136
+ if (!this.accessTokenKeyMatchesFilter(key, filter, true)) {
1137
+ return;
1138
+ }
1139
+
1140
+ const accessToken = this.getAccessTokenCredential(key);
1141
+ if (
1142
+ accessToken &&
1143
+ this.credentialMatchesFilter(accessToken, filter)
1144
+ ) {
1145
+ accessTokens.push(accessToken);
1146
+ }
1147
+ });
1148
+
1149
+ return accessTokens;
1150
+ }
1151
+
1152
+ /**
1153
+ * Helper to retrieve the appropriate refresh token from cache
1154
+ * @param clientId
1155
+ * @param account
1156
+ * @param familyRT
1157
+ */
1158
+ getRefreshToken(
1159
+ account: AccountInfo,
1160
+ familyRT: boolean,
1161
+ tokenKeys?: TokenKeys
1162
+ ): RefreshTokenEntity | null {
1163
+ this.commonLogger.trace("CacheManager - getRefreshToken called");
1164
+ const id = familyRT ? THE_FAMILY_ID : undefined;
1165
+ const refreshTokenFilter: CredentialFilter = {
1166
+ homeAccountId: account.homeAccountId,
1167
+ environment: account.environment,
1168
+ credentialType: CredentialType.REFRESH_TOKEN,
1169
+ clientId: this.clientId,
1170
+ familyId: id,
1171
+ };
1172
+
1173
+ const refreshTokenKeys =
1174
+ (tokenKeys && tokenKeys.refreshToken) ||
1175
+ this.getTokenKeys().refreshToken;
1176
+ const refreshTokens: RefreshTokenEntity[] = [];
1177
+
1178
+ refreshTokenKeys.forEach((key) => {
1179
+ // Validate key
1180
+ if (this.refreshTokenKeyMatchesFilter(key, refreshTokenFilter)) {
1181
+ const refreshToken = this.getRefreshTokenCredential(key);
1182
+ // Validate value
1183
+ if (
1184
+ refreshToken &&
1185
+ this.credentialMatchesFilter(
1186
+ refreshToken,
1187
+ refreshTokenFilter
1188
+ )
1189
+ ) {
1190
+ refreshTokens.push(refreshToken);
1191
+ }
1192
+ }
1193
+ });
1194
+
1195
+ const numRefreshTokens = refreshTokens.length;
1196
+ if (numRefreshTokens < 1) {
1197
+ this.commonLogger.info(
1198
+ "CacheManager:getRefreshToken - No refresh token found."
1199
+ );
1200
+ return null;
1201
+ }
1202
+ // address the else case after remove functions address environment aliases
1203
+
1204
+ this.commonLogger.info(
1205
+ "CacheManager:getRefreshToken - returning refresh token"
1206
+ );
1207
+ return refreshTokens[0] as RefreshTokenEntity;
1208
+ }
1209
+
1210
+ /**
1211
+ * Validate the cache key against filter before retrieving and parsing cache value
1212
+ * @param key
1213
+ * @param filter
1214
+ */
1215
+ refreshTokenKeyMatchesFilter(
1216
+ inputKey: string,
1217
+ filter: CredentialFilter
1218
+ ): boolean {
1219
+ const key = inputKey.toLowerCase();
1220
+ if (
1221
+ filter.familyId &&
1222
+ key.indexOf(filter.familyId.toLowerCase()) === -1
1223
+ ) {
1224
+ return false;
1225
+ }
1226
+
1227
+ // If familyId is used, clientId is not in the key
1228
+ if (
1229
+ !filter.familyId &&
1230
+ filter.clientId &&
1231
+ key.indexOf(filter.clientId.toLowerCase()) === -1
1232
+ ) {
1233
+ return false;
1234
+ }
1235
+
1236
+ if (
1237
+ filter.homeAccountId &&
1238
+ key.indexOf(filter.homeAccountId.toLowerCase()) === -1
1239
+ ) {
1240
+ return false;
1241
+ }
1242
+
1243
+ return true;
1244
+ }
1245
+
1246
+ /**
1247
+ * Retrieve AppMetadataEntity from cache
1248
+ */
1249
+ readAppMetadataFromCache(environment: string): AppMetadataEntity | null {
1250
+ const appMetadataFilter: AppMetadataFilter = {
1251
+ environment,
1252
+ clientId: this.clientId,
1253
+ };
1254
+
1255
+ const appMetadata: AppMetadataCache =
1256
+ this.getAppMetadataFilteredBy(appMetadataFilter);
1257
+ const appMetadataEntries: AppMetadataEntity[] = Object.keys(
1258
+ appMetadata
1259
+ ).map((key) => appMetadata[key]);
1260
+
1261
+ const numAppMetadata = appMetadataEntries.length;
1262
+ if (numAppMetadata < 1) {
1263
+ return null;
1264
+ } else if (numAppMetadata > 1) {
1265
+ throw createClientAuthError(
1266
+ ClientAuthErrorCodes.multipleMatchingAppMetadata
1267
+ );
1268
+ }
1269
+
1270
+ return appMetadataEntries[0] as AppMetadataEntity;
1271
+ }
1272
+
1273
+ /**
1274
+ * Return the family_id value associated with FOCI
1275
+ * @param environment
1276
+ * @param clientId
1277
+ */
1278
+ isAppMetadataFOCI(environment: string): boolean {
1279
+ const appMetadata = this.readAppMetadataFromCache(environment);
1280
+ return !!(appMetadata && appMetadata.familyId === THE_FAMILY_ID);
1281
+ }
1282
+
1283
+ /**
1284
+ * helper to match account ids
1285
+ * @param value
1286
+ * @param homeAccountId
1287
+ */
1288
+ private matchHomeAccountId(
1289
+ entity: AccountEntity | CredentialEntity,
1290
+ homeAccountId: string
1291
+ ): boolean {
1292
+ return !!(
1293
+ typeof entity.homeAccountId === "string" &&
1294
+ homeAccountId === entity.homeAccountId
1295
+ );
1296
+ }
1297
+
1298
+ /**
1299
+ * helper to match account ids
1300
+ * @param entity
1301
+ * @param localAccountId
1302
+ * @returns
1303
+ */
1304
+ private matchLocalAccountId(
1305
+ entity: AccountEntity,
1306
+ localAccountId: string
1307
+ ): boolean {
1308
+ return !!(
1309
+ typeof entity.localAccountId === "string" &&
1310
+ localAccountId === entity.localAccountId
1311
+ );
1312
+ }
1313
+
1314
+ /**
1315
+ * helper to match usernames
1316
+ * @param entity
1317
+ * @param username
1318
+ * @returns
1319
+ */
1320
+ private matchUsername(entity: AccountEntity, username: string): boolean {
1321
+ return !!(
1322
+ typeof entity.username === "string" &&
1323
+ username.toLowerCase() === entity.username.toLowerCase()
1324
+ );
1325
+ }
1326
+
1327
+ /**
1328
+ * helper to match assertion
1329
+ * @param value
1330
+ * @param oboAssertion
1331
+ */
1332
+ private matchUserAssertionHash(
1333
+ entity: CredentialEntity,
1334
+ userAssertionHash: string
1335
+ ): boolean {
1336
+ return !!(
1337
+ entity.userAssertionHash &&
1338
+ userAssertionHash === entity.userAssertionHash
1339
+ );
1340
+ }
1341
+
1342
+ /**
1343
+ * helper to match environment
1344
+ * @param value
1345
+ * @param environment
1346
+ */
1347
+ private matchEnvironment(
1348
+ entity: AccountEntity | CredentialEntity | AppMetadataEntity,
1349
+ environment: string
1350
+ ): boolean {
1351
+ const cloudMetadata = this.getAuthorityMetadataByAlias(environment);
1352
+ if (
1353
+ cloudMetadata &&
1354
+ cloudMetadata.aliases.indexOf(entity.environment) > -1
1355
+ ) {
1356
+ return true;
1357
+ }
1358
+
1359
+ return false;
1360
+ }
1361
+
1362
+ /**
1363
+ * helper to match credential type
1364
+ * @param entity
1365
+ * @param credentialType
1366
+ */
1367
+ private matchCredentialType(
1368
+ entity: CredentialEntity,
1369
+ credentialType: string
1370
+ ): boolean {
1371
+ return (
1372
+ entity.credentialType &&
1373
+ credentialType.toLowerCase() === entity.credentialType.toLowerCase()
1374
+ );
1375
+ }
1376
+
1377
+ /**
1378
+ * helper to match client ids
1379
+ * @param entity
1380
+ * @param clientId
1381
+ */
1382
+ private matchClientId(
1383
+ entity: CredentialEntity | AppMetadataEntity,
1384
+ clientId: string
1385
+ ): boolean {
1386
+ return !!(entity.clientId && clientId === entity.clientId);
1387
+ }
1388
+
1389
+ /**
1390
+ * helper to match family ids
1391
+ * @param entity
1392
+ * @param familyId
1393
+ */
1394
+ private matchFamilyId(
1395
+ entity: CredentialEntity | AppMetadataEntity,
1396
+ familyId: string
1397
+ ): boolean {
1398
+ return !!(entity.familyId && familyId === entity.familyId);
1399
+ }
1400
+
1401
+ /**
1402
+ * helper to match realm
1403
+ * @param entity
1404
+ * @param realm
1405
+ */
1406
+ private matchRealm(
1407
+ entity: AccountEntity | CredentialEntity,
1408
+ realm: string
1409
+ ): boolean {
1410
+ return !!(entity.realm && realm === entity.realm);
1411
+ }
1412
+
1413
+ /**
1414
+ * helper to match nativeAccountId
1415
+ * @param entity
1416
+ * @param nativeAccountId
1417
+ * @returns boolean indicating the match result
1418
+ */
1419
+ private matchNativeAccountId(
1420
+ entity: AccountEntity,
1421
+ nativeAccountId: string
1422
+ ): boolean {
1423
+ return !!(
1424
+ entity.nativeAccountId && nativeAccountId === entity.nativeAccountId
1425
+ );
1426
+ }
1427
+
1428
+ /**
1429
+ * Returns true if the target scopes are a subset of the current entity's scopes, false otherwise.
1430
+ * @param entity
1431
+ * @param target
1432
+ */
1433
+ private matchTarget(entity: CredentialEntity, target: ScopeSet): boolean {
1434
+ const isNotAccessTokenCredential =
1435
+ entity.credentialType !== CredentialType.ACCESS_TOKEN &&
1436
+ entity.credentialType !==
1437
+ CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;
1438
+
1439
+ if (isNotAccessTokenCredential || !entity.target) {
1440
+ return false;
1441
+ }
1442
+
1443
+ const entityScopeSet: ScopeSet = ScopeSet.fromString(entity.target);
1444
+
1445
+ return entityScopeSet.containsScopeSet(target);
1446
+ }
1447
+
1448
+ /**
1449
+ * Returns true if the credential's tokenType or Authentication Scheme matches the one in the request, false otherwise
1450
+ * @param entity
1451
+ * @param tokenType
1452
+ */
1453
+ private matchTokenType(
1454
+ entity: CredentialEntity,
1455
+ tokenType: AuthenticationScheme
1456
+ ): boolean {
1457
+ return !!(entity.tokenType && entity.tokenType === tokenType);
1458
+ }
1459
+
1460
+ /**
1461
+ * Returns true if the credential's keyId matches the one in the request, false otherwise
1462
+ * @param entity
1463
+ * @param tokenType
1464
+ */
1465
+ private matchKeyId(entity: CredentialEntity, keyId: string): boolean {
1466
+ return !!(entity.keyId && entity.keyId === keyId);
1467
+ }
1468
+
1469
+ /**
1470
+ * returns if a given cache entity is of the type appmetadata
1471
+ * @param key
1472
+ */
1473
+ private isAppMetadata(key: string): boolean {
1474
+ return key.indexOf(APP_METADATA) !== -1;
1475
+ }
1476
+
1477
+ /**
1478
+ * returns if a given cache entity is of the type authoritymetadata
1479
+ * @param key
1480
+ */
1481
+ protected isAuthorityMetadata(key: string): boolean {
1482
+ return key.indexOf(AUTHORITY_METADATA_CONSTANTS.CACHE_KEY) !== -1;
1483
+ }
1484
+
1485
+ /**
1486
+ * returns cache key used for cloud instance metadata
1487
+ */
1488
+ generateAuthorityMetadataCacheKey(authority: string): string {
1489
+ return `${AUTHORITY_METADATA_CONSTANTS.CACHE_KEY}-${this.clientId}-${authority}`;
1490
+ }
1491
+
1492
+ /**
1493
+ * Helper to convert serialized data to object
1494
+ * @param obj
1495
+ * @param json
1496
+ */
1497
+ static toObject<T>(obj: T, json: object): T {
1498
+ for (const propertyName in json) {
1499
+ obj[propertyName] = json[propertyName];
1500
+ }
1501
+ return obj;
1502
+ }
1503
+ }
1504
+
1505
+ /** @internal */
1506
+ export class DefaultStorageClass extends CacheManager {
1507
+ setAccount(): void {
1508
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1509
+ }
1510
+ getAccount(): AccountEntity {
1511
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1512
+ }
1513
+ setIdTokenCredential(): void {
1514
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1515
+ }
1516
+ getIdTokenCredential(): IdTokenEntity {
1517
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1518
+ }
1519
+ setAccessTokenCredential(): void {
1520
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1521
+ }
1522
+ getAccessTokenCredential(): AccessTokenEntity {
1523
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1524
+ }
1525
+ setRefreshTokenCredential(): void {
1526
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1527
+ }
1528
+ getRefreshTokenCredential(): RefreshTokenEntity {
1529
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1530
+ }
1531
+ setAppMetadata(): void {
1532
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1533
+ }
1534
+ getAppMetadata(): AppMetadataEntity {
1535
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1536
+ }
1537
+ setServerTelemetry(): void {
1538
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1539
+ }
1540
+ getServerTelemetry(): ServerTelemetryEntity {
1541
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1542
+ }
1543
+ setAuthorityMetadata(): void {
1544
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1545
+ }
1546
+ getAuthorityMetadata(): AuthorityMetadataEntity | null {
1547
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1548
+ }
1549
+ getAuthorityMetadataKeys(): Array<string> {
1550
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1551
+ }
1552
+ setThrottlingCache(): void {
1553
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1554
+ }
1555
+ getThrottlingCache(): ThrottlingEntity {
1556
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1557
+ }
1558
+ removeItem(): boolean {
1559
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1560
+ }
1561
+ containsKey(): boolean {
1562
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1563
+ }
1564
+ getKeys(): string[] {
1565
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1566
+ }
1567
+ getAccountKeys(): string[] {
1568
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1569
+ }
1570
+ getTokenKeys(): TokenKeys {
1571
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1572
+ }
1573
+ async clear(): Promise<void> {
1574
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1575
+ }
1576
+ updateCredentialCacheKey(): string {
1577
+ throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
1578
+ }
1579
+ }