@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,926 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ CommonAuthorizationCodeRequest,
8
+ AuthorizationCodeClient,
9
+ ThrottlingUtils,
10
+ CommonEndSessionRequest,
11
+ UrlString,
12
+ AuthError,
13
+ OIDC_DEFAULT_SCOPES,
14
+ Constants,
15
+ ProtocolUtils,
16
+ ServerAuthorizationCodeResponse,
17
+ PerformanceEvents,
18
+ IPerformanceClient,
19
+ Logger,
20
+ ICrypto,
21
+ ProtocolMode,
22
+ ServerResponseType,
23
+ } from "@azure/msal-common";
24
+ import { StandardInteractionClient } from "./StandardInteractionClient";
25
+ import { EventType } from "../event/EventType";
26
+ import {
27
+ InteractionType,
28
+ ApiId,
29
+ BrowserConstants,
30
+ } from "../utils/BrowserConstants";
31
+ import { EndSessionPopupRequest } from "../request/EndSessionPopupRequest";
32
+ import { NavigationOptions } from "../navigation/NavigationOptions";
33
+ import { BrowserUtils } from "../utils/BrowserUtils";
34
+ import { PopupRequest } from "../request/PopupRequest";
35
+ import { NativeInteractionClient } from "./NativeInteractionClient";
36
+ import { NativeMessageHandler } from "../broker/nativeBroker/NativeMessageHandler";
37
+ import {
38
+ createBrowserAuthError,
39
+ BrowserAuthErrorCodes,
40
+ } from "../error/BrowserAuthError";
41
+ import { INavigationClient } from "../navigation/INavigationClient";
42
+ import { EventHandler } from "../event/EventHandler";
43
+ import { BrowserCacheManager } from "../cache/BrowserCacheManager";
44
+ import { BrowserConfiguration } from "../config/Configuration";
45
+ import {
46
+ InteractionHandler,
47
+ InteractionParams,
48
+ } from "../interaction_handler/InteractionHandler";
49
+ import { PopupWindowAttributes } from "../request/PopupWindowAttributes";
50
+ import { EventError } from "../event/EventMessage";
51
+ import { AuthenticationResult } from "../response/AuthenticationResult";
52
+
53
+ export type PopupParams = InteractionParams & {
54
+ popup?: Window | null;
55
+ popupName: string;
56
+ popupWindowAttributes: PopupWindowAttributes;
57
+ };
58
+
59
+ export class PopupClient extends StandardInteractionClient {
60
+ private currentWindow: Window | undefined;
61
+ protected nativeStorage: BrowserCacheManager;
62
+
63
+ constructor(
64
+ config: BrowserConfiguration,
65
+ storageImpl: BrowserCacheManager,
66
+ browserCrypto: ICrypto,
67
+ logger: Logger,
68
+ eventHandler: EventHandler,
69
+ navigationClient: INavigationClient,
70
+ performanceClient: IPerformanceClient,
71
+ nativeStorageImpl: BrowserCacheManager,
72
+ nativeMessageHandler?: NativeMessageHandler,
73
+ correlationId?: string
74
+ ) {
75
+ super(
76
+ config,
77
+ storageImpl,
78
+ browserCrypto,
79
+ logger,
80
+ eventHandler,
81
+ navigationClient,
82
+ performanceClient,
83
+ nativeMessageHandler,
84
+ correlationId
85
+ );
86
+ // Properly sets this reference for the unload event.
87
+ this.unloadWindow = this.unloadWindow.bind(this);
88
+ this.nativeStorage = nativeStorageImpl;
89
+ }
90
+
91
+ /**
92
+ * Acquires tokens by opening a popup window to the /authorize endpoint of the authority
93
+ * @param request
94
+ */
95
+ acquireToken(request: PopupRequest): Promise<AuthenticationResult> {
96
+ try {
97
+ const popupName = this.generatePopupName(
98
+ request.scopes || OIDC_DEFAULT_SCOPES,
99
+ request.authority || this.config.auth.authority
100
+ );
101
+ const popupWindowAttributes = request.popupWindowAttributes || {};
102
+
103
+ // asyncPopups flag is true. Acquires token without first opening popup. Popup will be opened later asynchronously.
104
+ if (this.config.system.asyncPopups) {
105
+ this.logger.verbose("asyncPopups set to true, acquiring token");
106
+ // Passes on popup position and dimensions if in request
107
+ return this.acquireTokenPopupAsync(
108
+ request,
109
+ popupName,
110
+ popupWindowAttributes
111
+ );
112
+ } else {
113
+ // asyncPopups flag is set to false. Opens popup before acquiring token.
114
+ this.logger.verbose(
115
+ "asyncPopup set to false, opening popup before acquiring token"
116
+ );
117
+ const popup = this.openSizedPopup(
118
+ "about:blank",
119
+ popupName,
120
+ popupWindowAttributes
121
+ );
122
+ return this.acquireTokenPopupAsync(
123
+ request,
124
+ popupName,
125
+ popupWindowAttributes,
126
+ popup
127
+ );
128
+ }
129
+ } catch (e) {
130
+ return Promise.reject(e);
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Clears local cache for the current user then opens a popup window prompting the user to sign-out of the server
136
+ * @param logoutRequest
137
+ */
138
+ logout(logoutRequest?: EndSessionPopupRequest): Promise<void> {
139
+ try {
140
+ this.logger.verbose("logoutPopup called");
141
+ const validLogoutRequest =
142
+ this.initializeLogoutRequest(logoutRequest);
143
+
144
+ const popupName = this.generateLogoutPopupName(validLogoutRequest);
145
+ const authority = logoutRequest && logoutRequest.authority;
146
+ const mainWindowRedirectUri =
147
+ logoutRequest && logoutRequest.mainWindowRedirectUri;
148
+ const popupWindowAttributes =
149
+ logoutRequest?.popupWindowAttributes || {};
150
+
151
+ // asyncPopups flag is true. Acquires token without first opening popup. Popup will be opened later asynchronously.
152
+ if (this.config.system.asyncPopups) {
153
+ this.logger.verbose("asyncPopups set to true");
154
+ // Passes on popup position and dimensions if in request
155
+ return this.logoutPopupAsync(
156
+ validLogoutRequest,
157
+ popupName,
158
+ popupWindowAttributes,
159
+ authority,
160
+ undefined,
161
+ mainWindowRedirectUri
162
+ );
163
+ } else {
164
+ // asyncPopups flag is set to false. Opens popup before logging out.
165
+ this.logger.verbose("asyncPopup set to false, opening popup");
166
+ const popup = this.openSizedPopup(
167
+ "about:blank",
168
+ popupName,
169
+ popupWindowAttributes
170
+ );
171
+ return this.logoutPopupAsync(
172
+ validLogoutRequest,
173
+ popupName,
174
+ popupWindowAttributes,
175
+ authority,
176
+ popup,
177
+ mainWindowRedirectUri
178
+ );
179
+ }
180
+ } catch (e) {
181
+ // Since this function is synchronous we need to reject
182
+ return Promise.reject(e);
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Helper which obtains an access_token for your API via opening a popup window in the user's browser
188
+ * @param validRequest
189
+ * @param popupName
190
+ * @param popup
191
+ * @param popupWindowAttributes
192
+ *
193
+ * @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
194
+ */
195
+ protected async acquireTokenPopupAsync(
196
+ request: PopupRequest,
197
+ popupName: string,
198
+ popupWindowAttributes: PopupWindowAttributes,
199
+ popup?: Window | null
200
+ ): Promise<AuthenticationResult> {
201
+ this.logger.verbose("acquireTokenPopupAsync called");
202
+ const serverTelemetryManager = this.initializeServerTelemetryManager(
203
+ ApiId.acquireTokenPopup
204
+ );
205
+
206
+ this.performanceClient.setPreQueueTime(
207
+ PerformanceEvents.StandardInteractionClientInitializeAuthorizationRequest,
208
+ request.correlationId
209
+ );
210
+ const validRequest = await this.initializeAuthorizationRequest(
211
+ request,
212
+ InteractionType.Popup
213
+ );
214
+ this.browserStorage.updateCacheEntries(
215
+ validRequest.state,
216
+ validRequest.nonce,
217
+ validRequest.authority,
218
+ validRequest.loginHint || Constants.EMPTY_STRING,
219
+ validRequest.account || null
220
+ );
221
+
222
+ try {
223
+ // Create auth code request and generate PKCE params
224
+ this.performanceClient.setPreQueueTime(
225
+ PerformanceEvents.StandardInteractionClientInitializeAuthorizationCodeRequest,
226
+ request.correlationId
227
+ );
228
+ const authCodeRequest: CommonAuthorizationCodeRequest =
229
+ await this.initializeAuthorizationCodeRequest(validRequest);
230
+
231
+ // Initialize the client
232
+ this.performanceClient.setPreQueueTime(
233
+ PerformanceEvents.StandardInteractionClientCreateAuthCodeClient,
234
+ request.correlationId
235
+ );
236
+ const authClient: AuthorizationCodeClient =
237
+ await this.createAuthCodeClient(
238
+ serverTelemetryManager,
239
+ validRequest.authority,
240
+ validRequest.azureCloudOptions
241
+ );
242
+ this.logger.verbose("Auth code client created");
243
+
244
+ const isNativeBroker = NativeMessageHandler.isNativeAvailable(
245
+ this.config,
246
+ this.logger,
247
+ this.nativeMessageHandler,
248
+ request.authenticationScheme
249
+ );
250
+ // Start measurement for server calls with native brokering enabled
251
+ let fetchNativeAccountIdMeasurement;
252
+ if (isNativeBroker) {
253
+ fetchNativeAccountIdMeasurement =
254
+ this.performanceClient.startMeasurement(
255
+ PerformanceEvents.FetchAccountIdWithNativeBroker,
256
+ request.correlationId
257
+ );
258
+ }
259
+
260
+ // Create acquire token url.
261
+ const navigateUrl = await authClient.getAuthCodeUrl({
262
+ ...validRequest,
263
+ nativeBroker: isNativeBroker,
264
+ });
265
+
266
+ // Create popup interaction handler.
267
+ const interactionHandler = new InteractionHandler(
268
+ authClient,
269
+ this.browserStorage,
270
+ authCodeRequest,
271
+ this.logger,
272
+ this.performanceClient
273
+ );
274
+
275
+ // Show the UI once the url has been created. Get the window handle for the popup.
276
+ const popupParameters: PopupParams = {
277
+ popup,
278
+ popupName,
279
+ popupWindowAttributes,
280
+ };
281
+ const popupWindow: Window = this.initiateAuthRequest(
282
+ navigateUrl,
283
+ popupParameters
284
+ );
285
+ this.eventHandler.emitEvent(
286
+ EventType.POPUP_OPENED,
287
+ InteractionType.Popup,
288
+ { popupWindow },
289
+ null
290
+ );
291
+
292
+ // Monitor the window for the hash. Return the string value and close the popup when the hash is received. Default timeout is 60 seconds.
293
+ const hash = await this.monitorPopupForHash(popupWindow);
294
+ // Deserialize hash fragment response parameters.
295
+ const serverParams: ServerAuthorizationCodeResponse =
296
+ UrlString.getDeserializedHash(hash);
297
+ const state = this.validateAndExtractStateFromHash(
298
+ serverParams,
299
+ InteractionType.Popup,
300
+ validRequest.correlationId
301
+ );
302
+ // Remove throttle if it exists
303
+ ThrottlingUtils.removeThrottle(
304
+ this.browserStorage,
305
+ this.config.auth.clientId,
306
+ authCodeRequest
307
+ );
308
+
309
+ if (serverParams.accountId) {
310
+ this.logger.verbose(
311
+ "Account id found in hash, calling WAM for token"
312
+ );
313
+ // end measurement for server call with native brokering enabled
314
+ if (fetchNativeAccountIdMeasurement) {
315
+ fetchNativeAccountIdMeasurement.end({
316
+ success: true,
317
+ isNativeBroker: true,
318
+ });
319
+ }
320
+
321
+ if (!this.nativeMessageHandler) {
322
+ throw createBrowserAuthError(
323
+ BrowserAuthErrorCodes.nativeConnectionNotEstablished
324
+ );
325
+ }
326
+ const nativeInteractionClient = new NativeInteractionClient(
327
+ this.config,
328
+ this.browserStorage,
329
+ this.browserCrypto,
330
+ this.logger,
331
+ this.eventHandler,
332
+ this.navigationClient,
333
+ ApiId.acquireTokenPopup,
334
+ this.performanceClient,
335
+ this.nativeMessageHandler,
336
+ serverParams.accountId,
337
+ this.nativeStorage,
338
+ validRequest.correlationId
339
+ );
340
+ const { userRequestState } = ProtocolUtils.parseRequestState(
341
+ this.browserCrypto,
342
+ state
343
+ );
344
+ return nativeInteractionClient
345
+ .acquireToken({
346
+ ...validRequest,
347
+ state: userRequestState,
348
+ prompt: undefined, // Server should handle the prompt, ideally native broker can do this part silently
349
+ })
350
+ .finally(() => {
351
+ this.browserStorage.cleanRequestByState(state);
352
+ });
353
+ }
354
+
355
+ // Handle response from hash string.
356
+ const result = await interactionHandler.handleCodeResponseFromHash(
357
+ hash,
358
+ state,
359
+ authClient.authority,
360
+ this.networkClient
361
+ );
362
+
363
+ return result;
364
+ } catch (e) {
365
+ if (popup) {
366
+ // Close the synchronous popup if an error is thrown before the window unload event is registered
367
+ popup.close();
368
+ }
369
+
370
+ if (e instanceof AuthError) {
371
+ (e as AuthError).setCorrelationId(this.correlationId);
372
+ serverTelemetryManager.cacheFailedRequest(e);
373
+ }
374
+ this.browserStorage.cleanRequestByState(validRequest.state);
375
+ throw e;
376
+ }
377
+ }
378
+
379
+ /**
380
+ *
381
+ * @param validRequest
382
+ * @param popupName
383
+ * @param requestAuthority
384
+ * @param popup
385
+ * @param mainWindowRedirectUri
386
+ * @param popupWindowAttributes
387
+ */
388
+ protected async logoutPopupAsync(
389
+ validRequest: CommonEndSessionRequest,
390
+ popupName: string,
391
+ popupWindowAttributes: PopupWindowAttributes,
392
+ requestAuthority?: string,
393
+ popup?: Window | null,
394
+ mainWindowRedirectUri?: string
395
+ ): Promise<void> {
396
+ this.logger.verbose("logoutPopupAsync called");
397
+ this.eventHandler.emitEvent(
398
+ EventType.LOGOUT_START,
399
+ InteractionType.Popup,
400
+ validRequest
401
+ );
402
+
403
+ const serverTelemetryManager = this.initializeServerTelemetryManager(
404
+ ApiId.logoutPopup
405
+ );
406
+
407
+ try {
408
+ // Clear cache on logout
409
+ await this.clearCacheOnLogout(validRequest.account);
410
+
411
+ // Initialize the client
412
+ this.performanceClient.setPreQueueTime(
413
+ PerformanceEvents.StandardInteractionClientCreateAuthCodeClient,
414
+ validRequest.correlationId
415
+ );
416
+ const authClient = await this.createAuthCodeClient(
417
+ serverTelemetryManager,
418
+ requestAuthority
419
+ );
420
+ this.logger.verbose("Auth code client created");
421
+
422
+ try {
423
+ authClient.authority.endSessionEndpoint;
424
+ } catch {
425
+ if (
426
+ validRequest.account?.homeAccountId &&
427
+ validRequest.postLogoutRedirectUri &&
428
+ authClient.authority.protocolMode === ProtocolMode.OIDC
429
+ ) {
430
+ void this.browserStorage.removeAccount(
431
+ validRequest.account?.homeAccountId
432
+ );
433
+
434
+ this.eventHandler.emitEvent(
435
+ EventType.LOGOUT_SUCCESS,
436
+ InteractionType.Popup,
437
+ validRequest
438
+ );
439
+
440
+ if (mainWindowRedirectUri) {
441
+ const navigationOptions: NavigationOptions = {
442
+ apiId: ApiId.logoutPopup,
443
+ timeout:
444
+ this.config.system.redirectNavigationTimeout,
445
+ noHistory: false,
446
+ };
447
+ const absoluteUrl = UrlString.getAbsoluteUrl(
448
+ mainWindowRedirectUri,
449
+ BrowserUtils.getCurrentUri()
450
+ );
451
+ await this.navigationClient.navigateInternal(
452
+ absoluteUrl,
453
+ navigationOptions
454
+ );
455
+ }
456
+
457
+ if (popup) {
458
+ popup.close();
459
+ }
460
+
461
+ return;
462
+ }
463
+ }
464
+
465
+ // Create logout string and navigate user window to logout.
466
+ const logoutUri: string = authClient.getLogoutUri(validRequest);
467
+
468
+ this.eventHandler.emitEvent(
469
+ EventType.LOGOUT_SUCCESS,
470
+ InteractionType.Popup,
471
+ validRequest
472
+ );
473
+
474
+ // Open the popup window to requestUrl.
475
+ const popupWindow = this.openPopup(logoutUri, {
476
+ popupName,
477
+ popupWindowAttributes,
478
+ popup,
479
+ });
480
+ this.eventHandler.emitEvent(
481
+ EventType.POPUP_OPENED,
482
+ InteractionType.Popup,
483
+ { popupWindow },
484
+ null
485
+ );
486
+
487
+ await this.waitForLogoutPopup(popupWindow);
488
+
489
+ if (mainWindowRedirectUri) {
490
+ const navigationOptions: NavigationOptions = {
491
+ apiId: ApiId.logoutPopup,
492
+ timeout: this.config.system.redirectNavigationTimeout,
493
+ noHistory: false,
494
+ };
495
+ const absoluteUrl = UrlString.getAbsoluteUrl(
496
+ mainWindowRedirectUri,
497
+ BrowserUtils.getCurrentUri()
498
+ );
499
+
500
+ this.logger.verbose(
501
+ "Redirecting main window to url specified in the request"
502
+ );
503
+ this.logger.verbosePii(
504
+ `Redirecting main window to: ${absoluteUrl}`
505
+ );
506
+ await this.navigationClient.navigateInternal(
507
+ absoluteUrl,
508
+ navigationOptions
509
+ );
510
+ } else {
511
+ this.logger.verbose("No main window navigation requested");
512
+ }
513
+ } catch (e) {
514
+ if (popup) {
515
+ // Close the synchronous popup if an error is thrown before the window unload event is registered
516
+ popup.close();
517
+ }
518
+
519
+ if (e instanceof AuthError) {
520
+ (e as AuthError).setCorrelationId(this.correlationId);
521
+ serverTelemetryManager.cacheFailedRequest(e);
522
+ }
523
+ this.browserStorage.setInteractionInProgress(false);
524
+ this.eventHandler.emitEvent(
525
+ EventType.LOGOUT_FAILURE,
526
+ InteractionType.Popup,
527
+ null,
528
+ e as EventError
529
+ );
530
+ this.eventHandler.emitEvent(
531
+ EventType.LOGOUT_END,
532
+ InteractionType.Popup
533
+ );
534
+ throw e;
535
+ }
536
+
537
+ this.eventHandler.emitEvent(
538
+ EventType.LOGOUT_END,
539
+ InteractionType.Popup
540
+ );
541
+ }
542
+
543
+ /**
544
+ * Opens a popup window with given request Url.
545
+ * @param requestUrl
546
+ */
547
+ initiateAuthRequest(requestUrl: string, params: PopupParams): Window {
548
+ // Check that request url is not empty.
549
+ if (requestUrl) {
550
+ this.logger.infoPii(`Navigate to: ${requestUrl}`);
551
+ // Open the popup window to requestUrl.
552
+ return this.openPopup(requestUrl, params);
553
+ } else {
554
+ // Throw error if request URL is empty.
555
+ this.logger.error("Navigate url is empty");
556
+ throw createBrowserAuthError(
557
+ BrowserAuthErrorCodes.emptyNavigateUri
558
+ );
559
+ }
560
+ }
561
+
562
+ /**
563
+ * Monitors a window until it loads a url with the same origin.
564
+ * @param popupWindow - window that is being monitored
565
+ * @param timeout - timeout for processing hash once popup is redirected back to application
566
+ */
567
+ monitorPopupForHash(popupWindow: Window): Promise<string> {
568
+ return new Promise((resolve, reject) => {
569
+ /*
570
+ * Polling for popups needs to be tick-based,
571
+ * since a non-trivial amount of time can be spent on interaction (which should not count against the timeout).
572
+ */
573
+ const maxTicks =
574
+ this.config.system.windowHashTimeout /
575
+ this.config.system.pollIntervalMilliseconds;
576
+ let ticks = 0;
577
+
578
+ this.logger.verbose(
579
+ "PopupHandler.monitorPopupForHash - polling started"
580
+ );
581
+
582
+ const intervalId = setInterval(() => {
583
+ // Window is closed
584
+ if (popupWindow.closed) {
585
+ this.logger.error(
586
+ "PopupHandler.monitorPopupForHash - window closed"
587
+ );
588
+ this.cleanPopup();
589
+ clearInterval(intervalId);
590
+ reject(
591
+ createBrowserAuthError(
592
+ BrowserAuthErrorCodes.userCancelled
593
+ )
594
+ );
595
+ return;
596
+ }
597
+
598
+ let href = Constants.EMPTY_STRING;
599
+ let serverResponseString = Constants.EMPTY_STRING;
600
+ try {
601
+ /*
602
+ * Will throw if cross origin,
603
+ * which should be caught and ignored
604
+ * since we need the interval to keep running while on STS UI.
605
+ */
606
+ href = popupWindow.location.href;
607
+ serverResponseString =
608
+ this.extractServerResponseStringFromPopup(
609
+ popupWindow,
610
+ href
611
+ );
612
+ } catch (e) {}
613
+
614
+ // Don't process blank pages or cross domain
615
+ if (!href || href === "about:blank") {
616
+ return;
617
+ }
618
+
619
+ this.logger.verbose(
620
+ "PopupHandler.monitorPopupForHash - popup window is on same origin as caller"
621
+ );
622
+
623
+ /*
624
+ * Only run clock when we are on same domain for popups
625
+ * as popup operations can take a long time.
626
+ */
627
+ ticks++;
628
+
629
+ if (serverResponseString) {
630
+ this.logger.verbose(
631
+ "PopupHandler.monitorPopupForHash - found hash in url"
632
+ );
633
+ clearInterval(intervalId);
634
+ this.cleanPopup(popupWindow);
635
+
636
+ if (
637
+ UrlString.hashContainsKnownProperties(
638
+ serverResponseString
639
+ )
640
+ ) {
641
+ this.logger.verbose(
642
+ "PopupHandler.monitorPopupForHash - hash contains known properties, returning."
643
+ );
644
+ resolve(serverResponseString);
645
+ } else {
646
+ this.logger.error(
647
+ "PopupHandler.monitorPopupForHash - found hash in url but it does not contain known properties. Check that your router is not changing the hash prematurely."
648
+ );
649
+ this.logger.errorPii(
650
+ `PopupHandler.monitorPopupForHash - hash found: ${serverResponseString}`
651
+ );
652
+ reject(
653
+ createBrowserAuthError(
654
+ BrowserAuthErrorCodes.hashDoesNotContainKnownProperties
655
+ )
656
+ );
657
+ }
658
+ } else if (ticks > maxTicks) {
659
+ this.logger.error(
660
+ "PopupHandler.monitorPopupForHash - unable to find hash in url, timing out"
661
+ );
662
+ clearInterval(intervalId);
663
+ reject(
664
+ createBrowserAuthError(
665
+ BrowserAuthErrorCodes.monitorPopupTimeout
666
+ )
667
+ );
668
+ }
669
+ }, this.config.system.pollIntervalMilliseconds);
670
+ });
671
+ }
672
+
673
+ /**
674
+ * Waits for user interaction in logout popup window
675
+ * @param popupWindow
676
+ * @returns
677
+ */
678
+ waitForLogoutPopup(popupWindow: Window): Promise<void> {
679
+ return new Promise((resolve) => {
680
+ this.logger.verbose(
681
+ "PopupHandler.waitForLogoutPopup - polling started"
682
+ );
683
+
684
+ const intervalId = setInterval(() => {
685
+ // Window is closed
686
+ if (popupWindow.closed) {
687
+ this.logger.error(
688
+ "PopupHandler.waitForLogoutPopup - window closed"
689
+ );
690
+ this.cleanPopup();
691
+ clearInterval(intervalId);
692
+ resolve();
693
+ }
694
+
695
+ let href: string = Constants.EMPTY_STRING;
696
+ try {
697
+ /*
698
+ * Will throw if cross origin,
699
+ * which should be caught and ignored
700
+ * since we need the interval to keep running while on STS UI.
701
+ */
702
+ href = popupWindow.location.href;
703
+ } catch (e) {}
704
+
705
+ // Don't process blank pages or cross domain
706
+ if (!href || href === "about:blank") {
707
+ return;
708
+ }
709
+
710
+ this.logger.verbose(
711
+ "PopupHandler.waitForLogoutPopup - popup window is on same origin as caller, closing."
712
+ );
713
+
714
+ clearInterval(intervalId);
715
+ this.cleanPopup(popupWindow);
716
+ resolve();
717
+ }, this.config.system.pollIntervalMilliseconds);
718
+ });
719
+ }
720
+
721
+ /**
722
+ * @hidden
723
+ *
724
+ * Configures popup window for login.
725
+ *
726
+ * @param urlNavigate
727
+ * @param title
728
+ * @param popUpWidth
729
+ * @param popUpHeight
730
+ * @param popupWindowAttributes
731
+ * @ignore
732
+ * @hidden
733
+ */
734
+ openPopup(urlNavigate: string, popupParams: PopupParams): Window {
735
+ try {
736
+ let popupWindow;
737
+ // Popup window passed in, setting url to navigate to
738
+ if (popupParams.popup) {
739
+ popupWindow = popupParams.popup;
740
+ this.logger.verbosePii(
741
+ `Navigating popup window to: ${urlNavigate}`
742
+ );
743
+ popupWindow.location.assign(urlNavigate);
744
+ } else if (typeof popupParams.popup === "undefined") {
745
+ // Popup will be undefined if it was not passed in
746
+ this.logger.verbosePii(
747
+ `Opening popup window to: ${urlNavigate}`
748
+ );
749
+ popupWindow = this.openSizedPopup(
750
+ urlNavigate,
751
+ popupParams.popupName,
752
+ popupParams.popupWindowAttributes
753
+ );
754
+ }
755
+
756
+ // Popup will be null if popups are blocked
757
+ if (!popupWindow) {
758
+ throw createBrowserAuthError(
759
+ BrowserAuthErrorCodes.emptyWindowError
760
+ );
761
+ }
762
+ if (popupWindow.focus) {
763
+ popupWindow.focus();
764
+ }
765
+ this.currentWindow = popupWindow;
766
+ window.addEventListener("beforeunload", this.unloadWindow);
767
+
768
+ return popupWindow;
769
+ } catch (e) {
770
+ this.logger.error(
771
+ "error opening popup " + (e as AuthError).message
772
+ );
773
+ this.browserStorage.setInteractionInProgress(false);
774
+ throw createBrowserAuthError(
775
+ BrowserAuthErrorCodes.popupWindowError
776
+ );
777
+ }
778
+ }
779
+
780
+ /**
781
+ * Helper function to set popup window dimensions and position
782
+ * @param urlNavigate
783
+ * @param popupName
784
+ * @param popupWindowAttributes
785
+ * @returns
786
+ */
787
+ openSizedPopup(
788
+ urlNavigate: string,
789
+ popupName: string,
790
+ popupWindowAttributes: PopupWindowAttributes
791
+ ): Window | null {
792
+ /**
793
+ * adding winLeft and winTop to account for dual monitor
794
+ * using screenLeft and screenTop for IE8 and earlier
795
+ */
796
+ const winLeft = window.screenLeft ? window.screenLeft : window.screenX;
797
+ const winTop = window.screenTop ? window.screenTop : window.screenY;
798
+ /**
799
+ * window.innerWidth displays browser window"s height and width excluding toolbars
800
+ * using document.documentElement.clientWidth for IE8 and earlier
801
+ */
802
+ const winWidth =
803
+ window.innerWidth ||
804
+ document.documentElement.clientWidth ||
805
+ document.body.clientWidth;
806
+ const winHeight =
807
+ window.innerHeight ||
808
+ document.documentElement.clientHeight ||
809
+ document.body.clientHeight;
810
+
811
+ let width = popupWindowAttributes.popupSize?.width;
812
+ let height = popupWindowAttributes.popupSize?.height;
813
+ let top = popupWindowAttributes.popupPosition?.top;
814
+ let left = popupWindowAttributes.popupPosition?.left;
815
+
816
+ if (!width || width < 0 || width > winWidth) {
817
+ this.logger.verbose(
818
+ "Default popup window width used. Window width not configured or invalid."
819
+ );
820
+ width = BrowserConstants.POPUP_WIDTH;
821
+ }
822
+
823
+ if (!height || height < 0 || height > winHeight) {
824
+ this.logger.verbose(
825
+ "Default popup window height used. Window height not configured or invalid."
826
+ );
827
+ height = BrowserConstants.POPUP_HEIGHT;
828
+ }
829
+
830
+ if (!top || top < 0 || top > winHeight) {
831
+ this.logger.verbose(
832
+ "Default popup window top position used. Window top not configured or invalid."
833
+ );
834
+ top = Math.max(
835
+ 0,
836
+ winHeight / 2 - BrowserConstants.POPUP_HEIGHT / 2 + winTop
837
+ );
838
+ }
839
+
840
+ if (!left || left < 0 || left > winWidth) {
841
+ this.logger.verbose(
842
+ "Default popup window left position used. Window left not configured or invalid."
843
+ );
844
+ left = Math.max(
845
+ 0,
846
+ winWidth / 2 - BrowserConstants.POPUP_WIDTH / 2 + winLeft
847
+ );
848
+ }
849
+
850
+ return window.open(
851
+ urlNavigate,
852
+ popupName,
853
+ `width=${width}, height=${height}, top=${top}, left=${left}, scrollbars=yes`
854
+ );
855
+ }
856
+
857
+ /**
858
+ * Event callback to unload main window.
859
+ */
860
+ unloadWindow(e: Event): void {
861
+ this.browserStorage.cleanRequestByInteractionType(
862
+ InteractionType.Popup
863
+ );
864
+ if (this.currentWindow) {
865
+ this.currentWindow.close();
866
+ }
867
+ // Guarantees browser unload will happen, so no other errors will be thrown.
868
+ e.preventDefault();
869
+ }
870
+
871
+ /**
872
+ * Closes popup, removes any state vars created during popup calls.
873
+ * @param popupWindow
874
+ */
875
+ cleanPopup(popupWindow?: Window): void {
876
+ if (popupWindow) {
877
+ // Close window.
878
+ popupWindow.close();
879
+ }
880
+ // Remove window unload function
881
+ window.removeEventListener("beforeunload", this.unloadWindow);
882
+
883
+ // Interaction is completed - remove interaction status.
884
+ this.browserStorage.setInteractionInProgress(false);
885
+ }
886
+
887
+ /**
888
+ * Generates the name for the popup based on the client id and request
889
+ * @param clientId
890
+ * @param request
891
+ */
892
+ generatePopupName(scopes: Array<string>, authority: string): string {
893
+ return `${BrowserConstants.POPUP_NAME_PREFIX}.${
894
+ this.config.auth.clientId
895
+ }.${scopes.join("-")}.${authority}.${this.correlationId}`;
896
+ }
897
+
898
+ /**
899
+ * Generates the name for the popup based on the client id and request for logouts
900
+ * @param clientId
901
+ * @param request
902
+ */
903
+ generateLogoutPopupName(request: CommonEndSessionRequest): string {
904
+ const homeAccountId = request.account && request.account.homeAccountId;
905
+ return `${BrowserConstants.POPUP_NAME_PREFIX}.${this.config.auth.clientId}.${homeAccountId}.${this.correlationId}`;
906
+ }
907
+
908
+ /**
909
+ * Extracts the server response from the popup window
910
+ */
911
+ extractServerResponseStringFromPopup(
912
+ popupWindow: Window,
913
+ href: string
914
+ ): string {
915
+ let serverResponseString;
916
+ if (
917
+ this.config.auth.OIDCOptions?.serverResponseType ===
918
+ ServerResponseType.QUERY
919
+ ) {
920
+ serverResponseString = UrlString.parseQueryServerResponse(href);
921
+ } else {
922
+ serverResponseString = popupWindow.location.hash;
923
+ }
924
+ return serverResponseString;
925
+ }
926
+ }