@azure/msal-browser 3.0.2 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. package/dist/app/IPublicClientApplication.d.ts +2 -0
  2. package/dist/app/IPublicClientApplication.d.ts.map +1 -1
  3. package/dist/app/IPublicClientApplication.mjs +22 -18
  4. package/dist/app/IPublicClientApplication.mjs.map +1 -1
  5. package/dist/app/PublicClientApplication.d.ts +20 -6
  6. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  7. package/dist/app/PublicClientApplication.mjs +24 -7
  8. package/dist/app/PublicClientApplication.mjs.map +1 -1
  9. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +3 -4
  10. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
  11. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +17 -16
  12. package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +1 -1
  13. package/dist/broker/nativeBroker/NativeStatusCodes.d.ts +8 -0
  14. package/dist/broker/nativeBroker/NativeStatusCodes.d.ts.map +1 -0
  15. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +16 -0
  16. package/dist/broker/nativeBroker/NativeStatusCodes.mjs.map +1 -0
  17. package/dist/cache/AsyncMemoryStorage.mjs +4 -3
  18. package/dist/cache/AsyncMemoryStorage.mjs.map +1 -1
  19. package/dist/cache/BrowserCacheManager.d.ts +10 -3
  20. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  21. package/dist/cache/BrowserCacheManager.mjs +58 -29
  22. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  23. package/dist/cache/BrowserStorage.d.ts.map +1 -1
  24. package/dist/cache/BrowserStorage.mjs +7 -9
  25. package/dist/cache/BrowserStorage.mjs.map +1 -1
  26. package/dist/cache/CryptoKeyStore.mjs +1 -1
  27. package/dist/cache/CryptoKeyStore.mjs.map +1 -1
  28. package/dist/cache/DatabaseStorage.d.ts.map +1 -1
  29. package/dist/cache/DatabaseStorage.mjs +9 -8
  30. package/dist/cache/DatabaseStorage.mjs.map +1 -1
  31. package/dist/cache/MemoryStorage.mjs +1 -1
  32. package/dist/cache/MemoryStorage.mjs.map +1 -1
  33. package/dist/cache/TokenCache.d.ts.map +1 -1
  34. package/dist/cache/TokenCache.mjs +30 -30
  35. package/dist/cache/TokenCache.mjs.map +1 -1
  36. package/dist/config/Configuration.d.ts +1 -0
  37. package/dist/config/Configuration.d.ts.map +1 -1
  38. package/dist/config/Configuration.mjs +12 -16
  39. package/dist/config/Configuration.mjs.map +1 -1
  40. package/dist/controllers/ControllerFactory.mjs +1 -1
  41. package/dist/controllers/ControllerFactory.mjs.map +1 -1
  42. package/dist/controllers/IController.d.ts +5 -28
  43. package/dist/controllers/IController.d.ts.map +1 -1
  44. package/dist/controllers/StandardController.d.ts +17 -31
  45. package/dist/controllers/StandardController.d.ts.map +1 -1
  46. package/dist/controllers/StandardController.mjs +78 -83
  47. package/dist/controllers/StandardController.mjs.map +1 -1
  48. package/dist/crypto/BrowserCrypto.d.ts +44 -49
  49. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  50. package/dist/crypto/BrowserCrypto.mjs +78 -77
  51. package/dist/crypto/BrowserCrypto.mjs.map +1 -1
  52. package/dist/crypto/CryptoOps.d.ts +1 -10
  53. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  54. package/dist/crypto/CryptoOps.mjs +23 -34
  55. package/dist/crypto/CryptoOps.mjs.map +1 -1
  56. package/dist/crypto/PkceGenerator.d.ts +6 -22
  57. package/dist/crypto/PkceGenerator.d.ts.map +1 -1
  58. package/dist/crypto/PkceGenerator.mjs +48 -49
  59. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  60. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  61. package/dist/crypto/SignedHttpRequest.mjs.map +1 -1
  62. package/dist/encode/Base64Decode.d.ts +6 -19
  63. package/dist/encode/Base64Decode.d.ts.map +1 -1
  64. package/dist/encode/Base64Decode.mjs +31 -68
  65. package/dist/encode/Base64Decode.mjs.map +1 -1
  66. package/dist/encode/Base64Encode.d.ts +15 -27
  67. package/dist/encode/Base64Encode.d.ts.map +1 -1
  68. package/dist/encode/Base64Encode.mjs +36 -75
  69. package/dist/encode/Base64Encode.mjs.map +1 -1
  70. package/dist/error/BrowserAuthError.d.ts +63 -195
  71. package/dist/error/BrowserAuthError.d.ts.map +1 -1
  72. package/dist/error/BrowserAuthError.mjs +159 -381
  73. package/dist/error/BrowserAuthError.mjs.map +1 -1
  74. package/dist/error/BrowserAuthErrorCodes.d.ts +46 -0
  75. package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -0
  76. package/dist/error/BrowserAuthErrorCodes.mjs +54 -0
  77. package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -0
  78. package/dist/error/BrowserConfigurationAuthError.d.ts +9 -46
  79. package/dist/error/BrowserConfigurationAuthError.d.ts.map +1 -1
  80. package/dist/error/BrowserConfigurationAuthError.mjs +20 -73
  81. package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
  82. package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts +4 -0
  83. package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts.map +1 -0
  84. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +12 -0
  85. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs.map +1 -0
  86. package/dist/error/NativeAuthError.d.ts +17 -45
  87. package/dist/error/NativeAuthError.d.ts.map +1 -1
  88. package/dist/error/NativeAuthError.mjs +49 -79
  89. package/dist/error/NativeAuthError.mjs.map +1 -1
  90. package/dist/error/NativeAuthErrorCodes.d.ts +3 -0
  91. package/dist/error/NativeAuthErrorCodes.d.ts.map +1 -0
  92. package/dist/error/NativeAuthErrorCodes.mjs +11 -0
  93. package/dist/error/NativeAuthErrorCodes.mjs.map +1 -0
  94. package/dist/event/EventHandler.d.ts.map +1 -1
  95. package/dist/event/EventHandler.mjs +3 -2
  96. package/dist/event/EventHandler.mjs.map +1 -1
  97. package/dist/event/EventMessage.mjs +1 -1
  98. package/dist/event/EventMessage.mjs.map +1 -1
  99. package/dist/event/EventType.mjs +1 -1
  100. package/dist/event/EventType.mjs.map +1 -1
  101. package/dist/index.d.ts +6 -6
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.mjs +8 -4
  104. package/dist/index.mjs.map +1 -1
  105. package/dist/interaction_client/BaseInteractionClient.d.ts +2 -1
  106. package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
  107. package/dist/interaction_client/BaseInteractionClient.mjs +7 -8
  108. package/dist/interaction_client/BaseInteractionClient.mjs.map +1 -1
  109. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  110. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs.map +1 -1
  111. package/dist/interaction_client/NativeInteractionClient.d.ts +4 -10
  112. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  113. package/dist/interaction_client/NativeInteractionClient.mjs +32 -38
  114. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  115. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  116. package/dist/interaction_client/PopupClient.mjs +16 -15
  117. package/dist/interaction_client/PopupClient.mjs.map +1 -1
  118. package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
  119. package/dist/interaction_client/RedirectClient.mjs +7 -6
  120. package/dist/interaction_client/RedirectClient.mjs.map +1 -1
  121. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  122. package/dist/interaction_client/SilentAuthCodeClient.mjs +9 -11
  123. package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
  124. package/dist/interaction_client/SilentCacheClient.d.ts +4 -2
  125. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  126. package/dist/interaction_client/SilentCacheClient.mjs +19 -25
  127. package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
  128. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  129. package/dist/interaction_client/SilentIframeClient.mjs +20 -47
  130. package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
  131. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
  132. package/dist/interaction_client/SilentRefreshClient.mjs +11 -20
  133. package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
  134. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  135. package/dist/interaction_client/StandardInteractionClient.mjs +18 -38
  136. package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
  137. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  138. package/dist/interaction_handler/InteractionHandler.mjs +13 -16
  139. package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
  140. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  141. package/dist/interaction_handler/RedirectHandler.mjs +12 -11
  142. package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
  143. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  144. package/dist/interaction_handler/SilentHandler.mjs +11 -11
  145. package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
  146. package/dist/navigation/NavigationClient.mjs +1 -1
  147. package/dist/navigation/NavigationClient.mjs.map +1 -1
  148. package/dist/network/FetchClient.d.ts.map +1 -1
  149. package/dist/network/FetchClient.mjs +9 -8
  150. package/dist/network/FetchClient.mjs.map +1 -1
  151. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  152. package/dist/operatingcontext/BaseOperatingContext.mjs.map +1 -1
  153. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  154. package/dist/operatingcontext/StandardOperatingContext.mjs.map +1 -1
  155. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +1 -1
  156. package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
  157. package/dist/packageMetadata.d.ts +1 -1
  158. package/dist/packageMetadata.mjs +2 -2
  159. package/dist/packageMetadata.mjs.map +1 -1
  160. package/dist/request/ClearCacheRequest.d.ts +11 -0
  161. package/dist/request/ClearCacheRequest.d.ts.map +1 -0
  162. package/dist/telemetry/BrowserPerformanceClient.d.ts +2 -4
  163. package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -1
  164. package/dist/telemetry/BrowserPerformanceClient.mjs +2 -6
  165. package/dist/telemetry/BrowserPerformanceClient.mjs.map +1 -1
  166. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  167. package/dist/telemetry/BrowserPerformanceMeasurement.mjs.map +1 -1
  168. package/dist/utils/BrowserConstants.mjs +1 -1
  169. package/dist/utils/BrowserConstants.mjs.map +1 -1
  170. package/dist/utils/BrowserProtocolUtils.d.ts.map +1 -1
  171. package/dist/utils/BrowserProtocolUtils.mjs +4 -4
  172. package/dist/utils/BrowserProtocolUtils.mjs.map +1 -1
  173. package/dist/utils/BrowserStringUtils.mjs +1 -1
  174. package/dist/utils/BrowserStringUtils.mjs.map +1 -1
  175. package/dist/utils/BrowserUtils.d.ts +0 -9
  176. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  177. package/dist/utils/BrowserUtils.mjs +8 -33
  178. package/dist/utils/BrowserUtils.mjs.map +1 -1
  179. package/lib/msal-browser.cjs +8729 -9566
  180. package/lib/msal-browser.cjs.map +1 -1
  181. package/lib/msal-browser.js +8729 -9566
  182. package/lib/msal-browser.js.map +1 -1
  183. package/lib/msal-browser.min.js +68 -62
  184. package/package.json +7 -5
  185. package/src/app/IPublicClientApplication.ts +236 -0
  186. package/src/app/PublicClientApplication.ts +417 -0
  187. package/src/broker/nativeBroker/NativeMessageHandler.ts +416 -0
  188. package/src/broker/nativeBroker/NativeRequest.ts +52 -0
  189. package/src/broker/nativeBroker/NativeResponse.ts +56 -0
  190. package/src/broker/nativeBroker/NativeStatusCodes.ts +13 -0
  191. package/src/cache/AsyncMemoryStorage.ts +158 -0
  192. package/src/cache/BrowserCacheManager.ts +2009 -0
  193. package/src/cache/BrowserStorage.ts +52 -0
  194. package/src/cache/CryptoKeyStore.ts +63 -0
  195. package/src/cache/DatabaseStorage.ts +287 -0
  196. package/src/cache/IAsyncMemoryStorage.ts +36 -0
  197. package/src/cache/ITokenCache.ts +21 -0
  198. package/src/cache/IWindowStorage.ts +36 -0
  199. package/src/cache/MemoryStorage.ts +42 -0
  200. package/src/cache/TokenCache.ts +484 -0
  201. package/src/config/Configuration.ts +383 -0
  202. package/src/controllers/ControllerFactory.ts +55 -0
  203. package/src/controllers/IController.ts +134 -0
  204. package/src/controllers/StandardController.ts +2170 -0
  205. package/src/crypto/BrowserCrypto.ts +151 -0
  206. package/src/crypto/CryptoOps.ts +235 -0
  207. package/src/crypto/PkceGenerator.ts +115 -0
  208. package/src/crypto/SignedHttpRequest.ts +76 -0
  209. package/src/encode/Base64Decode.ts +46 -0
  210. package/src/encode/Base64Encode.ts +52 -0
  211. package/src/error/BrowserAuthError.ts +352 -0
  212. package/src/error/BrowserAuthErrorCodes.ts +57 -0
  213. package/src/error/BrowserConfigurationAuthError.ts +64 -0
  214. package/src/error/BrowserConfigurationAuthErrorCodes.ts +9 -0
  215. package/src/error/NativeAuthError.ts +113 -0
  216. package/src/error/NativeAuthErrorCodes.ts +7 -0
  217. package/src/event/EventHandler.ts +177 -0
  218. package/src/event/EventMessage.ts +125 -0
  219. package/src/event/EventType.ts +33 -0
  220. package/src/index.ts +157 -0
  221. package/src/interaction_client/BaseInteractionClient.ts +307 -0
  222. package/src/interaction_client/HybridSpaAuthorizationCodeClient.ts +16 -0
  223. package/src/interaction_client/NativeInteractionClient.ts +925 -0
  224. package/src/interaction_client/PopupClient.ts +926 -0
  225. package/src/interaction_client/RedirectClient.ts +616 -0
  226. package/src/interaction_client/SilentAuthCodeClient.ts +165 -0
  227. package/src/interaction_client/SilentCacheClient.ts +125 -0
  228. package/src/interaction_client/SilentIframeClient.ts +301 -0
  229. package/src/interaction_client/SilentRefreshClient.ts +118 -0
  230. package/src/interaction_client/StandardInteractionClient.ts +450 -0
  231. package/src/interaction_handler/InteractionHandler.ts +251 -0
  232. package/src/interaction_handler/RedirectHandler.ts +229 -0
  233. package/src/interaction_handler/SilentHandler.ts +269 -0
  234. package/src/navigation/INavigationClient.ts +23 -0
  235. package/src/navigation/NavigationClient.ts +55 -0
  236. package/src/navigation/NavigationOptions.ts +18 -0
  237. package/src/network/FetchClient.ts +130 -0
  238. package/src/operatingcontext/BaseOperatingContext.ts +82 -0
  239. package/src/operatingcontext/StandardOperatingContext.ts +49 -0
  240. package/src/operatingcontext/TeamsAppOperatingContext.ts +48 -0
  241. package/src/packageMetadata.ts +3 -0
  242. package/src/request/AuthorizationCodeRequest.ts +19 -0
  243. package/src/request/AuthorizationUrlRequest.ts +17 -0
  244. package/src/request/ClearCacheRequest.ts +16 -0
  245. package/src/request/EndSessionPopupRequest.ts +26 -0
  246. package/src/request/EndSessionRequest.ts +23 -0
  247. package/src/request/PopupRequest.ts +51 -0
  248. package/src/request/PopupWindowAttributes.ts +22 -0
  249. package/src/request/RedirectRequest.ts +51 -0
  250. package/src/request/SilentRequest.ts +49 -0
  251. package/src/request/SsoSilentRequest.ts +44 -0
  252. package/src/response/AuthenticationResult.ts +13 -0
  253. package/src/telemetry/BrowserPerformanceClient.ts +226 -0
  254. package/src/telemetry/BrowserPerformanceMeasurement.ts +144 -0
  255. package/src/utils/BrowserConstants.ts +241 -0
  256. package/src/utils/BrowserProtocolUtils.ts +58 -0
  257. package/src/utils/BrowserStringUtils.ts +143 -0
  258. package/src/utils/BrowserUtils.ts +156 -0
  259. package/dist/crypto/GuidGenerator.d.ts +0 -13
  260. package/dist/crypto/GuidGenerator.d.ts.map +0 -1
  261. package/dist/crypto/GuidGenerator.mjs +0 -104
  262. package/dist/crypto/GuidGenerator.mjs.map +0 -1
  263. package/dist/crypto/ISubtleCrypto.d.ts +0 -10
  264. package/dist/crypto/ISubtleCrypto.d.ts.map +0 -1
  265. package/dist/crypto/ModernBrowserCrypto.d.ts +0 -10
  266. package/dist/crypto/ModernBrowserCrypto.d.ts.map +0 -1
  267. package/dist/crypto/ModernBrowserCrypto.mjs +0 -31
  268. package/dist/crypto/ModernBrowserCrypto.mjs.map +0 -1
  269. package/dist/internals.d.ts +0 -23
  270. package/dist/internals.d.ts.map +0 -1
  271. package/dist/internals.mjs +0 -28
  272. package/dist/internals.mjs.map +0 -1
  273. package/dist/network/XhrClient.d.ts +0 -41
  274. package/dist/network/XhrClient.d.ts.map +0 -1
  275. package/dist/network/XhrClient.mjs +0 -125
  276. package/dist/network/XhrClient.mjs.map +0 -1
  277. package/dist/utils/MathUtils.d.ts +0 -12
  278. package/dist/utils/MathUtils.d.ts.map +0 -1
  279. package/dist/utils/MathUtils.mjs +0 -26
  280. package/dist/utils/MathUtils.mjs.map +0 -1
