@azure/msal-common 14.0.2 → 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 (269) 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.mjs +1 -1
  11. package/dist/authority/Authority.mjs.map +1 -1
  12. package/dist/authority/AuthorityFactory.d.ts.map +1 -1
  13. package/dist/authority/AuthorityFactory.mjs +2 -3
  14. package/dist/authority/AuthorityFactory.mjs.map +1 -1
  15. package/dist/authority/AuthorityMetadata.mjs +1 -1
  16. package/dist/authority/AuthorityMetadata.mjs.map +1 -1
  17. package/dist/authority/AuthorityOptions.mjs +1 -1
  18. package/dist/authority/AuthorityOptions.mjs.map +1 -1
  19. package/dist/authority/AuthorityType.mjs +1 -1
  20. package/dist/authority/AuthorityType.mjs.map +1 -1
  21. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  22. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs.map +1 -1
  23. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  24. package/dist/authority/CloudInstanceDiscoveryResponse.mjs.map +1 -1
  25. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  26. package/dist/authority/OpenIdConfigResponse.mjs.map +1 -1
  27. package/dist/authority/ProtocolMode.mjs +1 -1
  28. package/dist/authority/ProtocolMode.mjs.map +1 -1
  29. package/dist/authority/RegionDiscovery.mjs +1 -1
  30. package/dist/authority/RegionDiscovery.mjs.map +1 -1
  31. package/dist/cache/CacheManager.d.ts.map +1 -1
  32. package/dist/cache/CacheManager.mjs +5 -5
  33. package/dist/cache/CacheManager.mjs.map +1 -1
  34. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  35. package/dist/cache/entities/AccessTokenEntity.mjs +4 -7
  36. package/dist/cache/entities/AccessTokenEntity.mjs.map +1 -1
  37. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  38. package/dist/cache/entities/AccountEntity.mjs +2 -4
  39. package/dist/cache/entities/AccountEntity.mjs.map +1 -1
  40. package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
  41. package/dist/cache/entities/AppMetadataEntity.mjs.map +1 -1
  42. package/dist/cache/entities/AuthorityMetadataEntity.mjs +1 -1
  43. package/dist/cache/entities/AuthorityMetadataEntity.mjs.map +1 -1
  44. package/dist/cache/entities/CacheRecord.mjs +1 -1
  45. package/dist/cache/entities/CacheRecord.mjs.map +1 -1
  46. package/dist/cache/entities/CredentialEntity.mjs +1 -1
  47. package/dist/cache/entities/CredentialEntity.mjs.map +1 -1
  48. package/dist/cache/entities/IdTokenEntity.mjs +1 -1
  49. package/dist/cache/entities/IdTokenEntity.mjs.map +1 -1
  50. package/dist/cache/entities/RefreshTokenEntity.mjs +1 -1
  51. package/dist/cache/entities/RefreshTokenEntity.mjs.map +1 -1
  52. package/dist/cache/entities/ServerTelemetryEntity.mjs +1 -1
  53. package/dist/cache/entities/ServerTelemetryEntity.mjs.map +1 -1
  54. package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
  55. package/dist/cache/entities/ThrottlingEntity.mjs.map +1 -1
  56. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  57. package/dist/cache/persistence/TokenCacheContext.mjs.map +1 -1
  58. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  59. package/dist/client/AuthorizationCodeClient.mjs +10 -39
  60. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  61. package/dist/client/BaseClient.d.ts +1 -1
  62. package/dist/client/BaseClient.d.ts.map +1 -1
  63. package/dist/client/BaseClient.mjs +8 -2
  64. package/dist/client/BaseClient.mjs.map +1 -1
  65. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  66. package/dist/client/RefreshTokenClient.mjs +2 -11
  67. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  68. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  69. package/dist/client/SilentFlowClient.mjs +7 -7
  70. package/dist/client/SilentFlowClient.mjs.map +1 -1
  71. package/dist/config/ClientConfiguration.mjs +1 -1
  72. package/dist/config/ClientConfiguration.mjs.map +1 -1
  73. package/dist/crypto/ICrypto.mjs +1 -1
  74. package/dist/crypto/ICrypto.mjs.map +1 -1
  75. package/dist/crypto/JoseHeader.mjs +1 -1
  76. package/dist/crypto/JoseHeader.mjs.map +1 -1
  77. package/dist/crypto/PopTokenGenerator.mjs +1 -1
  78. package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
  79. package/dist/error/AuthError.mjs +1 -1
  80. package/dist/error/AuthError.mjs.map +1 -1
  81. package/dist/error/ClientAuthError.mjs +1 -1
  82. package/dist/error/ClientAuthError.mjs.map +1 -1
  83. package/dist/error/ClientConfigurationError.mjs +1 -1
  84. package/dist/error/ClientConfigurationError.mjs.map +1 -1
  85. package/dist/error/InteractionRequiredAuthError.mjs +1 -1
  86. package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
  87. package/dist/error/JoseHeaderError.mjs +1 -1
  88. package/dist/error/JoseHeaderError.mjs.map +1 -1
  89. package/dist/error/ServerError.mjs +1 -1
  90. package/dist/error/ServerError.mjs.map +1 -1
  91. package/dist/index.cjs +1641 -1560
  92. package/dist/index.cjs.map +1 -1
  93. package/dist/index.d.ts +3 -3
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.mjs +5 -3
  96. package/dist/index.mjs.map +1 -1
  97. package/dist/logger/Logger.d.ts.map +1 -1
  98. package/dist/logger/Logger.mjs +2 -12
  99. package/dist/logger/Logger.mjs.map +1 -1
  100. package/dist/network/INetworkModule.mjs +1 -1
  101. package/dist/network/INetworkModule.mjs.map +1 -1
  102. package/dist/network/NetworkManager.mjs +1 -1
  103. package/dist/network/NetworkManager.mjs.map +1 -1
  104. package/dist/network/ThrottlingUtils.mjs +1 -1
  105. package/dist/network/ThrottlingUtils.mjs.map +1 -1
  106. package/dist/packageMetadata.d.ts +1 -1
  107. package/dist/packageMetadata.mjs +2 -2
  108. package/dist/packageMetadata.mjs.map +1 -1
  109. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  110. package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
  111. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  112. package/dist/request/RequestParameterBuilder.mjs +6 -7
  113. package/dist/request/RequestParameterBuilder.mjs.map +1 -1
  114. package/dist/request/RequestValidator.d.ts.map +1 -1
  115. package/dist/request/RequestValidator.mjs +4 -6
  116. package/dist/request/RequestValidator.mjs.map +1 -1
  117. package/dist/request/ScopeSet.mjs +4 -4
  118. package/dist/request/ScopeSet.mjs.map +1 -1
  119. package/dist/response/AuthenticationResult.d.ts +3 -1
  120. package/dist/response/AuthenticationResult.d.ts.map +1 -1
  121. package/dist/response/ResponseHandler.d.ts +4 -3
  122. package/dist/response/ResponseHandler.d.ts.map +1 -1
  123. package/dist/response/ResponseHandler.mjs +57 -39
  124. package/dist/response/ResponseHandler.mjs.map +1 -1
  125. package/dist/response/ServerAuthorizationTokenResponse.d.ts +2 -0
  126. package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
  127. package/dist/telemetry/performance/IPerformanceClient.d.ts +4 -4
  128. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
  129. package/dist/telemetry/performance/PerformanceClient.d.ts +2 -2
  130. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  131. package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
  132. package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
  133. package/dist/telemetry/performance/PerformanceEvent.d.ts +8 -1
  134. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  135. package/dist/telemetry/performance/PerformanceEvent.mjs +9 -1
  136. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  137. package/dist/telemetry/performance/StubPerformanceClient.d.ts +3 -3
  138. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
  139. package/dist/telemetry/performance/StubPerformanceClient.mjs +23 -3
  140. package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -1
  141. package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
  142. package/dist/telemetry/server/ServerTelemetryManager.mjs +3 -4
  143. package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
  144. package/dist/url/UrlString.d.ts.map +1 -1
  145. package/dist/url/UrlString.mjs +10 -12
  146. package/dist/url/UrlString.mjs.map +1 -1
  147. package/dist/utils/Constants.d.ts +10 -0
  148. package/dist/utils/Constants.d.ts.map +1 -1
  149. package/dist/utils/Constants.mjs +11 -2
  150. package/dist/utils/Constants.mjs.map +1 -1
  151. package/dist/utils/FunctionWrappers.d.ts +28 -0
  152. package/dist/utils/FunctionWrappers.d.ts.map +1 -0
  153. package/dist/utils/FunctionWrappers.mjs +90 -0
  154. package/dist/utils/FunctionWrappers.mjs.map +1 -0
  155. package/dist/utils/ProtocolUtils.d.ts.map +1 -1
  156. package/dist/utils/ProtocolUtils.mjs +4 -7
  157. package/dist/utils/ProtocolUtils.mjs.map +1 -1
  158. package/dist/utils/StringUtils.d.ts +0 -13
  159. package/dist/utils/StringUtils.d.ts.map +1 -1
  160. package/dist/utils/StringUtils.mjs +3 -34
  161. package/dist/utils/StringUtils.mjs.map +1 -1
  162. package/dist/utils/TimeUtils.mjs +1 -1
  163. package/dist/utils/TimeUtils.mjs.map +1 -1
  164. package/package.json +6 -4
  165. package/src/account/AccountInfo.ts +44 -0
  166. package/src/account/AuthToken.ts +70 -0
  167. package/src/account/CcsCredential.ts +16 -0
  168. package/src/account/ClientCredentials.ts +20 -0
  169. package/src/account/ClientInfo.ts +64 -0
  170. package/src/account/TokenClaims.ts +70 -0
  171. package/src/authority/Authority.ts +1225 -0
  172. package/src/authority/AuthorityFactory.ts +106 -0
  173. package/src/authority/AuthorityMetadata.ts +953 -0
  174. package/src/authority/AuthorityOptions.ts +40 -0
  175. package/src/authority/AuthorityType.ts +15 -0
  176. package/src/authority/AzureRegion.ts +7 -0
  177. package/src/authority/AzureRegionConfiguration.ts +16 -0
  178. package/src/authority/CloudDiscoveryMetadata.ts +10 -0
  179. package/src/authority/CloudInstanceDiscoveryErrorResponse.ts +26 -0
  180. package/src/authority/CloudInstanceDiscoveryResponse.ts +21 -0
  181. package/src/authority/ImdsOptions.ts +10 -0
  182. package/src/authority/OIDCOptions.ts +14 -0
  183. package/src/authority/OpenIdConfigResponse.ts +24 -0
  184. package/src/authority/ProtocolMode.ts +13 -0
  185. package/src/authority/RegionDiscovery.ts +193 -0
  186. package/src/authority/RegionDiscoveryMetadata.ts +15 -0
  187. package/src/broker/nativeBroker/INativeBrokerPlugin.ts +29 -0
  188. package/src/cache/CacheManager.ts +1619 -0
  189. package/src/cache/entities/AccessTokenEntity.ts +162 -0
  190. package/src/cache/entities/AccountEntity.ts +309 -0
  191. package/src/cache/entities/AppMetadataEntity.ts +91 -0
  192. package/src/cache/entities/AuthorityMetadataEntity.ts +112 -0
  193. package/src/cache/entities/CacheRecord.ts +33 -0
  194. package/src/cache/entities/CredentialEntity.ts +215 -0
  195. package/src/cache/entities/IdTokenEntity.ts +74 -0
  196. package/src/cache/entities/RefreshTokenEntity.ts +78 -0
  197. package/src/cache/entities/ServerTelemetryEntity.ts +38 -0
  198. package/src/cache/entities/ThrottlingEntity.ts +36 -0
  199. package/src/cache/interface/ICacheManager.ts +218 -0
  200. package/src/cache/interface/ICachePlugin.ts +11 -0
  201. package/src/cache/interface/ISerializableTokenCache.ts +9 -0
  202. package/src/cache/persistence/TokenCacheContext.ts +39 -0
  203. package/src/cache/utils/CacheTypes.ts +93 -0
  204. package/src/client/AuthorizationCodeClient.ts +714 -0
  205. package/src/client/BaseClient.ts +205 -0
  206. package/src/client/RefreshTokenClient.ts +442 -0
  207. package/src/client/SilentFlowClient.ts +186 -0
  208. package/src/config/AppTokenProvider.ts +47 -0
  209. package/src/config/ClientConfiguration.ts +287 -0
  210. package/src/crypto/ICrypto.ts +127 -0
  211. package/src/crypto/IGuidGenerator.ts +9 -0
  212. package/src/crypto/JoseHeader.ts +55 -0
  213. package/src/crypto/PopTokenGenerator.ts +155 -0
  214. package/src/crypto/SignedHttpRequest.ts +16 -0
  215. package/src/error/AuthError.ts +85 -0
  216. package/src/error/ClientAuthError.ts +738 -0
  217. package/src/error/ClientConfigurationError.ts +396 -0
  218. package/src/error/InteractionRequiredAuthError.ts +134 -0
  219. package/src/error/JoseHeaderError.ts +52 -0
  220. package/src/error/ServerError.ts +18 -0
  221. package/src/index.ts +215 -0
  222. package/src/logger/Logger.ts +272 -0
  223. package/src/network/INetworkModule.ts +57 -0
  224. package/src/network/NetworkManager.ts +76 -0
  225. package/src/network/RequestThumbprint.ts +22 -0
  226. package/src/network/ThrottlingUtils.ts +156 -0
  227. package/src/packageMetadata.ts +3 -0
  228. package/src/request/AuthenticationHeaderParser.ts +89 -0
  229. package/src/request/BaseAuthRequest.ts +46 -0
  230. package/src/request/CommonAuthorizationCodeRequest.ts +33 -0
  231. package/src/request/CommonAuthorizationUrlRequest.ts +56 -0
  232. package/src/request/CommonClientCredentialRequest.ts +23 -0
  233. package/src/request/CommonDeviceCodeRequest.ts +31 -0
  234. package/src/request/CommonEndSessionRequest.ts +27 -0
  235. package/src/request/CommonOnBehalfOfRequest.ts +19 -0
  236. package/src/request/CommonRefreshTokenRequest.ts +25 -0
  237. package/src/request/CommonSilentFlowRequest.ts +24 -0
  238. package/src/request/CommonUsernamePasswordRequest.ts +23 -0
  239. package/src/request/NativeRequest.ts +25 -0
  240. package/src/request/NativeSignOutRequest.ts +10 -0
  241. package/src/request/RequestParameterBuilder.ts +606 -0
  242. package/src/request/RequestValidator.ts +103 -0
  243. package/src/request/ScopeSet.ts +230 -0
  244. package/src/request/StoreInCache.ts +16 -0
  245. package/src/response/AuthenticationResult.ts +47 -0
  246. package/src/response/AuthorizationCodePayload.ts +18 -0
  247. package/src/response/DeviceCodeResponse.ts +31 -0
  248. package/src/response/ExternalTokenResponse.ts +24 -0
  249. package/src/response/IMDSBadResponse.ts +9 -0
  250. package/src/response/ResponseHandler.ts +614 -0
  251. package/src/response/ServerAuthorizationCodeResponse.ts +33 -0
  252. package/src/response/ServerAuthorizationTokenResponse.ts +54 -0
  253. package/src/telemetry/performance/IPerformanceClient.ts +71 -0
  254. package/src/telemetry/performance/IPerformanceMeasurement.ts +10 -0
  255. package/src/telemetry/performance/PerformanceClient.ts +635 -0
  256. package/src/telemetry/performance/PerformanceEvent.ts +542 -0
  257. package/src/telemetry/performance/StubPerformanceClient.ts +101 -0
  258. package/src/telemetry/server/ServerTelemetryManager.ts +274 -0
  259. package/src/telemetry/server/ServerTelemetryRequest.ts +13 -0
  260. package/src/url/IUri.ts +17 -0
  261. package/src/url/UrlString.ts +363 -0
  262. package/src/utils/Constants.ts +436 -0
  263. package/src/utils/FunctionWrappers.ts +105 -0
  264. package/src/utils/MsalTypes.ts +9 -0
  265. package/src/utils/ProtocolUtils.ts +124 -0
  266. package/src/utils/StringUtils.ts +106 -0
  267. package/src/utils/TimeUtils.ts +51 -0
  268. package/dist/account/DecodedAuthToken.d.ts +0 -9
  269. package/dist/account/DecodedAuthToken.d.ts.map +0 -1
