@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,162 @@
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, AuthenticationScheme } from "../../utils/Constants";
8
+ import { TimeUtils } from "../../utils/TimeUtils";
9
+ import { ICrypto } from "../../crypto/ICrypto";
10
+ import { TokenClaims } from "../../account/TokenClaims";
11
+ import { ClientAuthError } from "../../error/ClientAuthError";
12
+ import { extractTokenClaims } from "../../account/AuthToken";
13
+
14
+ /**
15
+ * ACCESS_TOKEN Credential Type
16
+ *
17
+ * Key:Value Schema:
18
+ *
19
+ * Key Example: uid.utid-login.microsoftonline.com-accesstoken-clientId-contoso.com-user.read
20
+ *
21
+ * Value Schema:
22
+ * {
23
+ * homeAccountId: home account identifier for the auth scheme,
24
+ * environment: entity that issued the token, represented as a full host
25
+ * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
26
+ * clientId: client ID of the application
27
+ * secret: Actual credential as a string
28
+ * familyId: Family ID identifier, usually only used for refresh tokens
29
+ * realm: Full tenant or organizational identifier that the account belongs to
30
+ * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
31
+ * cachedAt: Absolute device time when entry was created in the cache.
32
+ * expiresOn: Token expiry time, calculated based on current UTC time in seconds. Represented as a string.
33
+ * extendedExpiresOn: Additional extended expiry time until when token is valid in case of server-side outage. Represented as string in UTC seconds.
34
+ * keyId: used for POP and SSH tokenTypes
35
+ * tokenType: Type of the token issued. Usually "Bearer"
36
+ * }
37
+ */
38
+ export class AccessTokenEntity extends CredentialEntity {
39
+ realm: string;
40
+ target: string;
41
+ cachedAt: string;
42
+ expiresOn: string;
43
+ extendedExpiresOn?: string;
44
+ refreshOn?: string;
45
+ keyId?: string; // for POP and SSH tokenTypes
46
+ tokenType?: AuthenticationScheme;
47
+ requestedClaims?: string;
48
+ requestedClaimsHash?: string;
49
+
50
+ /**
51
+ * Create AccessTokenEntity
52
+ * @param homeAccountId
53
+ * @param environment
54
+ * @param accessToken
55
+ * @param clientId
56
+ * @param tenantId
57
+ * @param scopes
58
+ * @param expiresOn
59
+ * @param extExpiresOn
60
+ */
61
+ static createAccessTokenEntity(
62
+ homeAccountId: string,
63
+ environment: string,
64
+ accessToken: string,
65
+ clientId: string,
66
+ tenantId: string,
67
+ scopes: string,
68
+ expiresOn: number,
69
+ extExpiresOn: number,
70
+ cryptoUtils: ICrypto,
71
+ refreshOn?: number,
72
+ tokenType?: AuthenticationScheme,
73
+ userAssertionHash?: string,
74
+ keyId?: string,
75
+ requestedClaims?: string,
76
+ requestedClaimsHash?: string
77
+ ): AccessTokenEntity {
78
+ const atEntity: AccessTokenEntity = new AccessTokenEntity();
79
+
80
+ atEntity.homeAccountId = homeAccountId;
81
+ atEntity.credentialType = CredentialType.ACCESS_TOKEN;
82
+ atEntity.secret = accessToken;
83
+
84
+ const currentTime = TimeUtils.nowSeconds();
85
+ atEntity.cachedAt = currentTime.toString();
86
+
87
+ /*
88
+ * Token expiry time.
89
+ * This value should be  calculated based on the current UTC time measured locally and the value  expires_in Represented as a string in JSON.
90
+ */
91
+ atEntity.expiresOn = expiresOn.toString();
92
+ atEntity.extendedExpiresOn = extExpiresOn.toString();
93
+ if (refreshOn) {
94
+ atEntity.refreshOn = refreshOn.toString();
95
+ }
96
+
97
+ atEntity.environment = environment;
98
+ atEntity.clientId = clientId;
99
+ atEntity.realm = tenantId;
100
+ atEntity.target = scopes;
101
+ atEntity.userAssertionHash = userAssertionHash;
102
+
103
+ atEntity.tokenType = tokenType || AuthenticationScheme.BEARER;
104
+
105
+ if (requestedClaims) {
106
+ atEntity.requestedClaims = requestedClaims;
107
+ atEntity.requestedClaimsHash = requestedClaimsHash;
108
+ }
109
+
110
+ /*
111
+ * Create Access Token With Auth Scheme instead of regular access token
112
+ * Cast to lower to handle "bearer" from ADFS
113
+ */
114
+ if (
115
+ atEntity.tokenType?.toLowerCase() !==
116
+ AuthenticationScheme.BEARER.toLowerCase()
117
+ ) {
118
+ atEntity.credentialType =
119
+ CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;
120
+ switch (atEntity.tokenType) {
121
+ case AuthenticationScheme.POP:
122
+ // Make sure keyId is present and add it to credential
123
+ const tokenClaims: TokenClaims | null = extractTokenClaims(
124
+ accessToken,
125
+ cryptoUtils.base64Decode
126
+ );
127
+ if (!tokenClaims?.cnf?.kid) {
128
+ throw ClientAuthError.createTokenClaimsRequiredError();
129
+ }
130
+ atEntity.keyId = tokenClaims.cnf.kid;
131
+ break;
132
+ case AuthenticationScheme.SSH:
133
+ atEntity.keyId = keyId;
134
+ }
135
+ }
136
+
137
+ return atEntity;
138
+ }
139
+
140
+ /**
141
+ * Validates an entity: checks for all expected params
142
+ * @param entity
143
+ */
144
+ static isAccessTokenEntity(entity: object): boolean {
145
+ if (!entity) {
146
+ return false;
147
+ }
148
+
149
+ return (
150
+ entity.hasOwnProperty("homeAccountId") &&
151
+ entity.hasOwnProperty("environment") &&
152
+ entity.hasOwnProperty("credentialType") &&
153
+ entity.hasOwnProperty("realm") &&
154
+ entity.hasOwnProperty("clientId") &&
155
+ entity.hasOwnProperty("secret") &&
156
+ entity.hasOwnProperty("target") &&
157
+ (entity["credentialType"] === CredentialType.ACCESS_TOKEN ||
158
+ entity["credentialType"] ===
159
+ CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME)
160
+ );
161
+ }
162
+ }
@@ -0,0 +1,309 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { Separators, CacheAccountType, Constants } from "../../utils/Constants";
7
+ import { Authority } from "../../authority/Authority";
8
+ import { ICrypto } from "../../crypto/ICrypto";
9
+ import { buildClientInfo } from "../../account/ClientInfo";
10
+ import { AccountInfo } from "../../account/AccountInfo";
11
+ import { ClientAuthError } from "../../error/ClientAuthError";
12
+ import { AuthorityType } from "../../authority/AuthorityType";
13
+ import { Logger } from "../../logger/Logger";
14
+ import { TokenClaims } from "../../account/TokenClaims";
15
+ import { ProtocolMode } from "../../authority/ProtocolMode";
16
+
17
+ /**
18
+ * Type that defines required and optional parameters for an Account field (based on universal cache schema implemented by all MSALs).
19
+ *
20
+ * Key : Value Schema
21
+ *
22
+ * Key: <home_account_id>-<environment>-<realm*>
23
+ *
24
+ * Value Schema:
25
+ * {
26
+ * homeAccountId: home account identifier for the auth scheme,
27
+ * environment: entity that issued the token, represented as a full host
28
+ * realm: Full tenant or organizational identifier that the account belongs to
29
+ * localAccountId: Original tenant-specific accountID, usually used for legacy cases
30
+ * username: primary username that represents the user, usually corresponds to preferred_username in the v2 endpt
31
+ * authorityType: Accounts authority type as a string
32
+ * name: Full name for the account, including given name and family name,
33
+ * lastModificationTime: last time this entity was modified in the cache
34
+ * lastModificationApp:
35
+ * idTokenClaims: Object containing claims parsed from ID token
36
+ * nativeAccountId: Account identifier on the native device
37
+ * }
38
+ * @internal
39
+ */
40
+ export class AccountEntity {
41
+ homeAccountId: string;
42
+ environment: string;
43
+ realm: string;
44
+ localAccountId: string;
45
+ username: string;
46
+ authorityType: string;
47
+ clientInfo?: string;
48
+ name?: string;
49
+ lastModificationTime?: string;
50
+ lastModificationApp?: string;
51
+ cloudGraphHostName?: string;
52
+ msGraphHost?: string;
53
+ idTokenClaims?: TokenClaims;
54
+ nativeAccountId?: string;
55
+
56
+ /**
57
+ * Generate Account Id key component as per the schema: <home_account_id>-<environment>
58
+ */
59
+ generateAccountId(): string {
60
+ const accountId: Array<string> = [this.homeAccountId, this.environment];
61
+ return accountId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
62
+ }
63
+
64
+ /**
65
+ * Generate Account Cache Key as per the schema: <home_account_id>-<environment>-<realm*>
66
+ */
67
+ generateAccountKey(): string {
68
+ return AccountEntity.generateAccountCacheKey({
69
+ homeAccountId: this.homeAccountId,
70
+ environment: this.environment,
71
+ tenantId: this.realm,
72
+ username: this.username,
73
+ localAccountId: this.localAccountId,
74
+ });
75
+ }
76
+
77
+ /**
78
+ * Returns the AccountInfo interface for this account.
79
+ */
80
+ getAccountInfo(): AccountInfo {
81
+ return {
82
+ homeAccountId: this.homeAccountId,
83
+ environment: this.environment,
84
+ tenantId: this.realm,
85
+ username: this.username,
86
+ localAccountId: this.localAccountId,
87
+ name: this.name,
88
+ idTokenClaims: this.idTokenClaims,
89
+ nativeAccountId: this.nativeAccountId,
90
+ authorityType: this.authorityType,
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Generates account key from interface
96
+ * @param accountInterface
97
+ */
98
+ static generateAccountCacheKey(accountInterface: AccountInfo): string {
99
+ const accountKey = [
100
+ accountInterface.homeAccountId,
101
+ accountInterface.environment || Constants.EMPTY_STRING,
102
+ accountInterface.tenantId || Constants.EMPTY_STRING,
103
+ ];
104
+
105
+ return accountKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
106
+ }
107
+
108
+ /**
109
+ * Build Account cache from IdToken, clientInfo and authority/policy. Associated with AAD.
110
+ * @param accountDetails
111
+ */
112
+ static createAccount(
113
+ accountDetails: {
114
+ homeAccountId: string;
115
+ idTokenClaims: TokenClaims;
116
+ clientInfo?: string;
117
+ cloudGraphHostName?: string;
118
+ msGraphHost?: string;
119
+ environment?: string;
120
+ nativeAccountId?: string;
121
+ },
122
+ authority: Authority
123
+ ): AccountEntity {
124
+ const account: AccountEntity = new AccountEntity();
125
+
126
+ if (authority.authorityType === AuthorityType.Adfs) {
127
+ account.authorityType = CacheAccountType.ADFS_ACCOUNT_TYPE;
128
+ } else if (authority.protocolMode === ProtocolMode.AAD) {
129
+ account.authorityType = CacheAccountType.MSSTS_ACCOUNT_TYPE;
130
+ } else {
131
+ account.authorityType = CacheAccountType.GENERIC_ACCOUNT_TYPE;
132
+ }
133
+
134
+ account.clientInfo = accountDetails.clientInfo;
135
+ account.homeAccountId = accountDetails.homeAccountId;
136
+ account.nativeAccountId = accountDetails.nativeAccountId;
137
+
138
+ const env =
139
+ accountDetails.environment ||
140
+ (authority && authority.getPreferredCache());
141
+
142
+ if (!env) {
143
+ throw ClientAuthError.createInvalidCacheEnvironmentError();
144
+ }
145
+
146
+ account.environment = env;
147
+ // non AAD scenarios can have empty realm
148
+ account.realm =
149
+ accountDetails.idTokenClaims.tid || Constants.EMPTY_STRING;
150
+
151
+ account.idTokenClaims = accountDetails.idTokenClaims;
152
+
153
+ // How do you account for MSA CID here?
154
+ account.localAccountId =
155
+ accountDetails.idTokenClaims.oid ||
156
+ accountDetails.idTokenClaims.sub ||
157
+ Constants.EMPTY_STRING;
158
+
159
+ /*
160
+ * In B2C scenarios the emails claim is used instead of preferred_username and it is an array.
161
+ * In most cases it will contain a single email. This field should not be relied upon if a custom
162
+ * policy is configured to return more than 1 email.
163
+ */
164
+ const preferredUsername =
165
+ accountDetails.idTokenClaims.preferred_username ||
166
+ accountDetails.idTokenClaims.upn;
167
+ const email = accountDetails.idTokenClaims.emails
168
+ ? accountDetails.idTokenClaims.emails[0]
169
+ : null;
170
+
171
+ account.username = preferredUsername || email || Constants.EMPTY_STRING;
172
+ account.name = accountDetails.idTokenClaims.name;
173
+
174
+ account.cloudGraphHostName = accountDetails.cloudGraphHostName;
175
+ account.msGraphHost = accountDetails.msGraphHost;
176
+
177
+ return account;
178
+ }
179
+
180
+ /**
181
+ * Creates an AccountEntity object from AccountInfo
182
+ * @param accountInfo
183
+ * @param cloudGraphHostName
184
+ * @param msGraphHost
185
+ * @returns
186
+ */
187
+ static createFromAccountInfo(
188
+ accountInfo: AccountInfo,
189
+ cloudGraphHostName?: string,
190
+ msGraphHost?: string
191
+ ): AccountEntity {
192
+ const account: AccountEntity = new AccountEntity();
193
+
194
+ account.authorityType =
195
+ accountInfo.authorityType || CacheAccountType.GENERIC_ACCOUNT_TYPE;
196
+ account.homeAccountId = accountInfo.homeAccountId;
197
+ account.localAccountId = accountInfo.localAccountId;
198
+ account.nativeAccountId = accountInfo.nativeAccountId;
199
+
200
+ account.realm = accountInfo.tenantId;
201
+ account.environment = accountInfo.environment;
202
+
203
+ account.username = accountInfo.username;
204
+ account.name = accountInfo.name;
205
+ account.idTokenClaims = accountInfo.idTokenClaims;
206
+
207
+ account.cloudGraphHostName = cloudGraphHostName;
208
+ account.msGraphHost = msGraphHost;
209
+
210
+ return account;
211
+ }
212
+
213
+ /**
214
+ * Generate HomeAccountId from server response
215
+ * @param serverClientInfo
216
+ * @param authType
217
+ */
218
+ static generateHomeAccountId(
219
+ serverClientInfo: string,
220
+ authType: AuthorityType,
221
+ logger: Logger,
222
+ cryptoObj: ICrypto,
223
+ idTokenClaims?: TokenClaims
224
+ ): string {
225
+ const accountId = idTokenClaims?.sub
226
+ ? idTokenClaims.sub
227
+ : Constants.EMPTY_STRING;
228
+
229
+ // since ADFS does not have tid and does not set client_info
230
+ if (
231
+ authType === AuthorityType.Adfs ||
232
+ authType === AuthorityType.Dsts
233
+ ) {
234
+ return accountId;
235
+ }
236
+
237
+ // for cases where there is clientInfo
238
+ if (serverClientInfo) {
239
+ try {
240
+ const clientInfo = buildClientInfo(serverClientInfo, cryptoObj);
241
+ if (clientInfo.uid && clientInfo.utid) {
242
+ return `${clientInfo.uid}${Separators.CLIENT_INFO_SEPARATOR}${clientInfo.utid}`;
243
+ }
244
+ } catch (e) {}
245
+ }
246
+
247
+ // default to "sub" claim
248
+ logger.verbose("No client info in response");
249
+ return accountId;
250
+ }
251
+
252
+ /**
253
+ * Validates an entity: checks for all expected params
254
+ * @param entity
255
+ */
256
+ static isAccountEntity(entity: object): boolean {
257
+ if (!entity) {
258
+ return false;
259
+ }
260
+
261
+ return (
262
+ entity.hasOwnProperty("homeAccountId") &&
263
+ entity.hasOwnProperty("environment") &&
264
+ entity.hasOwnProperty("realm") &&
265
+ entity.hasOwnProperty("localAccountId") &&
266
+ entity.hasOwnProperty("username") &&
267
+ entity.hasOwnProperty("authorityType")
268
+ );
269
+ }
270
+
271
+ /**
272
+ * Helper function to determine whether 2 accountInfo objects represent the same account
273
+ * @param accountA
274
+ * @param accountB
275
+ * @param compareClaims - If set to true idTokenClaims will also be compared to determine account equality
276
+ */
277
+ static accountInfoIsEqual(
278
+ accountA: AccountInfo | null,
279
+ accountB: AccountInfo | null,
280
+ compareClaims?: boolean
281
+ ): boolean {
282
+ if (!accountA || !accountB) {
283
+ return false;
284
+ }
285
+
286
+ let claimsMatch = true; // default to true so as to not fail comparison below if compareClaims: false
287
+ if (compareClaims) {
288
+ const accountAClaims = (accountA.idTokenClaims ||
289
+ {}) as TokenClaims;
290
+ const accountBClaims = (accountB.idTokenClaims ||
291
+ {}) as TokenClaims;
292
+
293
+ // issued at timestamp and nonce are expected to change each time a new id token is acquired
294
+ claimsMatch =
295
+ accountAClaims.iat === accountBClaims.iat &&
296
+ accountAClaims.nonce === accountBClaims.nonce;
297
+ }
298
+
299
+ return (
300
+ accountA.homeAccountId === accountB.homeAccountId &&
301
+ accountA.localAccountId === accountB.localAccountId &&
302
+ accountA.username === accountB.username &&
303
+ accountA.tenantId === accountB.tenantId &&
304
+ accountA.environment === accountB.environment &&
305
+ accountA.nativeAccountId === accountB.nativeAccountId &&
306
+ claimsMatch
307
+ );
308
+ }
309
+ }
@@ -0,0 +1,91 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { APP_METADATA, Separators } from "../../utils/Constants";
7
+
8
+ /**
9
+ * APP_METADATA Cache
10
+ *
11
+ * Key:Value Schema:
12
+ *
13
+ * Key: appmetadata-<environment>-<client_id>
14
+ *
15
+ * Value:
16
+ * {
17
+ * clientId: client ID of the application
18
+ * environment: entity that issued the token, represented as a full host
19
+ * familyId: Family ID identifier, '1' represents Microsoft Family
20
+ * }
21
+ */
22
+ export class AppMetadataEntity {
23
+ clientId: string;
24
+ environment: string;
25
+ familyId?: string;
26
+
27
+ /**
28
+ * Generate AppMetadata Cache Key as per the schema: appmetadata-<environment>-<client_id>
29
+ */
30
+ generateAppMetadataKey(): string {
31
+ return AppMetadataEntity.generateAppMetadataCacheKey(
32
+ this.environment,
33
+ this.clientId
34
+ );
35
+ }
36
+
37
+ /**
38
+ * Generate AppMetadata Cache Key
39
+ */
40
+ static generateAppMetadataCacheKey(
41
+ environment: string,
42
+ clientId: string
43
+ ): string {
44
+ const appMetaDataKeyArray: Array<string> = [
45
+ APP_METADATA,
46
+ environment,
47
+ clientId,
48
+ ];
49
+ return appMetaDataKeyArray
50
+ .join(Separators.CACHE_KEY_SEPARATOR)
51
+ .toLowerCase();
52
+ }
53
+
54
+ /**
55
+ * Creates AppMetadataEntity
56
+ * @param clientId
57
+ * @param environment
58
+ * @param familyId
59
+ */
60
+ static createAppMetadataEntity(
61
+ clientId: string,
62
+ environment: string,
63
+ familyId?: string
64
+ ): AppMetadataEntity {
65
+ const appMetadata = new AppMetadataEntity();
66
+
67
+ appMetadata.clientId = clientId;
68
+ appMetadata.environment = environment;
69
+ if (familyId) {
70
+ appMetadata.familyId = familyId;
71
+ }
72
+
73
+ return appMetadata;
74
+ }
75
+
76
+ /**
77
+ * Validates an entity: checks for all expected params
78
+ * @param entity
79
+ */
80
+ static isAppMetadataEntity(key: string, entity: object): boolean {
81
+ if (!entity) {
82
+ return false;
83
+ }
84
+
85
+ return (
86
+ key.indexOf(APP_METADATA) === 0 &&
87
+ entity.hasOwnProperty("clientId") &&
88
+ entity.hasOwnProperty("environment")
89
+ );
90
+ }
91
+ }
@@ -0,0 +1,112 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { CloudDiscoveryMetadata } from "../../authority/CloudDiscoveryMetadata";
7
+ import { OpenIdConfigResponse } from "../../authority/OpenIdConfigResponse";
8
+ import { AUTHORITY_METADATA_CONSTANTS } from "../../utils/Constants";
9
+ import { TimeUtils } from "../../utils/TimeUtils";
10
+
11
+ /** @internal */
12
+ export class AuthorityMetadataEntity {
13
+ aliases: Array<string>;
14
+ preferred_cache: string;
15
+ preferred_network: string;
16
+ canonical_authority: string;
17
+ authorization_endpoint: string;
18
+ token_endpoint: string;
19
+ end_session_endpoint?: string;
20
+ issuer: string;
21
+ aliasesFromNetwork: boolean;
22
+ endpointsFromNetwork: boolean;
23
+ expiresAt: number;
24
+ jwks_uri: string;
25
+
26
+ constructor() {
27
+ this.expiresAt =
28
+ TimeUtils.nowSeconds() +
29
+ AUTHORITY_METADATA_CONSTANTS.REFRESH_TIME_SECONDS;
30
+ }
31
+
32
+ /**
33
+ * Update the entity with new aliases, preferred_cache and preferred_network values
34
+ * @param metadata
35
+ * @param fromNetwork
36
+ */
37
+ updateCloudDiscoveryMetadata(
38
+ metadata: CloudDiscoveryMetadata,
39
+ fromNetwork: boolean
40
+ ): void {
41
+ this.aliases = metadata.aliases;
42
+ this.preferred_cache = metadata.preferred_cache;
43
+ this.preferred_network = metadata.preferred_network;
44
+ this.aliasesFromNetwork = fromNetwork;
45
+ }
46
+
47
+ /**
48
+ * Update the entity with new endpoints
49
+ * @param metadata
50
+ * @param fromNetwork
51
+ */
52
+ updateEndpointMetadata(
53
+ metadata: OpenIdConfigResponse,
54
+ fromNetwork: boolean
55
+ ): void {
56
+ this.authorization_endpoint = metadata.authorization_endpoint;
57
+ this.token_endpoint = metadata.token_endpoint;
58
+ this.end_session_endpoint = metadata.end_session_endpoint;
59
+ this.issuer = metadata.issuer;
60
+ this.endpointsFromNetwork = fromNetwork;
61
+ this.jwks_uri = metadata.jwks_uri;
62
+ }
63
+
64
+ /**
65
+ * Save the authority that was used to create this cache entry
66
+ * @param authority
67
+ */
68
+ updateCanonicalAuthority(authority: string): void {
69
+ this.canonical_authority = authority;
70
+ }
71
+
72
+ /**
73
+ * Reset the exiresAt value
74
+ */
75
+ resetExpiresAt(): void {
76
+ this.expiresAt =
77
+ TimeUtils.nowSeconds() +
78
+ AUTHORITY_METADATA_CONSTANTS.REFRESH_TIME_SECONDS;
79
+ }
80
+
81
+ /**
82
+ * Returns whether or not the data needs to be refreshed
83
+ */
84
+ isExpired(): boolean {
85
+ return this.expiresAt <= TimeUtils.nowSeconds();
86
+ }
87
+
88
+ /**
89
+ * Validates an entity: checks for all expected params
90
+ * @param entity
91
+ */
92
+ static isAuthorityMetadataEntity(key: string, entity: object): boolean {
93
+ if (!entity) {
94
+ return false;
95
+ }
96
+
97
+ return (
98
+ key.indexOf(AUTHORITY_METADATA_CONSTANTS.CACHE_KEY) === 0 &&
99
+ entity.hasOwnProperty("aliases") &&
100
+ entity.hasOwnProperty("preferred_cache") &&
101
+ entity.hasOwnProperty("preferred_network") &&
102
+ entity.hasOwnProperty("canonical_authority") &&
103
+ entity.hasOwnProperty("authorization_endpoint") &&
104
+ entity.hasOwnProperty("token_endpoint") &&
105
+ entity.hasOwnProperty("issuer") &&
106
+ entity.hasOwnProperty("aliasesFromNetwork") &&
107
+ entity.hasOwnProperty("endpointsFromNetwork") &&
108
+ entity.hasOwnProperty("expiresAt") &&
109
+ entity.hasOwnProperty("jwks_uri")
110
+ );
111
+ }
112
+ }