@azure/msal-common 14.0.1 → 14.0.3

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 (295) hide show
  1. package/dist/account/AuthToken.d.ts +14 -17
  2. package/dist/account/AuthToken.d.ts.map +1 -1
  3. package/dist/account/AuthToken.mjs +48 -39
  4. package/dist/account/AuthToken.mjs.map +1 -1
  5. package/dist/account/CcsCredential.mjs +1 -1
  6. package/dist/account/CcsCredential.mjs.map +1 -1
  7. package/dist/account/ClientInfo.d.ts.map +1 -1
  8. package/dist/account/ClientInfo.mjs +3 -4
  9. package/dist/account/ClientInfo.mjs.map +1 -1
  10. package/dist/authority/Authority.d.ts +1 -0
  11. package/dist/authority/Authority.d.ts.map +1 -1
  12. package/dist/authority/Authority.mjs +4 -2
  13. package/dist/authority/Authority.mjs.map +1 -1
  14. package/dist/authority/AuthorityFactory.d.ts +1 -0
  15. package/dist/authority/AuthorityFactory.d.ts.map +1 -1
  16. package/dist/authority/AuthorityFactory.mjs +3 -3
  17. package/dist/authority/AuthorityFactory.mjs.map +1 -1
  18. package/dist/authority/AuthorityMetadata.mjs +1 -1
  19. package/dist/authority/AuthorityMetadata.mjs.map +1 -1
  20. package/dist/authority/AuthorityOptions.mjs +1 -1
  21. package/dist/authority/AuthorityOptions.mjs.map +1 -1
  22. package/dist/authority/AuthorityType.mjs +1 -1
  23. package/dist/authority/AuthorityType.mjs.map +1 -1
  24. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  25. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs.map +1 -1
  26. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  27. package/dist/authority/CloudInstanceDiscoveryResponse.mjs.map +1 -1
  28. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  29. package/dist/authority/OpenIdConfigResponse.mjs.map +1 -1
  30. package/dist/authority/ProtocolMode.mjs +1 -1
  31. package/dist/authority/ProtocolMode.mjs.map +1 -1
  32. package/dist/authority/RegionDiscovery.mjs +1 -1
  33. package/dist/authority/RegionDiscovery.mjs.map +1 -1
  34. package/dist/cache/CacheManager.d.ts +2 -0
  35. package/dist/cache/CacheManager.d.ts.map +1 -1
  36. package/dist/cache/CacheManager.mjs +7 -5
  37. package/dist/cache/CacheManager.mjs.map +1 -1
  38. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  39. package/dist/cache/entities/AccessTokenEntity.mjs +4 -7
  40. package/dist/cache/entities/AccessTokenEntity.mjs.map +1 -1
  41. package/dist/cache/entities/AccountEntity.d.ts +1 -0
  42. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  43. package/dist/cache/entities/AccountEntity.mjs +3 -4
  44. package/dist/cache/entities/AccountEntity.mjs.map +1 -1
  45. package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
  46. package/dist/cache/entities/AppMetadataEntity.mjs.map +1 -1
  47. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +1 -0
  48. package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
  49. package/dist/cache/entities/AuthorityMetadataEntity.mjs +2 -1
  50. package/dist/cache/entities/AuthorityMetadataEntity.mjs.map +1 -1
  51. package/dist/cache/entities/CacheRecord.d.ts +1 -0
  52. package/dist/cache/entities/CacheRecord.d.ts.map +1 -1
  53. package/dist/cache/entities/CacheRecord.mjs +2 -1
  54. package/dist/cache/entities/CacheRecord.mjs.map +1 -1
  55. package/dist/cache/entities/CredentialEntity.mjs +1 -1
  56. package/dist/cache/entities/CredentialEntity.mjs.map +1 -1
  57. package/dist/cache/entities/IdTokenEntity.mjs +1 -1
  58. package/dist/cache/entities/IdTokenEntity.mjs.map +1 -1
  59. package/dist/cache/entities/RefreshTokenEntity.mjs +1 -1
  60. package/dist/cache/entities/RefreshTokenEntity.mjs.map +1 -1
  61. package/dist/cache/entities/ServerTelemetryEntity.mjs +1 -1
  62. package/dist/cache/entities/ServerTelemetryEntity.mjs.map +1 -1
  63. package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
  64. package/dist/cache/entities/ThrottlingEntity.mjs.map +1 -1
  65. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  66. package/dist/cache/persistence/TokenCacheContext.mjs.map +1 -1
  67. package/dist/cache/utils/CacheTypes.d.ts +7 -0
  68. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  69. package/dist/client/AuthorizationCodeClient.d.ts +1 -0
  70. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  71. package/dist/client/AuthorizationCodeClient.mjs +11 -39
  72. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  73. package/dist/client/BaseClient.d.ts +2 -1
  74. package/dist/client/BaseClient.d.ts.map +1 -1
  75. package/dist/client/BaseClient.mjs +9 -2
  76. package/dist/client/BaseClient.mjs.map +1 -1
  77. package/dist/client/RefreshTokenClient.d.ts +1 -0
  78. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  79. package/dist/client/RefreshTokenClient.mjs +3 -11
  80. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  81. package/dist/client/SilentFlowClient.d.ts +1 -0
  82. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  83. package/dist/client/SilentFlowClient.mjs +8 -7
  84. package/dist/client/SilentFlowClient.mjs.map +1 -1
  85. package/dist/config/ClientConfiguration.d.ts +2 -0
  86. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  87. package/dist/config/ClientConfiguration.mjs +1 -1
  88. package/dist/config/ClientConfiguration.mjs.map +1 -1
  89. package/dist/crypto/ICrypto.mjs +1 -1
  90. package/dist/crypto/ICrypto.mjs.map +1 -1
  91. package/dist/crypto/JoseHeader.d.ts +1 -0
  92. package/dist/crypto/JoseHeader.d.ts.map +1 -1
  93. package/dist/crypto/JoseHeader.mjs +2 -1
  94. package/dist/crypto/JoseHeader.mjs.map +1 -1
  95. package/dist/crypto/PopTokenGenerator.d.ts +1 -0
  96. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  97. package/dist/crypto/PopTokenGenerator.mjs +2 -1
  98. package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
  99. package/dist/error/AuthError.mjs +1 -1
  100. package/dist/error/AuthError.mjs.map +1 -1
  101. package/dist/error/ClientAuthError.mjs +1 -1
  102. package/dist/error/ClientAuthError.mjs.map +1 -1
  103. package/dist/error/ClientConfigurationError.mjs +1 -1
  104. package/dist/error/ClientConfigurationError.mjs.map +1 -1
  105. package/dist/error/InteractionRequiredAuthError.mjs +1 -1
  106. package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
  107. package/dist/error/JoseHeaderError.mjs +1 -1
  108. package/dist/error/JoseHeaderError.mjs.map +1 -1
  109. package/dist/error/ServerError.mjs +1 -1
  110. package/dist/error/ServerError.mjs.map +1 -1
  111. package/dist/index.cjs +1926 -1826
  112. package/dist/index.cjs.map +1 -1
  113. package/dist/index.d.ts +4 -3
  114. package/dist/index.d.ts.map +1 -1
  115. package/dist/index.mjs +5 -3
  116. package/dist/index.mjs.map +1 -1
  117. package/dist/logger/Logger.d.ts.map +1 -1
  118. package/dist/logger/Logger.mjs +2 -12
  119. package/dist/logger/Logger.mjs.map +1 -1
  120. package/dist/network/INetworkModule.mjs +1 -1
  121. package/dist/network/INetworkModule.mjs.map +1 -1
  122. package/dist/network/NetworkManager.d.ts +1 -0
  123. package/dist/network/NetworkManager.d.ts.map +1 -1
  124. package/dist/network/NetworkManager.mjs +2 -1
  125. package/dist/network/NetworkManager.mjs.map +1 -1
  126. package/dist/network/ThrottlingUtils.d.ts +1 -0
  127. package/dist/network/ThrottlingUtils.d.ts.map +1 -1
  128. package/dist/network/ThrottlingUtils.mjs +2 -1
  129. package/dist/network/ThrottlingUtils.mjs.map +1 -1
  130. package/dist/packageMetadata.d.ts +1 -1
  131. package/dist/packageMetadata.mjs +2 -2
  132. package/dist/packageMetadata.mjs.map +1 -1
  133. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  134. package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
  135. package/dist/request/RequestParameterBuilder.d.ts +1 -0
  136. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  137. package/dist/request/RequestParameterBuilder.mjs +7 -7
  138. package/dist/request/RequestParameterBuilder.mjs.map +1 -1
  139. package/dist/request/RequestValidator.d.ts.map +1 -1
  140. package/dist/request/RequestValidator.mjs +4 -6
  141. package/dist/request/RequestValidator.mjs.map +1 -1
  142. package/dist/request/ScopeSet.mjs +4 -4
  143. package/dist/request/ScopeSet.mjs.map +1 -1
  144. package/dist/response/AuthenticationResult.d.ts +3 -1
  145. package/dist/response/AuthenticationResult.d.ts.map +1 -1
  146. package/dist/response/ResponseHandler.d.ts +5 -3
  147. package/dist/response/ResponseHandler.d.ts.map +1 -1
  148. package/dist/response/ResponseHandler.mjs +58 -39
  149. package/dist/response/ResponseHandler.mjs.map +1 -1
  150. package/dist/response/ServerAuthorizationTokenResponse.d.ts +2 -0
  151. package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
  152. package/dist/telemetry/performance/IPerformanceClient.d.ts +4 -4
  153. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
  154. package/dist/telemetry/performance/PerformanceClient.d.ts +2 -2
  155. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  156. package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
  157. package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
  158. package/dist/telemetry/performance/PerformanceEvent.d.ts +8 -1
  159. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  160. package/dist/telemetry/performance/PerformanceEvent.mjs +9 -1
  161. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  162. package/dist/telemetry/performance/StubPerformanceClient.d.ts +3 -3
  163. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
  164. package/dist/telemetry/performance/StubPerformanceClient.mjs +23 -3
  165. package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -1
  166. package/dist/telemetry/server/ServerTelemetryManager.d.ts +1 -0
  167. package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
  168. package/dist/telemetry/server/ServerTelemetryManager.mjs +4 -4
  169. package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
  170. package/dist/url/UrlString.d.ts.map +1 -1
  171. package/dist/url/UrlString.mjs +10 -12
  172. package/dist/url/UrlString.mjs.map +1 -1
  173. package/dist/utils/Constants.d.ts +10 -0
  174. package/dist/utils/Constants.d.ts.map +1 -1
  175. package/dist/utils/Constants.mjs +11 -2
  176. package/dist/utils/Constants.mjs.map +1 -1
  177. package/dist/utils/FunctionWrappers.d.ts +28 -0
  178. package/dist/utils/FunctionWrappers.d.ts.map +1 -0
  179. package/dist/utils/FunctionWrappers.mjs +90 -0
  180. package/dist/utils/FunctionWrappers.mjs.map +1 -0
  181. package/dist/utils/ProtocolUtils.d.ts.map +1 -1
  182. package/dist/utils/ProtocolUtils.mjs +4 -7
  183. package/dist/utils/ProtocolUtils.mjs.map +1 -1
  184. package/dist/utils/StringUtils.d.ts +0 -13
  185. package/dist/utils/StringUtils.d.ts.map +1 -1
  186. package/dist/utils/StringUtils.mjs +3 -34
  187. package/dist/utils/StringUtils.mjs.map +1 -1
  188. package/dist/utils/TimeUtils.mjs +1 -1
  189. package/dist/utils/TimeUtils.mjs.map +1 -1
  190. package/package.json +6 -4
  191. package/src/account/AccountInfo.ts +44 -0
  192. package/src/account/AuthToken.ts +70 -0
  193. package/src/account/CcsCredential.ts +16 -0
  194. package/src/account/ClientCredentials.ts +20 -0
  195. package/src/account/ClientInfo.ts +64 -0
  196. package/src/account/TokenClaims.ts +70 -0
  197. package/src/authority/Authority.ts +1225 -0
  198. package/src/authority/AuthorityFactory.ts +106 -0
  199. package/src/authority/AuthorityMetadata.ts +953 -0
  200. package/src/authority/AuthorityOptions.ts +40 -0
  201. package/src/authority/AuthorityType.ts +15 -0
  202. package/src/authority/AzureRegion.ts +7 -0
  203. package/src/authority/AzureRegionConfiguration.ts +16 -0
  204. package/src/authority/CloudDiscoveryMetadata.ts +10 -0
  205. package/src/authority/CloudInstanceDiscoveryErrorResponse.ts +26 -0
  206. package/src/authority/CloudInstanceDiscoveryResponse.ts +21 -0
  207. package/src/authority/ImdsOptions.ts +10 -0
  208. package/src/authority/OIDCOptions.ts +14 -0
  209. package/src/authority/OpenIdConfigResponse.ts +24 -0
  210. package/src/authority/ProtocolMode.ts +13 -0
  211. package/src/authority/RegionDiscovery.ts +193 -0
  212. package/src/authority/RegionDiscoveryMetadata.ts +15 -0
  213. package/src/broker/nativeBroker/INativeBrokerPlugin.ts +29 -0
  214. package/src/cache/CacheManager.ts +1619 -0
  215. package/src/cache/entities/AccessTokenEntity.ts +162 -0
  216. package/src/cache/entities/AccountEntity.ts +309 -0
  217. package/src/cache/entities/AppMetadataEntity.ts +91 -0
  218. package/src/cache/entities/AuthorityMetadataEntity.ts +112 -0
  219. package/src/cache/entities/CacheRecord.ts +33 -0
  220. package/src/cache/entities/CredentialEntity.ts +215 -0
  221. package/src/cache/entities/IdTokenEntity.ts +74 -0
  222. package/src/cache/entities/RefreshTokenEntity.ts +78 -0
  223. package/src/cache/entities/ServerTelemetryEntity.ts +38 -0
  224. package/src/cache/entities/ThrottlingEntity.ts +36 -0
  225. package/src/cache/interface/ICacheManager.ts +218 -0
  226. package/src/cache/interface/ICachePlugin.ts +11 -0
  227. package/src/cache/interface/ISerializableTokenCache.ts +9 -0
  228. package/src/cache/persistence/TokenCacheContext.ts +39 -0
  229. package/src/cache/utils/CacheTypes.ts +93 -0
  230. package/src/client/AuthorizationCodeClient.ts +714 -0
  231. package/src/client/BaseClient.ts +205 -0
  232. package/src/client/RefreshTokenClient.ts +442 -0
  233. package/src/client/SilentFlowClient.ts +186 -0
  234. package/src/config/AppTokenProvider.ts +47 -0
  235. package/src/config/ClientConfiguration.ts +287 -0
  236. package/src/crypto/ICrypto.ts +127 -0
  237. package/src/crypto/IGuidGenerator.ts +9 -0
  238. package/src/crypto/JoseHeader.ts +55 -0
  239. package/src/crypto/PopTokenGenerator.ts +155 -0
  240. package/src/crypto/SignedHttpRequest.ts +16 -0
  241. package/src/error/AuthError.ts +85 -0
  242. package/src/error/ClientAuthError.ts +738 -0
  243. package/src/error/ClientConfigurationError.ts +396 -0
  244. package/src/error/InteractionRequiredAuthError.ts +134 -0
  245. package/src/error/JoseHeaderError.ts +52 -0
  246. package/src/error/ServerError.ts +18 -0
  247. package/src/index.ts +215 -0
  248. package/src/logger/Logger.ts +272 -0
  249. package/src/network/INetworkModule.ts +57 -0
  250. package/src/network/NetworkManager.ts +76 -0
  251. package/src/network/RequestThumbprint.ts +22 -0
  252. package/src/network/ThrottlingUtils.ts +156 -0
  253. package/src/packageMetadata.ts +3 -0
  254. package/src/request/AuthenticationHeaderParser.ts +89 -0
  255. package/src/request/BaseAuthRequest.ts +46 -0
  256. package/src/request/CommonAuthorizationCodeRequest.ts +33 -0
  257. package/src/request/CommonAuthorizationUrlRequest.ts +56 -0
  258. package/src/request/CommonClientCredentialRequest.ts +23 -0
  259. package/src/request/CommonDeviceCodeRequest.ts +31 -0
  260. package/src/request/CommonEndSessionRequest.ts +27 -0
  261. package/src/request/CommonOnBehalfOfRequest.ts +19 -0
  262. package/src/request/CommonRefreshTokenRequest.ts +25 -0
  263. package/src/request/CommonSilentFlowRequest.ts +24 -0
  264. package/src/request/CommonUsernamePasswordRequest.ts +23 -0
  265. package/src/request/NativeRequest.ts +25 -0
  266. package/src/request/NativeSignOutRequest.ts +10 -0
  267. package/src/request/RequestParameterBuilder.ts +606 -0
  268. package/src/request/RequestValidator.ts +103 -0
  269. package/src/request/ScopeSet.ts +230 -0
  270. package/src/request/StoreInCache.ts +16 -0
  271. package/src/response/AuthenticationResult.ts +47 -0
  272. package/src/response/AuthorizationCodePayload.ts +18 -0
  273. package/src/response/DeviceCodeResponse.ts +31 -0
  274. package/src/response/ExternalTokenResponse.ts +24 -0
  275. package/src/response/IMDSBadResponse.ts +9 -0
  276. package/src/response/ResponseHandler.ts +614 -0
  277. package/src/response/ServerAuthorizationCodeResponse.ts +33 -0
  278. package/src/response/ServerAuthorizationTokenResponse.ts +54 -0
  279. package/src/telemetry/performance/IPerformanceClient.ts +71 -0
  280. package/src/telemetry/performance/IPerformanceMeasurement.ts +10 -0
  281. package/src/telemetry/performance/PerformanceClient.ts +635 -0
  282. package/src/telemetry/performance/PerformanceEvent.ts +542 -0
  283. package/src/telemetry/performance/StubPerformanceClient.ts +101 -0
  284. package/src/telemetry/server/ServerTelemetryManager.ts +274 -0
  285. package/src/telemetry/server/ServerTelemetryRequest.ts +13 -0
  286. package/src/url/IUri.ts +17 -0
  287. package/src/url/UrlString.ts +363 -0
  288. package/src/utils/Constants.ts +436 -0
  289. package/src/utils/FunctionWrappers.ts +105 -0
  290. package/src/utils/MsalTypes.ts +9 -0
  291. package/src/utils/ProtocolUtils.ts +124 -0
  292. package/src/utils/StringUtils.ts +106 -0
  293. package/src/utils/TimeUtils.ts +51 -0
  294. package/dist/account/DecodedAuthToken.d.ts +0 -9
  295. package/dist/account/DecodedAuthToken.d.ts.map +0 -1
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { IdTokenEntity } from "./IdTokenEntity";
7
+ import { AccessTokenEntity } from "./AccessTokenEntity";
8
+ import { RefreshTokenEntity } from "./RefreshTokenEntity";
9
+ import { AccountEntity } from "./AccountEntity";
10
+ import { AppMetadataEntity } from "./AppMetadataEntity";
11
+
12
+ /** @internal */
13
+ export class CacheRecord {
14
+ account: AccountEntity | null;
15
+ idToken: IdTokenEntity | null;
16
+ accessToken: AccessTokenEntity | null;
17
+ refreshToken: RefreshTokenEntity | null;
18
+ appMetadata: AppMetadataEntity | null;
19
+
20
+ constructor(
21
+ accountEntity?: AccountEntity | null,
22
+ idTokenEntity?: IdTokenEntity | null,
23
+ accessTokenEntity?: AccessTokenEntity | null,
24
+ refreshTokenEntity?: RefreshTokenEntity | null,
25
+ appMetadataEntity?: AppMetadataEntity | null
26
+ ) {
27
+ this.account = accountEntity || null;
28
+ this.idToken = idTokenEntity || null;
29
+ this.accessToken = accessTokenEntity || null;
30
+ this.refreshToken = refreshTokenEntity || null;
31
+ this.appMetadata = appMetadataEntity || null;
32
+ }
33
+ }
@@ -0,0 +1,215 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ Separators,
8
+ CredentialType,
9
+ CacheType,
10
+ Constants,
11
+ AuthenticationScheme,
12
+ } from "../../utils/Constants";
13
+ import { ClientAuthError } from "../../error/ClientAuthError";
14
+
15
+ /**
16
+ * Base type for credentials to be stored in the cache: eg: ACCESS_TOKEN, ID_TOKEN etc
17
+ *
18
+ * Key:Value Schema:
19
+ *
20
+ * Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<requestedClaims*>-<scheme*>
21
+ *
22
+ * Value Schema:
23
+ * {
24
+ * homeAccountId: home account identifier for the auth scheme,
25
+ * environment: entity that issued the token, represented as a full host
26
+ * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
27
+ * clientId: client ID of the application
28
+ * secret: Actual credential as a string
29
+ * familyId: Family ID identifier, usually only used for refresh tokens
30
+ * realm: Full tenant or organizational identifier that the account belongs to
31
+ * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
32
+ * tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
33
+ * requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request
34
+ * userAssertionHash: Matches the SHA 256 hash of the obo_assertion for the OBO flow
35
+ * }
36
+ */
37
+ export class CredentialEntity {
38
+ homeAccountId: string;
39
+ environment: string;
40
+ credentialType: CredentialType;
41
+ clientId: string;
42
+ secret: string;
43
+ familyId?: string;
44
+ realm?: string;
45
+ target?: string;
46
+ userAssertionHash?: string;
47
+ tokenType?: AuthenticationScheme;
48
+ keyId?: string;
49
+ requestedClaimsHash?: string;
50
+
51
+ /**
52
+ * Generate Account Id key component as per the schema: <home_account_id>-<environment>
53
+ */
54
+ generateAccountId(): string {
55
+ return CredentialEntity.generateAccountIdForCacheKey(
56
+ this.homeAccountId,
57
+ this.environment
58
+ );
59
+ }
60
+
61
+ /**
62
+ * Generate Credential Id key component as per the schema: <credential_type>-<client_id>-<realm>
63
+ */
64
+ generateCredentialId(): string {
65
+ return CredentialEntity.generateCredentialIdForCacheKey(
66
+ this.credentialType,
67
+ this.clientId,
68
+ this.realm,
69
+ this.familyId
70
+ );
71
+ }
72
+
73
+ /**
74
+ * Generate target key component as per schema: <target>
75
+ */
76
+ generateTarget(): string {
77
+ return CredentialEntity.generateTargetForCacheKey(this.target);
78
+ }
79
+
80
+ /**
81
+ * generates credential key
82
+ */
83
+ generateCredentialKey(): string {
84
+ return CredentialEntity.generateCredentialCacheKey(
85
+ this.homeAccountId,
86
+ this.environment,
87
+ this.credentialType,
88
+ this.clientId,
89
+ this.realm,
90
+ this.target,
91
+ this.familyId,
92
+ this.tokenType,
93
+ this.requestedClaimsHash
94
+ );
95
+ }
96
+
97
+ /**
98
+ * returns the type of the cache (in this case credential)
99
+ */
100
+ generateType(): number {
101
+ switch (this.credentialType) {
102
+ case CredentialType.ID_TOKEN:
103
+ return CacheType.ID_TOKEN;
104
+ case CredentialType.ACCESS_TOKEN:
105
+ case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
106
+ return CacheType.ACCESS_TOKEN;
107
+ case CredentialType.REFRESH_TOKEN:
108
+ return CacheType.REFRESH_TOKEN;
109
+ default: {
110
+ throw ClientAuthError.createUnexpectedCredentialTypeError();
111
+ }
112
+ }
113
+ }
114
+
115
+ /**
116
+ * generates credential key
117
+ * <home_account_id*>-\<environment>-<credential_type>-<client_id>-<realm\*>-<target\*>-<scheme\*>
118
+ */
119
+ static generateCredentialCacheKey(
120
+ homeAccountId: string,
121
+ environment: string,
122
+ credentialType: CredentialType,
123
+ clientId: string,
124
+ realm?: string,
125
+ target?: string,
126
+ familyId?: string,
127
+ tokenType?: AuthenticationScheme,
128
+ requestedClaimsHash?: string
129
+ ): string {
130
+ const credentialKey = [
131
+ this.generateAccountIdForCacheKey(homeAccountId, environment),
132
+ this.generateCredentialIdForCacheKey(
133
+ credentialType,
134
+ clientId,
135
+ realm,
136
+ familyId
137
+ ),
138
+ this.generateTargetForCacheKey(target),
139
+ this.generateClaimsHashForCacheKey(requestedClaimsHash),
140
+ this.generateSchemeForCacheKey(tokenType),
141
+ ];
142
+
143
+ return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
144
+ }
145
+
146
+ /**
147
+ * generates Account Id for keys
148
+ * @param homeAccountId
149
+ * @param environment
150
+ */
151
+ private static generateAccountIdForCacheKey(
152
+ homeAccountId: string,
153
+ environment: string
154
+ ): string {
155
+ const accountId: Array<string> = [homeAccountId, environment];
156
+ return accountId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
157
+ }
158
+
159
+ /**
160
+ * Generates Credential Id for keys
161
+ * @param credentialType
162
+ * @param realm
163
+ * @param clientId
164
+ * @param familyId
165
+ */
166
+ private static generateCredentialIdForCacheKey(
167
+ credentialType: CredentialType,
168
+ clientId: string,
169
+ realm?: string,
170
+ familyId?: string
171
+ ): string {
172
+ const clientOrFamilyId =
173
+ credentialType === CredentialType.REFRESH_TOKEN
174
+ ? familyId || clientId
175
+ : clientId;
176
+ const credentialId: Array<string> = [
177
+ credentialType,
178
+ clientOrFamilyId,
179
+ realm || Constants.EMPTY_STRING,
180
+ ];
181
+
182
+ return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
183
+ }
184
+
185
+ /**
186
+ * Generate target key component as per schema: <target>
187
+ */
188
+ private static generateTargetForCacheKey(scopes?: string): string {
189
+ return (scopes || Constants.EMPTY_STRING).toLowerCase();
190
+ }
191
+
192
+ /**
193
+ * Generate requested claims key component as per schema: <requestedClaims>
194
+ */
195
+ private static generateClaimsHashForCacheKey(
196
+ requestedClaimsHash?: string
197
+ ): string {
198
+ return (requestedClaimsHash || Constants.EMPTY_STRING).toLowerCase();
199
+ }
200
+
201
+ /**
202
+ * Generate scheme key componenet as per schema: <scheme>
203
+ */
204
+ private static generateSchemeForCacheKey(tokenType?: string): string {
205
+ /*
206
+ * PoP Tokens and SSH certs include scheme in cache key
207
+ * Cast to lowercase to handle "bearer" from ADFS
208
+ */
209
+ return tokenType &&
210
+ tokenType.toLowerCase() !==
211
+ AuthenticationScheme.BEARER.toLowerCase()
212
+ ? tokenType.toLowerCase()
213
+ : Constants.EMPTY_STRING;
214
+ }
215
+ }
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { CredentialEntity } from "./CredentialEntity";
7
+ import { CredentialType } from "../../utils/Constants";
8
+
9
+ /**
10
+ * ID_TOKEN Cache
11
+ *
12
+ * Key:Value Schema:
13
+ *
14
+ * Key Example: uid.utid-login.microsoftonline.com-idtoken-clientId-contoso.com-
15
+ *
16
+ * Value Schema:
17
+ * {
18
+ * homeAccountId: home account identifier for the auth scheme,
19
+ * environment: entity that issued the token, represented as a full host
20
+ * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
21
+ * clientId: client ID of the application
22
+ * secret: Actual credential as a string
23
+ * realm: Full tenant or organizational identifier that the account belongs to
24
+ * }
25
+ */
26
+ export class IdTokenEntity extends CredentialEntity {
27
+ realm: string;
28
+
29
+ /**
30
+ * Create IdTokenEntity
31
+ * @param homeAccountId
32
+ * @param authenticationResult
33
+ * @param clientId
34
+ * @param authority
35
+ */
36
+ static createIdTokenEntity(
37
+ homeAccountId: string,
38
+ environment: string,
39
+ idToken: string,
40
+ clientId: string,
41
+ tenantId: string
42
+ ): IdTokenEntity {
43
+ const idTokenEntity = new IdTokenEntity();
44
+
45
+ idTokenEntity.credentialType = CredentialType.ID_TOKEN;
46
+ idTokenEntity.homeAccountId = homeAccountId;
47
+ idTokenEntity.environment = environment;
48
+ idTokenEntity.clientId = clientId;
49
+ idTokenEntity.secret = idToken;
50
+ idTokenEntity.realm = tenantId;
51
+
52
+ return idTokenEntity;
53
+ }
54
+
55
+ /**
56
+ * Validates an entity: checks for all expected params
57
+ * @param entity
58
+ */
59
+ static isIdTokenEntity(entity: object): boolean {
60
+ if (!entity) {
61
+ return false;
62
+ }
63
+
64
+ return (
65
+ entity.hasOwnProperty("homeAccountId") &&
66
+ entity.hasOwnProperty("environment") &&
67
+ entity.hasOwnProperty("credentialType") &&
68
+ entity.hasOwnProperty("realm") &&
69
+ entity.hasOwnProperty("clientId") &&
70
+ entity.hasOwnProperty("secret") &&
71
+ entity["credentialType"] === CredentialType.ID_TOKEN
72
+ );
73
+ }
74
+ }
@@ -0,0 +1,78 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { CredentialEntity } from "./CredentialEntity";
7
+ import { CredentialType } from "../../utils/Constants";
8
+
9
+ /**
10
+ * REFRESH_TOKEN Cache
11
+ *
12
+ * Key:Value Schema:
13
+ *
14
+ * Key Example: uid.utid-login.microsoftonline.com-refreshtoken-clientId--
15
+ *
16
+ * Value:
17
+ * {
18
+ * homeAccountId: home account identifier for the auth scheme,
19
+ * environment: entity that issued the token, represented as a full host
20
+ * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
21
+ * clientId: client ID of the application
22
+ * secret: Actual credential as a string
23
+ * familyId: Family ID identifier, '1' represents Microsoft Family
24
+ * realm: Full tenant or organizational identifier that the account belongs to
25
+ * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
26
+ * }
27
+ */
28
+ export class RefreshTokenEntity extends CredentialEntity {
29
+ familyId?: string;
30
+
31
+ /**
32
+ * Create RefreshTokenEntity
33
+ * @param homeAccountId
34
+ * @param authenticationResult
35
+ * @param clientId
36
+ * @param authority
37
+ */
38
+ static createRefreshTokenEntity(
39
+ homeAccountId: string,
40
+ environment: string,
41
+ refreshToken: string,
42
+ clientId: string,
43
+ familyId?: string,
44
+ userAssertionHash?: string
45
+ ): RefreshTokenEntity {
46
+ const rtEntity = new RefreshTokenEntity();
47
+
48
+ rtEntity.clientId = clientId;
49
+ rtEntity.credentialType = CredentialType.REFRESH_TOKEN;
50
+ rtEntity.environment = environment;
51
+ rtEntity.homeAccountId = homeAccountId;
52
+ rtEntity.secret = refreshToken;
53
+ rtEntity.userAssertionHash = userAssertionHash;
54
+
55
+ if (familyId) rtEntity.familyId = familyId;
56
+
57
+ return rtEntity;
58
+ }
59
+
60
+ /**
61
+ * Validates an entity: checks for all expected params
62
+ * @param entity
63
+ */
64
+ static isRefreshTokenEntity(entity: object): boolean {
65
+ if (!entity) {
66
+ return false;
67
+ }
68
+
69
+ return (
70
+ entity.hasOwnProperty("homeAccountId") &&
71
+ entity.hasOwnProperty("environment") &&
72
+ entity.hasOwnProperty("credentialType") &&
73
+ entity.hasOwnProperty("clientId") &&
74
+ entity.hasOwnProperty("secret") &&
75
+ entity["credentialType"] === CredentialType.REFRESH_TOKEN
76
+ );
77
+ }
78
+ }
@@ -0,0 +1,38 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { SERVER_TELEM_CONSTANTS } from "../../utils/Constants";
7
+
8
+ export class ServerTelemetryEntity {
9
+ failedRequests: Array<string | number>;
10
+ errors: string[];
11
+ cacheHits: number;
12
+
13
+ constructor() {
14
+ this.failedRequests = [];
15
+ this.errors = [];
16
+ this.cacheHits = 0;
17
+ }
18
+
19
+ /**
20
+ * validates if a given cache entry is "Telemetry", parses <key,value>
21
+ * @param key
22
+ * @param entity
23
+ */
24
+ static isServerTelemetryEntity(key: string, entity?: object): boolean {
25
+ const validateKey: boolean =
26
+ key.indexOf(SERVER_TELEM_CONSTANTS.CACHE_KEY) === 0;
27
+ let validateEntity: boolean = true;
28
+
29
+ if (entity) {
30
+ validateEntity =
31
+ entity.hasOwnProperty("failedRequests") &&
32
+ entity.hasOwnProperty("errors") &&
33
+ entity.hasOwnProperty("cacheHits");
34
+ }
35
+
36
+ return validateKey && validateEntity;
37
+ }
38
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ThrottlingConstants } from "../../utils/Constants";
7
+
8
+ export class ThrottlingEntity {
9
+ // Unix-time value representing the expiration of the throttle
10
+ throttleTime: number;
11
+ // Information provided by the server
12
+ error?: string;
13
+ errorCodes?: Array<string>;
14
+ errorMessage?: string;
15
+ subError?: string;
16
+
17
+ /**
18
+ * validates if a given cache entry is "Throttling", parses <key,value>
19
+ * @param key
20
+ * @param entity
21
+ */
22
+ static isThrottlingEntity(key: string, entity?: object): boolean {
23
+ let validateKey: boolean = false;
24
+ if (key) {
25
+ validateKey =
26
+ key.indexOf(ThrottlingConstants.THROTTLING_PREFIX) === 0;
27
+ }
28
+
29
+ let validateEntity: boolean = true;
30
+ if (entity) {
31
+ validateEntity = entity.hasOwnProperty("throttleTime");
32
+ }
33
+
34
+ return validateKey && validateEntity;
35
+ }
36
+ }
@@ -0,0 +1,218 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { AccountFilter } from "../utils/CacheTypes";
7
+ import { CacheRecord } from "../entities/CacheRecord";
8
+ import { AccountEntity } from "../entities/AccountEntity";
9
+ import { AccountInfo } from "../../account/AccountInfo";
10
+ import { AppMetadataEntity } from "../entities/AppMetadataEntity";
11
+ import { ServerTelemetryEntity } from "../entities/ServerTelemetryEntity";
12
+ import { ThrottlingEntity } from "../entities/ThrottlingEntity";
13
+ import { IdTokenEntity } from "../entities/IdTokenEntity";
14
+ import { AccessTokenEntity } from "../entities/AccessTokenEntity";
15
+ import { RefreshTokenEntity } from "../entities/RefreshTokenEntity";
16
+ import { AuthorityMetadataEntity } from "../entities/AuthorityMetadataEntity";
17
+ import { StoreInCache } from "../../request/StoreInCache";
18
+
19
+ export interface ICacheManager {
20
+ /**
21
+ * fetch the account entity from the platform cache
22
+ * @param accountKey
23
+ */
24
+ getAccount(accountKey: string): AccountEntity | null;
25
+
26
+ /**
27
+ * set account entity in the platform cache
28
+ * @param account
29
+ */
30
+ setAccount(account: AccountEntity): void;
31
+
32
+ /**
33
+ * Returns true if the given key matches our account key schema. Also matches homeAccountId and/or tenantId if provided
34
+ * @param key
35
+ * @param homeAccountId
36
+ * @param tenantId
37
+ * @returns
38
+ */
39
+ isAccountKey(
40
+ key: string,
41
+ homeAccountId?: string,
42
+ tenantId?: string
43
+ ): boolean;
44
+
45
+ /**
46
+ * fetch the idToken entity from the platform cache
47
+ * @param idTokenKey
48
+ */
49
+ getIdTokenCredential(idTokenKey: string): IdTokenEntity | null;
50
+
51
+ /**
52
+ * set idToken entity to the platform cache
53
+ * @param idToken
54
+ */
55
+ setIdTokenCredential(idToken: IdTokenEntity): void;
56
+
57
+ /**
58
+ * fetch the idToken entity from the platform cache
59
+ * @param accessTokenKey
60
+ */
61
+ getAccessTokenCredential(accessTokenKey: string): AccessTokenEntity | null;
62
+
63
+ /**
64
+ * set idToken entity to the platform cache
65
+ * @param accessToken
66
+ */
67
+ setAccessTokenCredential(accessToken: AccessTokenEntity): void;
68
+
69
+ /**
70
+ * fetch the idToken entity from the platform cache
71
+ * @param refreshTokenKey
72
+ */
73
+ getRefreshTokenCredential(
74
+ refreshTokenKey: string
75
+ ): RefreshTokenEntity | null;
76
+
77
+ /**
78
+ * set idToken entity to the platform cache
79
+ * @param refreshToken
80
+ */
81
+ setRefreshTokenCredential(refreshToken: RefreshTokenEntity): void;
82
+
83
+ /**
84
+ * fetch appMetadata entity from the platform cache
85
+ * @param appMetadataKey
86
+ */
87
+ getAppMetadata(appMetadataKey: string): AppMetadataEntity | null;
88
+
89
+ /**
90
+ * set appMetadata entity to the platform cache
91
+ * @param appMetadata
92
+ */
93
+ setAppMetadata(appMetadata: AppMetadataEntity): void;
94
+
95
+ /**
96
+ * fetch server telemetry entity from the platform cache
97
+ * @param serverTelemetryKey
98
+ */
99
+ getServerTelemetry(
100
+ serverTelemetryKey: string
101
+ ): ServerTelemetryEntity | null;
102
+
103
+ /**
104
+ * set server telemetry entity to the platform cache
105
+ * @param serverTelemetryKey
106
+ * @param serverTelemetry
107
+ */
108
+ setServerTelemetry(
109
+ serverTelemetryKey: string,
110
+ serverTelemetry: ServerTelemetryEntity
111
+ ): void;
112
+
113
+ /**
114
+ * fetch cloud discovery metadata entity from the platform cache
115
+ * @param key
116
+ */
117
+ getAuthorityMetadata(key: string): AuthorityMetadataEntity | null;
118
+
119
+ /**
120
+ * Get cache keys for authority metadata
121
+ */
122
+ getAuthorityMetadataKeys(): Array<string>;
123
+
124
+ /**
125
+ * set cloud discovery metadata entity to the platform cache
126
+ * @param key
127
+ * @param value
128
+ */
129
+ setAuthorityMetadata(key: string, value: AuthorityMetadataEntity): void;
130
+
131
+ /**
132
+ * Provide an alias to find a matching AuthorityMetadataEntity in cache
133
+ * @param host
134
+ */
135
+ getAuthorityMetadataByAlias(host: string): AuthorityMetadataEntity | null;
136
+
137
+ /**
138
+ * given an authority generates the cache key for authorityMetadata
139
+ * @param authority
140
+ */
141
+ generateAuthorityMetadataCacheKey(authority: string): string;
142
+
143
+ /**
144
+ * fetch throttling entity from the platform cache
145
+ * @param throttlingCacheKey
146
+ */
147
+ getThrottlingCache(throttlingCacheKey: string): ThrottlingEntity | null;
148
+
149
+ /**
150
+ * set throttling entity to the platform cache
151
+ * @param throttlingCacheKey
152
+ * @param throttlingCache
153
+ */
154
+ setThrottlingCache(
155
+ throttlingCacheKey: string,
156
+ throttlingCache: ThrottlingEntity
157
+ ): void;
158
+
159
+ /**
160
+ * Returns all accounts in cache
161
+ */
162
+ getAllAccounts(): AccountInfo[];
163
+
164
+ /**
165
+ * saves a cache record
166
+ * @param cacheRecord
167
+ */
168
+ saveCacheRecord(
169
+ cacheRecord: CacheRecord,
170
+ storeInCache?: StoreInCache
171
+ ): Promise<void>;
172
+
173
+ /**
174
+ * retrieve accounts matching all provided filters; if no filter is set, get all accounts
175
+ * @param homeAccountId
176
+ * @param environment
177
+ * @param realm
178
+ */
179
+ getAccountsFilteredBy(filter: AccountFilter): AccountEntity[];
180
+
181
+ /**
182
+ * Get AccountInfo object based on provided filters
183
+ * @param filter
184
+ */
185
+ getAccountInfoFilteredBy(filter: AccountFilter): AccountInfo | null;
186
+
187
+ /**
188
+ * Removes all accounts and related tokens from cache.
189
+ */
190
+ removeAllAccounts(): Promise<void>;
191
+
192
+ /**
193
+ * returns a boolean if the given account is removed
194
+ * @param account
195
+ */
196
+ removeAccount(accountKey: string): Promise<void>;
197
+
198
+ /**
199
+ * returns a boolean if the given account is removed
200
+ * @param account
201
+ */
202
+ removeAccountContext(account: AccountEntity): Promise<void>;
203
+
204
+ /**
205
+ * @param key
206
+ */
207
+ removeIdToken(key: string): void;
208
+
209
+ /**
210
+ * @param key
211
+ */
212
+ removeAccessToken(key: string): Promise<void>;
213
+
214
+ /**
215
+ * @param key
216
+ */
217
+ removeRefreshToken(key: string): void;
218
+ }
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { TokenCacheContext } from "../persistence/TokenCacheContext";
7
+
8
+ export interface ICachePlugin {
9
+ beforeCacheAccess: (tokenCacheContext: TokenCacheContext) => Promise<void>;
10
+ afterCacheAccess: (tokenCacheContext: TokenCacheContext) => Promise<void>;
11
+ }