@@ -0,0 +1,156 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { NetworkResponse } from "./NetworkManager";
7
+ import { ServerAuthorizationTokenResponse } from "../response/ServerAuthorizationTokenResponse";
8
+ import {
9
+ HeaderNames,
10
+ ThrottlingConstants,
11
+ Constants,
12
+ } from "../utils/Constants";
13
+ import { CacheManager } from "../cache/CacheManager";
14
+ import { ServerError } from "../error/ServerError";
15
+ import { RequestThumbprint } from "./RequestThumbprint";
16
+ import { ThrottlingEntity } from "../cache/entities/ThrottlingEntity";
17
+ import { BaseAuthRequest } from "../request/BaseAuthRequest";
18
+
19
+ /** @internal */
20
+ export class ThrottlingUtils {
21
+ /**
22
+ * Prepares a RequestThumbprint to be stored as a key.
23
+ * @param thumbprint
24
+ */
25
+ static generateThrottlingStorageKey(thumbprint: RequestThumbprint): string {
26
+ return `${ThrottlingConstants.THROTTLING_PREFIX}.${JSON.stringify(
27
+ thumbprint
28
+ )}`;
29
+ }
30
+
31
+ /**
32
+ * Performs necessary throttling checks before a network request.
33
+ * @param cacheManager
34
+ * @param thumbprint
35
+ */
36
+ static preProcess(
37
+ cacheManager: CacheManager,
38
+ thumbprint: RequestThumbprint
39
+ ): void {
40
+ const key = ThrottlingUtils.generateThrottlingStorageKey(thumbprint);
41
+ const value = cacheManager.getThrottlingCache(key);
42
+
43
+ if (value) {
44
+ if (value.throttleTime < Date.now()) {
45
+ cacheManager.removeItem(key);
46
+ return;
47
+ }
48
+ throw new ServerError(
49
+ value.errorCodes?.join(" ") || Constants.EMPTY_STRING,
50
+ value.errorMessage,
51
+ value.subError
52
+ );
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Performs necessary throttling checks after a network request.
58
+ * @param cacheManager
59
+ * @param thumbprint
60
+ * @param response
61
+ */
62
+ static postProcess(
63
+ cacheManager: CacheManager,
64
+ thumbprint: RequestThumbprint,
65
+ response: NetworkResponse<ServerAuthorizationTokenResponse>
66
+ ): void {
67
+ if (
68
+ ThrottlingUtils.checkResponseStatus(response) ||
69
+ ThrottlingUtils.checkResponseForRetryAfter(response)
70
+ ) {
71
+ const thumbprintValue: ThrottlingEntity = {
72
+ throttleTime: ThrottlingUtils.calculateThrottleTime(
73
+ parseInt(response.headers[HeaderNames.RETRY_AFTER])
74
+ ),
75
+ error: response.body.error,
76
+ errorCodes: response.body.error_codes,
77
+ errorMessage: response.body.error_description,
78
+ subError: response.body.suberror,
79
+ };
80
+ cacheManager.setThrottlingCache(
81
+ ThrottlingUtils.generateThrottlingStorageKey(thumbprint),
82
+ thumbprintValue
83
+ );
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Checks a NetworkResponse object's status codes against 429 or 5xx
89
+ * @param response
90
+ */
91
+ static checkResponseStatus(
92
+ response: NetworkResponse<ServerAuthorizationTokenResponse>
93
+ ): boolean {
94
+ return (
95
+ response.status === 429 ||
96
+ (response.status >= 500 && response.status < 600)
97
+ );
98
+ }
99
+
100
+ /**
101
+ * Checks a NetworkResponse object's RetryAfter header
102
+ * @param response
103
+ */
104
+ static checkResponseForRetryAfter(
105
+ response: NetworkResponse<ServerAuthorizationTokenResponse>
106
+ ): boolean {
107
+ if (response.headers) {
108
+ return (
109
+ response.headers.hasOwnProperty(HeaderNames.RETRY_AFTER) &&
110
+ (response.status < 200 || response.status >= 300)
111
+ );
112
+ }
113
+ return false;
114
+ }
115
+
116
+ /**
117
+ * Calculates the Unix-time value for a throttle to expire given throttleTime in seconds.
118
+ * @param throttleTime
119
+ */
120
+ static calculateThrottleTime(throttleTime: number): number {
121
+ const time = throttleTime <= 0 ? 0 : throttleTime;
122
+
123
+ const currentSeconds = Date.now() / 1000;
124
+ return Math.floor(
125
+ Math.min(
126
+ currentSeconds +
127
+ (time || ThrottlingConstants.DEFAULT_THROTTLE_TIME_SECONDS),
128
+ currentSeconds +
129
+ ThrottlingConstants.DEFAULT_MAX_THROTTLE_TIME_SECONDS
130
+ ) * 1000
131
+ );
132
+ }
133
+
134
+ static removeThrottle(
135
+ cacheManager: CacheManager,
136
+ clientId: string,
137
+ request: BaseAuthRequest,
138
+ homeAccountIdentifier?: string
139
+ ): void {
140
+ const thumbprint: RequestThumbprint = {
141
+ clientId: clientId,
142
+ authority: request.authority,
143
+ scopes: request.scopes,
144
+ homeAccountIdentifier: homeAccountIdentifier,
145
+ claims: request.claims,
146
+ authenticationScheme: request.authenticationScheme,
147
+ resourceRequestMethod: request.resourceRequestMethod,
148
+ resourceRequestUri: request.resourceRequestUri,
149
+ shrClaims: request.shrClaims,
150
+ sshKid: request.sshKid,
151
+ };
152
+
153
+ const key = this.generateThrottlingStorageKey(thumbprint);
154
+ cacheManager.removeItem(key);
155
+ }
156
+ }
@@ -0,0 +1,3 @@
1
+ /* eslint-disable header/header */
2
+ export const name = "@azure/msal-common";
3
+ export const version = "14.0.3";
@@ -0,0 +1,89 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ClientConfigurationError } from "../error/ClientConfigurationError";
7
+ import { Constants, HeaderNames } from "../utils/Constants";
8
+
9
+ type WWWAuthenticateChallenges = {
10
+ nonce?: string;
11
+ };
12
+
13
+ type AuthenticationInfoChallenges = {
14
+ nextnonce?: string;
15
+ };
16
+
17
+ /**
18
+ * This is a helper class that parses supported HTTP response authentication headers to extract and return
19
+ * header challenge values that can be used outside the basic authorization flows.
20
+ */
21
+ export class AuthenticationHeaderParser {
22
+ private headers: Record<string, string>;
23
+
24
+ constructor(headers: Record<string, string>) {
25
+ this.headers = headers;
26
+ }
27
+
28
+ /**
29
+ * This method parses the SHR nonce value out of either the Authentication-Info or WWW-Authenticate authentication headers.
30
+ * @returns
31
+ */
32
+ getShrNonce(): string {
33
+ // Attempt to parse nonce from Authentiacation-Info
34
+ const authenticationInfo = this.headers[HeaderNames.AuthenticationInfo];
35
+ if (authenticationInfo) {
36
+ const authenticationInfoChallenges =
37
+ this.parseChallenges<AuthenticationInfoChallenges>(
38
+ authenticationInfo
39
+ );
40
+ if (authenticationInfoChallenges.nextnonce) {
41
+ return authenticationInfoChallenges.nextnonce;
42
+ }
43
+ throw ClientConfigurationError.createInvalidAuthenticationHeaderError(
44
+ HeaderNames.AuthenticationInfo,
45
+ "nextnonce challenge is missing."
46
+ );
47
+ }
48
+
49
+ // Attempt to parse nonce from WWW-Authenticate
50
+ const wwwAuthenticate = this.headers[HeaderNames.WWWAuthenticate];
51
+ if (wwwAuthenticate) {
52
+ const wwwAuthenticateChallenges =
53
+ this.parseChallenges<WWWAuthenticateChallenges>(
54
+ wwwAuthenticate
55
+ );
56
+ if (wwwAuthenticateChallenges.nonce) {
57
+ return wwwAuthenticateChallenges.nonce;
58
+ }
59
+ throw ClientConfigurationError.createInvalidAuthenticationHeaderError(
60
+ HeaderNames.WWWAuthenticate,
61
+ "nonce challenge is missing."
62
+ );
63
+ }
64
+
65
+ // If neither header is present, throw missing headers error
66
+ throw ClientConfigurationError.createMissingNonceAuthenticationHeadersError();
67
+ }
68
+
69
+ /**
70
+ * Parses an HTTP header's challenge set into a key/value map.
71
+ * @param header
72
+ * @returns
73
+ */
74
+ private parseChallenges<T>(header: string): T {
75
+ const schemeSeparator = header.indexOf(" ");
76
+ const challenges = header.substr(schemeSeparator + 1).split(",");
77
+ const challengeMap = {} as T;
78
+
79
+ challenges.forEach((challenge: string) => {
80
+ const [key, value] = challenge.split("=");
81
+ // Remove escaped quotation marks (', ") from challenge string to keep only the challenge value
82
+ challengeMap[key] = unescape(
83
+ value.replace(/['"]+/g, Constants.EMPTY_STRING)
84
+ );
85
+ });
86
+
87
+ return challengeMap;
88
+ }
89
+ }
@@ -0,0 +1,46 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { AuthenticationScheme } from "../utils/Constants";
7
+ import { AzureCloudOptions } from "../config/ClientConfiguration";
8
+ import { StringDict } from "../utils/MsalTypes";
9
+ import { StoreInCache } from "./StoreInCache";
10
+
11
+ /**
12
+ * BaseAuthRequest
13
+ * - authority - URL of the authority, the security token service (STS) from which MSAL will acquire tokens. Defaults to https://login.microsoftonline.com/common. If using the same authority for all request, authority should set on client application object and not request, to avoid resolving authority endpoints multiple times.
14
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
15
+ * - scopes - Array of scopes the application is requesting access to.
16
+ * - authenticationScheme - The type of token retrieved. Defaults to "Bearer". Can also be type "pop" or "SSH".
17
+ * - claims - A stringified claims request which will be added to all /authorize and /token calls
18
+ * - shrClaims - A stringified claims object which will be added to a Signed HTTP Request
19
+ * - shrNonce - A server-generated timestamp that has been encrypted and base64URL encoded, which will be added to a Signed HTTP Request.
20
+ * - resourceRequestMethod - HTTP Request type used to request data from the resource (i.e. "GET", "POST", etc.). Used for proof-of-possession flows.
21
+ * - resourceRequestUri - URI that token will be used for. Used for proof-of-possession flows.
22
+ * - sshJwk - A stringified JSON Web Key representing a public key that can be signed by an SSH certificate.
23
+ * - sshKid - Key ID that uniquely identifies the SSH public key mentioned above.
24
+ * - azureCloudOptions - Convenience string enums for users to provide public/sovereign cloud ids
25
+ * - requestedClaimsHash - SHA 256 hash string of the requested claims string, used as part of an access token cache key so tokens can be filtered by requested claims
26
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
27
+ * - storeInCache - Object containing boolean values indicating whether to store tokens in the cache or not (default is true)
28
+ */
29
+ export type BaseAuthRequest = {
30
+ authority: string;
31
+ correlationId: string;
32
+ scopes: Array<string>;
33
+ authenticationScheme?: AuthenticationScheme;
34
+ claims?: string;
35
+ shrClaims?: string;
36
+ shrNonce?: string;
37
+ resourceRequestMethod?: string;
38
+ resourceRequestUri?: string;
39
+ sshJwk?: string;
40
+ sshKid?: string;
41
+ azureCloudOptions?: AzureCloudOptions;
42
+ requestedClaimsHash?: string;
43
+ maxAge?: number;
44
+ tokenQueryParameters?: StringDict;
45
+ storeInCache?: StoreInCache;
46
+ };
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { BaseAuthRequest } from "./BaseAuthRequest";
7
+ import { StringDict } from "../utils/MsalTypes";
8
+ import { CcsCredential } from "../account/CcsCredential";
9
+
10
+ /**
11
+ * Request object passed by user to acquire a token from the server exchanging a valid authorization code (second leg of OAuth2.0 Authorization Code flow)
12
+ *
13
+ * - scopes - Array of scopes the application is requesting access to.
14
+ * - claims - A stringified claims request which will be added to all /authorize and /token calls
15
+ * - authority: - URL of the authority, the security token service (STS) from which MSAL will acquire tokens. If authority is set on client application object, this will override that value. Overriding the value will cause for authority validation to happen each time. If the same authority will be used for all request, set on the application object instead of the requests.
16
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
17
+ * - redirectUri - The redirect URI of your app, where the authority will redirect to after the user inputs credentials and consents. It must exactly match one of the redirect URIs you registered in the portal
18
+ * - code - The authorization_code that the user acquired in the first leg of the flow.
19
+ * - codeVerifier - The same code_verifier that was used to obtain the authorization_code. Required if PKCE was used in the authorization code grant request.For more information, see the PKCE RFC: https://tools.ietf.org/html/rfc7636
20
+ * - resourceRequestMethod - HTTP Request type used to request data from the resource (i.e. "GET", "POST", etc.). Used for proof-of-possession flows.
21
+ * - resourceRequestUri - URI that token will be used for. Used for proof-of-possession flows.
22
+ * - enableSpaAuthCode - Enables the acqusition of a spa authorization code (confidential clients only)
23
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
24
+ */
25
+ export type CommonAuthorizationCodeRequest = BaseAuthRequest & {
26
+ code: string;
27
+ redirectUri: string;
28
+ codeVerifier?: string;
29
+ tokenBodyParameters?: StringDict;
30
+ enableSpaAuthorizationCode?: boolean;
31
+ clientInfo?: string;
32
+ ccsCredential?: CcsCredential;
33
+ };
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ResponseMode } from "../utils/Constants";
7
+ import { StringDict } from "../utils/MsalTypes";
8
+ import { BaseAuthRequest } from "./BaseAuthRequest";
9
+ import { AccountInfo } from "../account/AccountInfo";
10
+
11
+ /**
12
+ * Request object passed by user to retrieve a Code from the server (first leg of authorization code grant flow)
13
+ *
14
+ * - scopes - Array of scopes the application is requesting access to.
15
+ * - claims - A stringified claims request which will be added to all /authorize and /token calls
16
+ * - authority - Url of the authority which the application acquires tokens from.
17
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
18
+ * - redirectUri - The redirect URI where authentication responses can be received by your application. It must exactly match one of the redirect URIs registered in the Azure portal.
19
+ * - extraScopesToConsent - Scopes for a different resource when the user needs consent upfront.
20
+ * - responseMode - Specifies the method that should be used to send the authentication result to your app. Can be query, form_post, or fragment. If no value is passed in, it defaults to query.
21
+ * - codeChallenge - Used to secure authorization code grant via Proof of Key for Code Exchange (PKCE). For more information, see the PKCE RCF:https://tools.ietf.org/html/rfc7636
22
+ * - codeChallengeMethod - The method used to encode the code verifier for the code challenge parameter. Can be "plain" or "S256". If excluded, code challenge is assumed to be plaintext. For more information, see the PKCE RCF: https://tools.ietf.org/html/rfc7636
23
+ * - state - A value included in the request that is also returned in the token response. A randomly generated unique value is typically used for preventing cross site request forgery attacks. The state is also used to encode information about the user's state in the app before the authentication request occurred.
24
+ * - prompt - Indicates the type of user interaction that is required.
25
+ * login: will force the user to enter their credentials on that request, negating single-sign on
26
+ * none: will ensure that the user isn't presented with any interactive prompt. if request can't be completed via single-sign on, the endpoint will return an interaction_required error
27
+ * consent: will the trigger the OAuth consent dialog after the user signs in, asking the user to grant permissions to the app
28
+ * select_account: will interrupt single sign-=on providing account selection experience listing all the accounts in session or any remembered accounts or an option to choose to use a different account
29
+ * create: will direct the user to the account creation experience instead of the log in experience
30
+ * no_session: will not read existing session token when authenticating the user. Upon user being successfully authenticated, EVO won’t create a new session for the user. FOR INTERNAL USE ONLY.
31
+ * - account - AccountInfo obtained from a getAccount API. Will be used in certain scenarios to generate login_hint if both loginHint and sid params are not provided.
32
+ * - loginHint - Can be used to pre-fill the username/email address field of the sign-in page for the user, if you know the username/email address ahead of time. Often apps use this parameter during re-authentication, having already extracted the username from a previous sign-in using the preferred_username claim.
33
+ * - sid - Session ID, unique identifier for the session. Available as an optional claim on ID tokens.
34
+ * - domainHint - Provides a hint about the tenant or domain that the user should use to sign in. The value of the domain hint is a registered domain for the tenant.
35
+ * - extraQueryParameters - String to string map of custom query parameters added to the /authorize call
36
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
37
+ * - nonce - A value included in the request that is returned in the id token. A randomly generated unique value is typically used to mitigate replay attacks.
38
+ * - resourceRequestMethod - HTTP Request type used to request data from the resource (i.e. "GET", "POST", etc.). Used for proof-of-possession flows.
39
+ * - resourceRequestUri - URI that token will be used for. Used for proof-of-possession flows.
40
+ */
41
+ export type CommonAuthorizationUrlRequest = BaseAuthRequest & {
42
+ redirectUri: string;
43
+ responseMode: ResponseMode;
44
+ account?: AccountInfo;
45
+ codeChallenge?: string;
46
+ codeChallengeMethod?: string;
47
+ domainHint?: string;
48
+ extraQueryParameters?: StringDict;
49
+ extraScopesToConsent?: Array<string>;
50
+ loginHint?: string;
51
+ nonce?: string;
52
+ prompt?: string;
53
+ sid?: string;
54
+ state?: string;
55
+ nativeBroker?: boolean;
56
+ };
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { BaseAuthRequest } from "./BaseAuthRequest";
7
+ import { AzureRegion } from "../authority/AzureRegion";
8
+ import { ClientAssertion } from "../account/ClientCredentials";
9
+
10
+ /**
11
+ * CommonClientCredentialRequest
12
+ * - scopes - Array of scopes the application is requesting access to.
13
+ * - authority - URL of the authority, the security token service (STS) from which MSAL will acquire tokens.
14
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
15
+ * - skipCache - Skip token cache lookup and force request to authority to get a a new token. Defaults to false.
16
+ * - preferredAzureRegionOptions - Options of the user's preferred azure region
17
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
18
+ */
19
+ export type CommonClientCredentialRequest = BaseAuthRequest & {
20
+ skipCache?: boolean;
21
+ azureRegion?: AzureRegion;
22
+ clientAssertion?: ClientAssertion;
23
+ };
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { DeviceCodeResponse } from "../response/DeviceCodeResponse";
7
+ import { StringDict } from "../utils/MsalTypes";
8
+ import { BaseAuthRequest } from "./BaseAuthRequest";
9
+
10
+ /**
11
+ * Parameters for Oauth2 device code flow.
12
+ * - scopes - Array of scopes the application is requesting access to.
13
+ * - authority: - URL of the authority, the security token service (STS) from which MSAL will acquire tokens. If authority is set on client application object, this will override that value. Overriding the value will cause for authority validation to happen each time. If the same authority will be used for all request, set on the application object instead of the requests.
14
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
15
+ * - deviceCodeCallback - Callback containing device code response. Message should be shown to end user. End user can then navigate to the verification_uri, input the user_code, and input credentials.
16
+ * - cancel - Boolean to cancel polling of device code endpoint. While the user authenticates on a separate device, MSAL polls the the token endpoint of security token service for the interval specified in the device code response (usually 15 minutes). To stop polling and cancel the request, set cancel=true.
17
+ * - resourceRequestMethod - HTTP Request type used to request data from the resource (i.e. "GET", "POST", etc.). Used for proof-of-possession flows.
18
+ * - resourceRequestUri - URI that token will be used for. Used for proof-of-possession flows.
19
+ * - timeout - Timeout period in seconds which the user explicitly configures for the polling of the device code endpoint. At the end of this period; assuming the device code has not expired yet; the device code polling is stopped and the request cancelled. The device code expiration window will always take precedence over this set period.
20
+ * - extraQueryParameters - String to string map of custom query parameters added to the query string
21
+ */
22
+ // export type CommonDeviceCodeRequest = BaseAuthRequest & {
23
+ export type CommonDeviceCodeRequest = Omit<
24
+ BaseAuthRequest,
25
+ "tokenQueryParameters"
26
+ > & {
27
+ deviceCodeCallback: (response: DeviceCodeResponse) => void;
28
+ cancel?: boolean;
29
+ timeout?: number;
30
+ extraQueryParameters?: StringDict;
31
+ };
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { AccountInfo } from "../account/AccountInfo";
7
+ import { StringDict } from "../utils/MsalTypes";
8
+
9
+ /**
10
+ * CommonEndSessionRequest
11
+ * - account - Account object that will be logged out of. All tokens tied to this account will be cleared.
12
+ * - postLogoutRedirectUri - URI to navigate to after logout page.
13
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
14
+ * - idTokenHint - ID Token used by B2C to validate logout if required by the policy
15
+ * - state - A value included in the request to the logout endpoint which will be returned in the query string upon post logout redirection
16
+ * - logoutHint - A string that specifies the account that is being logged out in order to skip the server account picker on logout
17
+ * - extraQueryParameters - String to string map of custom query parameters added to the /authorize call
18
+ */
19
+ export type CommonEndSessionRequest = {
20
+ correlationId: string;
21
+ account?: AccountInfo | null;
22
+ postLogoutRedirectUri?: string | null;
23
+ idTokenHint?: string;
24
+ state?: string;
25
+ logoutHint?: string;
26
+ extraQueryParameters?: StringDict;
27
+ };
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { BaseAuthRequest } from "./BaseAuthRequest";
7
+
8
+ /**
9
+ * - scopes - Array of scopes the application is requesting access to.
10
+ * - authority - URL of the authority, the security token service (STS) from which MSAL will acquire tokens.
11
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
12
+ * - oboAssertion - The access token that was sent to the middle-tier API. This token must have an audience of the app making this OBO request.
13
+ * - skipCache - Skip token cache lookup and force request to authority to get a a new token. Defaults to false.
14
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
15
+ */
16
+ export type CommonOnBehalfOfRequest = BaseAuthRequest & {
17
+ oboAssertion: string;
18
+ skipCache?: boolean;
19
+ };
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { BaseAuthRequest } from "./BaseAuthRequest";
7
+ import { CcsCredential } from "../account/CcsCredential";
8
+
9
+ /**
10
+ * CommonRefreshTokenRequest
11
+ * - scopes - Array of scopes the application is requesting access to.
12
+ * - claims - A stringified claims request which will be added to all /authorize and /token calls
13
+ * - authority - URL of the authority, the security token service (STS) from which MSAL will acquire tokens.
14
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
15
+ * - refreshToken - A refresh token returned from a previous request to the Identity provider.
16
+ * - resourceRequestMethod - HTTP Request type used to request data from the resource (i.e. "GET", "POST", etc.). Used for proof-of-possession flows.
17
+ * - resourceRequestUri - URI that token will be used for. Used for proof-of-possession flows.
18
+ * - forceCache - Force MSAL to cache a refresh token flow response when there is no account in the cache. Used for migration scenarios.
19
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
20
+ */
21
+ export type CommonRefreshTokenRequest = BaseAuthRequest & {
22
+ refreshToken: string;
23
+ ccsCredential?: CcsCredential;
24
+ forceCache?: boolean;
25
+ };
@@ -0,0 +1,24 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { AccountInfo } from "../account/AccountInfo";
7
+ import { BaseAuthRequest } from "./BaseAuthRequest";
8
+
9
+ /**
10
+ * SilentFlow parameters passed by the user to retrieve credentials silently
11
+ * - scopes - Array of scopes the application is requesting access to.
12
+ * - claims - A stringified claims request which will be added to all /authorize and /token calls. When included on a silent request, cache lookup will be skipped and token will be refreshed.
13
+ * - authority - Url of the authority which the application acquires tokens from.
14
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
15
+ * - account - Account entity to lookup the credentials.
16
+ * - forceRefresh - Forces silent requests to make network calls if true.
17
+ * - resourceRequestMethod - HTTP Request type used to request data from the resource (i.e. "GET", "POST", etc.). Used for proof-of-possession flows.
18
+ * - resourceRequestUri - URI that token will be used for. Used for proof-of-possession flows.
19
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
20
+ */
21
+ export type CommonSilentFlowRequest = BaseAuthRequest & {
22
+ account: AccountInfo;
23
+ forceRefresh: boolean;
24
+ };
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { BaseAuthRequest } from "./BaseAuthRequest";
7
+
8
+ /**
9
+ * CommonUsernamePassword parameters passed by the user to retrieve credentials
10
+ * Note: The latest OAuth 2.0 Security Best Current Practice disallows the password grant entirely. This flow is added for internal testing.
11
+ *
12
+ * - scopes - Array of scopes the application is requesting access to.
13
+ * - claims - A stringified claims request which will be added to all /authorize and /token calls. When included on a silent request, cache lookup will be skipped and token will be refreshed.
14
+ * - authority - Url of the authority which the application acquires tokens from.
15
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
16
+ * - username - username of the client
17
+ * - password - credentials
18
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
19
+ */
20
+ export type CommonUsernamePasswordRequest = BaseAuthRequest & {
21
+ username: string;
22
+ password: string;
23
+ };
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { StringDict } from "../utils/MsalTypes";
7
+
8
+ export type NativeRequest = {
9
+ clientId: string;
10
+ authority: string;
11
+ correlationId: string;
12
+ redirectUri: string;
13
+ scopes: Array<string>;
14
+ claims?: string;
15
+ authenticationScheme?: string;
16
+ resourceRequestMethod?: string;
17
+ resourceRequestUri?: string;
18
+ shrNonce?: string;
19
+ accountId?: string;
20
+ forceRefresh?: boolean;
21
+ extraParameters?: StringDict;
22
+ extraScopesToConsent?: Array<string>;
23
+ loginHint?: string;
24
+ prompt?: string;
25
+ };
@@ -0,0 +1,10 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ export type NativeSignOutRequest = {
7
+ clientId: string;
8
+ accountId: string;
9
+ correlationId: string;
10
+ };