@@ -0,0 +1,118 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { StandardInteractionClient } from "./StandardInteractionClient";
7
+ import {
8
+ CommonSilentFlowRequest,
9
+ ServerTelemetryManager,
10
+ RefreshTokenClient,
11
+ AuthError,
12
+ AzureCloudOptions,
13
+ PerformanceEvents,
14
+ invokeAsync,
15
+ } from "@azure/msal-common";
16
+ import { ApiId } from "../utils/BrowserConstants";
17
+ import {
18
+ createBrowserAuthError,
19
+ BrowserAuthErrorCodes,
20
+ } from "../error/BrowserAuthError";
21
+ import { AuthenticationResult } from "../response/AuthenticationResult";
22
+
23
+ export class SilentRefreshClient extends StandardInteractionClient {
24
+ /**
25
+ * Exchanges the refresh token for new tokens
26
+ * @param request
27
+ */
28
+ async acquireToken(
29
+ request: CommonSilentFlowRequest
30
+ ): Promise<AuthenticationResult> {
31
+ this.performanceClient.addQueueMeasurement(
32
+ PerformanceEvents.SilentRefreshClientAcquireToken,
33
+ request.correlationId
34
+ );
35
+
36
+ const baseRequest = await invokeAsync(
37
+ this.initializeBaseRequest.bind(this),
38
+ PerformanceEvents.InitializeBaseRequest,
39
+ this.logger,
40
+ this.performanceClient,
41
+ request.correlationId
42
+ )(request, request.account);
43
+ const silentRequest: CommonSilentFlowRequest = {
44
+ ...request,
45
+ ...baseRequest,
46
+ };
47
+ const serverTelemetryManager = this.initializeServerTelemetryManager(
48
+ ApiId.acquireTokenSilent_silentFlow
49
+ );
50
+
51
+ const refreshTokenClient = await this.createRefreshTokenClient(
52
+ serverTelemetryManager,
53
+ silentRequest.authority,
54
+ silentRequest.azureCloudOptions
55
+ );
56
+ this.logger.verbose("Refresh token client created");
57
+ // Send request to renew token. Auth module will throw errors if token cannot be renewed.
58
+ return invokeAsync(
59
+ refreshTokenClient.acquireTokenByRefreshToken.bind(
60
+ refreshTokenClient
61
+ ),
62
+ PerformanceEvents.RefreshTokenClientAcquireTokenByRefreshToken,
63
+ this.logger,
64
+ this.performanceClient,
65
+ request.correlationId
66
+ )(silentRequest)
67
+ .then((result) => result as AuthenticationResult)
68
+ .then((result: AuthenticationResult) => {
69
+ this.performanceClient.addFields(
70
+ {
71
+ fromCache: result.fromCache,
72
+ requestId: result.requestId,
73
+ },
74
+ request.correlationId
75
+ );
76
+
77
+ return result;
78
+ })
79
+ .catch((e: AuthError) => {
80
+ (e as AuthError).setCorrelationId(this.correlationId);
81
+ serverTelemetryManager.cacheFailedRequest(e);
82
+ throw e;
83
+ });
84
+ }
85
+
86
+ /**
87
+ * Currently Unsupported
88
+ */
89
+ logout(): Promise<void> {
90
+ // Synchronous so we must reject
91
+ return Promise.reject(
92
+ createBrowserAuthError(
93
+ BrowserAuthErrorCodes.silentLogoutUnsupported
94
+ )
95
+ );
96
+ }
97
+
98
+ /**
99
+ * Creates a Refresh Client with the given authority, or the default authority.
100
+ * @param serverTelemetryManager
101
+ * @param authorityUrl
102
+ */
103
+ protected async createRefreshTokenClient(
104
+ serverTelemetryManager: ServerTelemetryManager,
105
+ authorityUrl?: string,
106
+ azureCloudOptions?: AzureCloudOptions
107
+ ): Promise<RefreshTokenClient> {
108
+ // Create auth module.
109
+ const clientConfig = await invokeAsync(
110
+ this.getClientConfiguration.bind(this),
111
+ PerformanceEvents.StandardInteractionClientGetClientConfiguration,
112
+ this.logger,
113
+ this.performanceClient,
114
+ this.correlationId
115
+ )(serverTelemetryManager, authorityUrl, azureCloudOptions);
116
+ return new RefreshTokenClient(clientConfig, this.performanceClient);
117
+ }
118
+ }
@@ -0,0 +1,450 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ ServerTelemetryManager,
8
+ CommonAuthorizationCodeRequest,
9
+ Constants,
10
+ AuthorizationCodeClient,
11
+ ClientConfiguration,
12
+ AuthorityOptions,
13
+ Authority,
14
+ AuthorityFactory,
15
+ ServerAuthorizationCodeResponse,
16
+ UrlString,
17
+ CommonEndSessionRequest,
18
+ ProtocolUtils,
19
+ ResponseMode,
20
+ IdTokenClaims,
21
+ AccountInfo,
22
+ AzureCloudOptions,
23
+ PerformanceEvents,
24
+ invokeAsync,
25
+ BaseAuthRequest,
26
+ } from "@azure/msal-common";
27
+ import { BaseInteractionClient } from "./BaseInteractionClient";
28
+ import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest";
29
+ import { BrowserConstants, InteractionType } from "../utils/BrowserConstants";
30
+ import { version } from "../packageMetadata";
31
+ import {
32
+ createBrowserAuthError,
33
+ BrowserAuthErrorCodes,
34
+ } from "../error/BrowserAuthError";
35
+ import {
36
+ BrowserProtocolUtils,
37
+ BrowserStateObject,
38
+ } from "../utils/BrowserProtocolUtils";
39
+ import { EndSessionRequest } from "../request/EndSessionRequest";
40
+ import { BrowserUtils } from "../utils/BrowserUtils";
41
+ import { RedirectRequest } from "../request/RedirectRequest";
42
+ import { PopupRequest } from "../request/PopupRequest";
43
+ import { SsoSilentRequest } from "../request/SsoSilentRequest";
44
+ import { generatePkceCodes } from "../crypto/PkceGenerator";
45
+ import { createNewGuid } from "../crypto/BrowserCrypto";
46
+
47
+ /**
48
+ * Defines the class structure and helper functions used by the "standard", non-brokered auth flows (popup, redirect, silent (RT), silent (iframe))
49
+ */
50
+ export abstract class StandardInteractionClient extends BaseInteractionClient {
51
+ /**
52
+ * Generates an auth code request tied to the url request.
53
+ * @param request
54
+ */
55
+ protected async initializeAuthorizationCodeRequest(
56
+ request: AuthorizationUrlRequest
57
+ ): Promise<CommonAuthorizationCodeRequest> {
58
+ this.performanceClient.addQueueMeasurement(
59
+ PerformanceEvents.StandardInteractionClientInitializeAuthorizationCodeRequest,
60
+ request.correlationId
61
+ );
62
+ const generatedPkceParams = await invokeAsync(
63
+ generatePkceCodes,
64
+ PerformanceEvents.GeneratePkceCodes,
65
+ this.logger,
66
+ this.performanceClient,
67
+ this.correlationId
68
+ )(this.performanceClient, this.logger, this.correlationId);
69
+
70
+ const authCodeRequest: CommonAuthorizationCodeRequest = {
71
+ ...request,
72
+ redirectUri: request.redirectUri,
73
+ code: Constants.EMPTY_STRING,
74
+ codeVerifier: generatedPkceParams.verifier,
75
+ };
76
+
77
+ request.codeChallenge = generatedPkceParams.challenge;
78
+ request.codeChallengeMethod = Constants.S256_CODE_CHALLENGE_METHOD;
79
+
80
+ return authCodeRequest;
81
+ }
82
+
83
+ /**
84
+ * Initializer for the logout request.
85
+ * @param logoutRequest
86
+ */
87
+ protected initializeLogoutRequest(
88
+ logoutRequest?: EndSessionRequest
89
+ ): CommonEndSessionRequest {
90
+ this.logger.verbose(
91
+ "initializeLogoutRequest called",
92
+ logoutRequest?.correlationId
93
+ );
94
+
95
+ const validLogoutRequest: CommonEndSessionRequest = {
96
+ correlationId: this.correlationId || createNewGuid(),
97
+ ...logoutRequest,
98
+ };
99
+
100
+ /**
101
+ * Set logout_hint to be login_hint from ID Token Claims if present
102
+ * and logoutHint attribute wasn't manually set in logout request
103
+ */
104
+ if (logoutRequest) {
105
+ // If logoutHint isn't set and an account was passed in, try to extract logoutHint from ID Token Claims
106
+ if (!logoutRequest.logoutHint) {
107
+ if (logoutRequest.account) {
108
+ const logoutHint = this.getLogoutHintFromIdTokenClaims(
109
+ logoutRequest.account
110
+ );
111
+ if (logoutHint) {
112
+ this.logger.verbose(
113
+ "Setting logoutHint to login_hint ID Token Claim value for the account provided"
114
+ );
115
+ validLogoutRequest.logoutHint = logoutHint;
116
+ }
117
+ } else {
118
+ this.logger.verbose(
119
+ "logoutHint was not set and account was not passed into logout request, logoutHint will not be set"
120
+ );
121
+ }
122
+ } else {
123
+ this.logger.verbose(
124
+ "logoutHint has already been set in logoutRequest"
125
+ );
126
+ }
127
+ } else {
128
+ this.logger.verbose(
129
+ "logoutHint will not be set since no logout request was configured"
130
+ );
131
+ }
132
+
133
+ /*
134
+ * Only set redirect uri if logout request isn't provided or the set uri isn't null.
135
+ * Otherwise, use passed uri, config, or current page.
136
+ */
137
+ if (!logoutRequest || logoutRequest.postLogoutRedirectUri !== null) {
138
+ if (logoutRequest && logoutRequest.postLogoutRedirectUri) {
139
+ this.logger.verbose(
140
+ "Setting postLogoutRedirectUri to uri set on logout request",
141
+ validLogoutRequest.correlationId
142
+ );
143
+ validLogoutRequest.postLogoutRedirectUri =
144
+ UrlString.getAbsoluteUrl(
145
+ logoutRequest.postLogoutRedirectUri,
146
+ BrowserUtils.getCurrentUri()
147
+ );
148
+ } else if (this.config.auth.postLogoutRedirectUri === null) {
149
+ this.logger.verbose(
150
+ "postLogoutRedirectUri configured as null and no uri set on request, not passing post logout redirect",
151
+ validLogoutRequest.correlationId
152
+ );
153
+ } else if (this.config.auth.postLogoutRedirectUri) {
154
+ this.logger.verbose(
155
+ "Setting postLogoutRedirectUri to configured uri",
156
+ validLogoutRequest.correlationId
157
+ );
158
+ validLogoutRequest.postLogoutRedirectUri =
159
+ UrlString.getAbsoluteUrl(
160
+ this.config.auth.postLogoutRedirectUri,
161
+ BrowserUtils.getCurrentUri()
162
+ );
163
+ } else {
164
+ this.logger.verbose(
165
+ "Setting postLogoutRedirectUri to current page",
166
+ validLogoutRequest.correlationId
167
+ );
168
+ validLogoutRequest.postLogoutRedirectUri =
169
+ UrlString.getAbsoluteUrl(
170
+ BrowserUtils.getCurrentUri(),
171
+ BrowserUtils.getCurrentUri()
172
+ );
173
+ }
174
+ } else {
175
+ this.logger.verbose(
176
+ "postLogoutRedirectUri passed as null, not setting post logout redirect uri",
177
+ validLogoutRequest.correlationId
178
+ );
179
+ }
180
+
181
+ return validLogoutRequest;
182
+ }
183
+
184
+ /**
185
+ * Parses login_hint ID Token Claim out of AccountInfo object to be used as
186
+ * logout_hint in end session request.
187
+ * @param account
188
+ */
189
+ protected getLogoutHintFromIdTokenClaims(
190
+ account: AccountInfo
191
+ ): string | null {
192
+ const idTokenClaims: IdTokenClaims | undefined = account.idTokenClaims;
193
+ if (idTokenClaims) {
194
+ if (idTokenClaims.login_hint) {
195
+ return idTokenClaims.login_hint;
196
+ } else {
197
+ this.logger.verbose(
198
+ "The ID Token Claims tied to the provided account do not contain a login_hint claim, logoutHint will not be added to logout request"
199
+ );
200
+ }
201
+ } else {
202
+ this.logger.verbose(
203
+ "The provided account does not contain ID Token Claims, logoutHint will not be added to logout request"
204
+ );
205
+ }
206
+
207
+ return null;
208
+ }
209
+
210
+ /**
211
+ * Creates an Authorization Code Client with the given authority, or the default authority.
212
+ * @param serverTelemetryManager
213
+ * @param authorityUrl
214
+ */
215
+ protected async createAuthCodeClient(
216
+ serverTelemetryManager: ServerTelemetryManager,
217
+ authorityUrl?: string,
218
+ requestAzureCloudOptions?: AzureCloudOptions
219
+ ): Promise<AuthorizationCodeClient> {
220
+ this.performanceClient.addQueueMeasurement(
221
+ PerformanceEvents.StandardInteractionClientCreateAuthCodeClient,
222
+ this.correlationId
223
+ );
224
+ // Create auth module.
225
+ const clientConfig = await invokeAsync(
226
+ this.getClientConfiguration.bind(this),
227
+ PerformanceEvents.StandardInteractionClientGetClientConfiguration,
228
+ this.logger,
229
+ this.performanceClient,
230
+ this.correlationId
231
+ )(serverTelemetryManager, authorityUrl, requestAzureCloudOptions);
232
+ return new AuthorizationCodeClient(
233
+ clientConfig,
234
+ this.performanceClient
235
+ );
236
+ }
237
+
238
+ /**
239
+ * Creates a Client Configuration object with the given request authority, or the default authority.
240
+ * @param serverTelemetryManager
241
+ * @param requestAuthority
242
+ * @param requestCorrelationId
243
+ */
244
+ protected async getClientConfiguration(
245
+ serverTelemetryManager: ServerTelemetryManager,
246
+ requestAuthority?: string,
247
+ requestAzureCloudOptions?: AzureCloudOptions
248
+ ): Promise<ClientConfiguration> {
249
+ this.performanceClient.addQueueMeasurement(
250
+ PerformanceEvents.StandardInteractionClientGetClientConfiguration,
251
+ this.correlationId
252
+ );
253
+ const discoveredAuthority = await invokeAsync(
254
+ this.getDiscoveredAuthority.bind(this),
255
+ PerformanceEvents.StandardInteractionClientGetDiscoveredAuthority,
256
+ this.logger,
257
+ this.performanceClient,
258
+ this.correlationId
259
+ )(requestAuthority, requestAzureCloudOptions);
260
+ const logger = this.config.system.loggerOptions;
261
+
262
+ return {
263
+ authOptions: {
264
+ clientId: this.config.auth.clientId,
265
+ authority: discoveredAuthority,
266
+ clientCapabilities: this.config.auth.clientCapabilities,
267
+ },
268
+ systemOptions: {
269
+ tokenRenewalOffsetSeconds:
270
+ this.config.system.tokenRenewalOffsetSeconds,
271
+ preventCorsPreflight: true,
272
+ },
273
+ loggerOptions: {
274
+ loggerCallback: logger.loggerCallback,
275
+ piiLoggingEnabled: logger.piiLoggingEnabled,
276
+ logLevel: logger.logLevel,
277
+ correlationId: this.correlationId,
278
+ },
279
+ cacheOptions: {
280
+ claimsBasedCachingEnabled:
281
+ this.config.cache.claimsBasedCachingEnabled,
282
+ },
283
+ cryptoInterface: this.browserCrypto,
284
+ networkInterface: this.networkClient,
285
+ storageInterface: this.browserStorage,
286
+ serverTelemetryManager: serverTelemetryManager,
287
+ libraryInfo: {
288
+ sku: BrowserConstants.MSAL_SKU,
289
+ version: version,
290
+ cpu: Constants.EMPTY_STRING,
291
+ os: Constants.EMPTY_STRING,
292
+ },
293
+ telemetry: this.config.telemetry,
294
+ };
295
+ }
296
+
297
+ /**
298
+ * @param hash
299
+ * @param interactionType
300
+ */
301
+ protected validateAndExtractStateFromHash(
302
+ serverParams: ServerAuthorizationCodeResponse,
303
+ interactionType: InteractionType,
304
+ requestCorrelationId?: string
305
+ ): string {
306
+ this.logger.verbose(
307
+ "validateAndExtractStateFromHash called",
308
+ requestCorrelationId
309
+ );
310
+ if (!serverParams.state) {
311
+ throw createBrowserAuthError(BrowserAuthErrorCodes.noStateInHash);
312
+ }
313
+
314
+ const platformStateObj =
315
+ BrowserProtocolUtils.extractBrowserRequestState(
316
+ this.browserCrypto,
317
+ serverParams.state
318
+ );
319
+ if (!platformStateObj) {
320
+ throw createBrowserAuthError(
321
+ BrowserAuthErrorCodes.unableToParseState
322
+ );
323
+ }
324
+
325
+ if (platformStateObj.interactionType !== interactionType) {
326
+ throw createBrowserAuthError(
327
+ BrowserAuthErrorCodes.stateInteractionTypeMismatch
328
+ );
329
+ }
330
+
331
+ this.logger.verbose("Returning state from hash", requestCorrelationId);
332
+ return serverParams.state;
333
+ }
334
+
335
+ /**
336
+ * Used to get a discovered version of the default authority.
337
+ * @param requestAuthority
338
+ * @param requestCorrelationId
339
+ */
340
+ protected async getDiscoveredAuthority(
341
+ requestAuthority?: string,
342
+ requestAzureCloudOptions?: AzureCloudOptions
343
+ ): Promise<Authority> {
344
+ this.performanceClient.addQueueMeasurement(
345
+ PerformanceEvents.StandardInteractionClientGetDiscoveredAuthority,
346
+ this.correlationId
347
+ );
348
+ const authorityOptions: AuthorityOptions = {
349
+ protocolMode: this.config.auth.protocolMode,
350
+ OIDCOptions: this.config.auth.OIDCOptions,
351
+ knownAuthorities: this.config.auth.knownAuthorities,
352
+ cloudDiscoveryMetadata: this.config.auth.cloudDiscoveryMetadata,
353
+ authorityMetadata: this.config.auth.authorityMetadata,
354
+ skipAuthorityMetadataCache:
355
+ this.config.auth.skipAuthorityMetadataCache,
356
+ };
357
+
358
+ // build authority string based on auth params, precedence - azureCloudInstance + tenant >> authority
359
+ const userAuthority = requestAuthority
360
+ ? requestAuthority
361
+ : this.config.auth.authority;
362
+
363
+ // fall back to the authority from config
364
+ const builtAuthority = Authority.generateAuthority(
365
+ userAuthority,
366
+ requestAzureCloudOptions || this.config.auth.azureCloudOptions
367
+ );
368
+ return await invokeAsync(
369
+ AuthorityFactory.createDiscoveredInstance.bind(AuthorityFactory),
370
+ PerformanceEvents.AuthorityFactoryCreateDiscoveredInstance,
371
+ this.logger,
372
+ this.performanceClient,
373
+ this.correlationId
374
+ )(
375
+ builtAuthority,
376
+ this.config.system.networkClient,
377
+ this.browserStorage,
378
+ authorityOptions,
379
+ this.logger,
380
+ this.performanceClient,
381
+ this.correlationId
382
+ );
383
+ }
384
+
385
+ /**
386
+ * Helper to initialize required request parameters for interactive APIs and ssoSilent()
387
+ * @param request
388
+ * @param interactionType
389
+ */
390
+ protected async initializeAuthorizationRequest(
391
+ request: RedirectRequest | PopupRequest | SsoSilentRequest,
392
+ interactionType: InteractionType
393
+ ): Promise<AuthorizationUrlRequest> {
394
+ this.performanceClient.addQueueMeasurement(
395
+ PerformanceEvents.StandardInteractionClientInitializeAuthorizationRequest,
396
+ this.correlationId
397
+ );
398
+
399
+ const redirectUri = this.getRedirectUri(request.redirectUri);
400
+ const browserState: BrowserStateObject = {
401
+ interactionType: interactionType,
402
+ };
403
+ const state = ProtocolUtils.setRequestState(
404
+ this.browserCrypto,
405
+ (request && request.state) || Constants.EMPTY_STRING,
406
+ browserState
407
+ );
408
+
409
+ const baseRequest: BaseAuthRequest = await invokeAsync(
410
+ this.initializeBaseRequest.bind(this),
411
+ PerformanceEvents.InitializeBaseRequest,
412
+ this.logger,
413
+ this.performanceClient,
414
+ this.correlationId
415
+ )(request);
416
+
417
+ const validatedRequest: AuthorizationUrlRequest = {
418
+ ...baseRequest,
419
+ redirectUri: redirectUri,
420
+ state: state,
421
+ nonce: request.nonce || createNewGuid(),
422
+ responseMode: this.config.auth.OIDCOptions
423
+ .serverResponseType as ResponseMode,
424
+ };
425
+
426
+ const account =
427
+ request.account || this.browserStorage.getActiveAccount();
428
+ if (account) {
429
+ this.logger.verbose(
430
+ "Setting validated request account",
431
+ this.correlationId
432
+ );
433
+ this.logger.verbosePii(
434
+ `Setting validated request account: ${account.homeAccountId}`,
435
+ this.correlationId
436
+ );
437
+ validatedRequest.account = account;
438
+ }
439
+
440
+ // Check for ADAL/MSAL v1 SSO
441
+ if (!validatedRequest.loginHint && !account) {
442
+ const legacyLoginHint = this.browserStorage.getLegacyLoginHint();
443
+ if (legacyLoginHint) {
444
+ validatedRequest.loginHint = legacyLoginHint;
445
+ }
446
+ }
447
+
448
+ return validatedRequest;
449
+ }
450
+ }