@azure/msal-browser 3.19.1 → 3.21.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.
- package/dist/app/IPublicClientApplication.d.ts +53 -53
- package/dist/app/IPublicClientApplication.mjs +105 -105
- package/dist/app/PublicClientApplication.d.ts +293 -293
- package/dist/app/PublicClientApplication.mjs +364 -364
- package/dist/app/PublicClientNext.d.ts +276 -276
- package/dist/app/PublicClientNext.mjs +354 -354
- package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +62 -62
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs +254 -254
- package/dist/broker/nativeBroker/NativeRequest.d.ts +45 -45
- package/dist/broker/nativeBroker/NativeResponse.d.ts +48 -48
- package/dist/broker/nativeBroker/NativeStatusCodes.d.ts +7 -7
- package/dist/broker/nativeBroker/NativeStatusCodes.mjs +11 -11
- package/dist/cache/AccountManager.d.ts +48 -48
- package/dist/cache/AccountManager.mjs +126 -126
- package/dist/cache/AsyncMemoryStorage.d.ts +50 -50
- package/dist/cache/AsyncMemoryStorage.mjs +131 -131
- package/dist/cache/BrowserCacheManager.d.ts +410 -385
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +1364 -1294
- package/dist/cache/BrowserCacheManager.mjs.map +1 -1
- package/dist/cache/BrowserStorage.d.ts +11 -11
- package/dist/cache/BrowserStorage.mjs +32 -32
- package/dist/cache/DatabaseStorage.d.ts +56 -56
- package/dist/cache/DatabaseStorage.mjs +200 -200
- package/dist/cache/IAsyncStorage.d.ts +27 -27
- package/dist/cache/ITokenCache.d.ts +11 -11
- package/dist/cache/IWindowStorage.d.ts +27 -27
- package/dist/cache/MemoryStorage.d.ts +11 -11
- package/dist/cache/MemoryStorage.mjs +31 -31
- package/dist/cache/TokenCache.d.ts +77 -77
- package/dist/cache/TokenCache.mjs +195 -195
- package/dist/config/Configuration.d.ts +213 -208
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +128 -128
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/controllers/ControllerFactory.d.ts +5 -5
- package/dist/controllers/ControllerFactory.mjs +25 -25
- package/dist/controllers/IController.d.ts +60 -60
- package/dist/controllers/NestedAppAuthController.d.ts +202 -202
- package/dist/controllers/NestedAppAuthController.mjs +473 -473
- package/dist/controllers/StandardController.d.ts +405 -405
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +1334 -1316
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/controllers/UnknownOperatingContextController.d.ts +86 -86
- package/dist/controllers/UnknownOperatingContextController.mjs +256 -256
- package/dist/crypto/BrowserCrypto.d.ts +52 -52
- package/dist/crypto/BrowserCrypto.mjs +151 -151
- package/dist/crypto/CryptoOps.d.ts +74 -74
- package/dist/crypto/CryptoOps.mjs +176 -176
- package/dist/crypto/PkceGenerator.d.ts +8 -8
- package/dist/crypto/PkceGenerator.mjs +54 -54
- package/dist/crypto/SignedHttpRequest.d.ts +30 -30
- package/dist/crypto/SignedHttpRequest.mjs +39 -39
- package/dist/encode/Base64Decode.d.ts +9 -9
- package/dist/encode/Base64Decode.mjs +36 -36
- package/dist/encode/Base64Encode.d.ts +19 -19
- package/dist/encode/Base64Encode.mjs +43 -43
- package/dist/error/BrowserAuthError.d.ts +256 -255
- package/dist/error/BrowserAuthError.d.ts.map +1 -1
- package/dist/error/BrowserAuthError.mjs +265 -264
- package/dist/error/BrowserAuthError.mjs.map +1 -1
- package/dist/error/BrowserAuthErrorCodes.d.ts +47 -46
- package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -1
- package/dist/error/BrowserAuthErrorCodes.mjs +53 -52
- package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -1
- package/dist/error/BrowserConfigurationAuthError.d.ts +33 -33
- package/dist/error/BrowserConfigurationAuthError.mjs +40 -40
- package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
- package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts +3 -3
- package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +7 -7
- package/dist/error/NativeAuthError.d.ts +29 -29
- package/dist/error/NativeAuthError.mjs +60 -60
- package/dist/error/NativeAuthErrorCodes.d.ts +2 -2
- package/dist/error/NativeAuthErrorCodes.mjs +6 -6
- package/dist/error/NestedAppAuthError.d.ts +14 -14
- package/dist/error/NestedAppAuthError.mjs +23 -23
- package/dist/event/EventHandler.d.ts +41 -41
- package/dist/event/EventHandler.mjs +125 -125
- package/dist/event/EventMessage.d.ts +25 -25
- package/dist/event/EventMessage.mjs +68 -68
- package/dist/event/EventType.d.ts +29 -29
- package/dist/event/EventType.mjs +32 -32
- package/dist/index.d.ts +40 -40
- package/dist/index.mjs +1 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts +50 -50
- package/dist/interaction_client/BaseInteractionClient.mjs +106 -106
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.d.ts +4 -4
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +10 -10
- package/dist/interaction_client/NativeInteractionClient.d.ts +151 -143
- package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/NativeInteractionClient.mjs +624 -584
- package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/PopupClient.d.ts +118 -105
- package/dist/interaction_client/PopupClient.d.ts.map +1 -1
- package/dist/interaction_client/PopupClient.mjs +460 -434
- package/dist/interaction_client/PopupClient.mjs.map +1 -1
- package/dist/interaction_client/RedirectClient.d.ts +50 -50
- package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
- package/dist/interaction_client/RedirectClient.mjs +349 -317
- package/dist/interaction_client/RedirectClient.mjs.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.d.ts +23 -23
- package/dist/interaction_client/SilentAuthCodeClient.mjs +57 -57
- package/dist/interaction_client/SilentCacheClient.d.ts +16 -16
- package/dist/interaction_client/SilentCacheClient.mjs +42 -42
- package/dist/interaction_client/SilentIframeClient.d.ts +32 -32
- package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentIframeClient.mjs +111 -101
- package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.d.ts +20 -20
- package/dist/interaction_client/SilentRefreshClient.mjs +47 -47
- package/dist/interaction_client/StandardInteractionClient.d.ts +48 -48
- package/dist/interaction_client/StandardInteractionClient.mjs +199 -199
- package/dist/interaction_handler/InteractionHandler.d.ts +33 -33
- package/dist/interaction_handler/InteractionHandler.mjs +93 -93
- package/dist/interaction_handler/RedirectHandler.d.ts +32 -32
- package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
- package/dist/interaction_handler/RedirectHandler.mjs +135 -134
- package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
- package/dist/interaction_handler/SilentHandler.d.ts +13 -13
- package/dist/interaction_handler/SilentHandler.mjs +134 -134
- package/dist/naa/AccountInfo.d.ts +11 -11
- package/dist/naa/AuthBridge.d.ts +8 -8
- package/dist/naa/AuthResult.d.ts +6 -6
- package/dist/naa/BridgeAccountContext.d.ts +12 -12
- package/dist/naa/BridgeCapabilities.d.ts +3 -3
- package/dist/naa/BridgeError.d.ts +9 -9
- package/dist/naa/BridgeError.mjs +7 -7
- package/dist/naa/BridgeProxy.d.ts +67 -67
- package/dist/naa/BridgeProxy.d.ts.map +1 -1
- package/dist/naa/BridgeProxy.mjs +153 -148
- package/dist/naa/BridgeProxy.mjs.map +1 -1
- package/dist/naa/BridgeRequest.d.ts +7 -7
- package/dist/naa/BridgeRequestEnvelope.d.ts +12 -12
- package/dist/naa/BridgeResponseEnvelope.d.ts +13 -13
- package/dist/naa/BridgeStatusCode.d.ts +11 -11
- package/dist/naa/BridgeStatusCode.mjs +14 -14
- package/dist/naa/IBridgeProxy.d.ts +10 -10
- package/dist/naa/InitContext.d.ts +8 -8
- package/dist/naa/TokenRequest.d.ts +18 -18
- package/dist/naa/TokenResponse.d.ts +13 -13
- package/dist/naa/mapping/NestedAppAuthAdapter.d.ts +35 -35
- package/dist/naa/mapping/NestedAppAuthAdapter.mjs +179 -179
- package/dist/navigation/INavigationClient.d.ts +16 -16
- package/dist/navigation/NavigationClient.d.ts +22 -22
- package/dist/navigation/NavigationClient.mjs +40 -40
- package/dist/navigation/NavigationOptions.d.ts +12 -12
- package/dist/network/FetchClient.d.ts +26 -26
- package/dist/network/FetchClient.mjs +99 -99
- package/dist/operatingcontext/BaseOperatingContext.d.ts +41 -41
- package/dist/operatingcontext/BaseOperatingContext.mjs +94 -94
- package/dist/operatingcontext/NestedAppOperatingContext.d.ts +34 -34
- package/dist/operatingcontext/NestedAppOperatingContext.mjs +71 -71
- package/dist/operatingcontext/StandardOperatingContext.d.ts +25 -25
- package/dist/operatingcontext/StandardOperatingContext.mjs +43 -43
- package/dist/operatingcontext/UnknownOperatingContext.d.ts +25 -25
- package/dist/operatingcontext/UnknownOperatingContext.mjs +42 -42
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.mjs +4 -4
- package/dist/request/AuthorizationCodeRequest.d.ts +8 -8
- package/dist/request/AuthorizationUrlRequest.d.ts +8 -8
- package/dist/request/ClearCacheRequest.d.ts +10 -10
- package/dist/request/EndSessionPopupRequest.d.ts +18 -18
- package/dist/request/EndSessionRequest.d.ts +15 -15
- package/dist/request/InitializeApplicationRequest.d.ts +8 -8
- package/dist/request/PopupRequest.d.ts +34 -34
- package/dist/request/PopupWindowAttributes.d.ts +15 -15
- package/dist/request/RedirectRequest.d.ts +40 -35
- package/dist/request/RedirectRequest.d.ts.map +1 -1
- package/dist/request/RequestHelpers.d.ts +13 -13
- package/dist/request/RequestHelpers.mjs +53 -53
- package/dist/request/SilentRequest.d.ts +33 -33
- package/dist/request/SsoSilentRequest.d.ts +29 -29
- package/dist/response/AuthenticationResult.d.ts +4 -4
- package/dist/response/ResponseHandler.d.ts +7 -7
- package/dist/response/ResponseHandler.mjs +36 -36
- package/dist/telemetry/BrowserPerformanceClient.d.ts +38 -34
- package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/BrowserPerformanceClient.mjs +163 -163
- package/dist/telemetry/BrowserPerformanceClient.mjs.map +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.d.ts +21 -21
- package/dist/telemetry/BrowserPerformanceMeasurement.mjs +92 -92
- package/dist/utils/BrowserConstants.d.ts +182 -180
- package/dist/utils/BrowserConstants.d.ts.map +1 -1
- package/dist/utils/BrowserConstants.mjs +214 -212
- package/dist/utils/BrowserConstants.mjs.map +1 -1
- package/dist/utils/BrowserProtocolUtils.d.ts +11 -11
- package/dist/utils/BrowserProtocolUtils.mjs +21 -21
- package/dist/utils/BrowserUtils.d.ts +75 -75
- package/dist/utils/BrowserUtils.mjs +157 -157
- package/lib/msal-browser.cjs +19028 -18759
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +19028 -18759
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +65 -65
- package/package.json +2 -2
- package/src/cache/BrowserCacheManager.ts +95 -0
- package/src/config/Configuration.ts +9 -1
- package/src/controllers/StandardController.ts +30 -12
- package/src/error/BrowserAuthError.ts +2 -0
- package/src/error/BrowserAuthErrorCodes.ts +1 -0
- package/src/interaction_client/NativeInteractionClient.ts +105 -54
- package/src/interaction_client/PopupClient.ts +202 -117
- package/src/interaction_client/RedirectClient.ts +62 -2
- package/src/interaction_client/SilentIframeClient.ts +41 -3
- package/src/interaction_handler/RedirectHandler.ts +1 -0
- package/src/naa/BridgeProxy.ts +7 -2
- package/src/packageMetadata.ts +1 -1
- package/src/request/RedirectRequest.ts +5 -0
- package/src/telemetry/BrowserPerformanceClient.ts +1 -1
- package/src/utils/BrowserConstants.ts +2 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/*! @azure/msal-browser v3.
|
|
1
|
+
/*! @azure/msal-browser v3.21.0 2024-08-13 */
|
|
2
2
|
'use strict';
|
|
3
|
-
import { OIDC_DEFAULT_SCOPES, invokeAsync, PerformanceEvents, invoke, ThrottlingUtils, ProtocolUtils,
|
|
3
|
+
import { OIDC_DEFAULT_SCOPES, invokeAsync, PerformanceEvents, AuthError, ServerError, invoke, ThrottlingUtils, ProtocolUtils, ProtocolMode, UrlString, ServerResponseType } from '@azure/msal-common';
|
|
4
4
|
import { StandardInteractionClient } from './StandardInteractionClient.mjs';
|
|
5
5
|
import { EventType } from '../event/EventType.mjs';
|
|
6
6
|
import { ApiId, InteractionType, BrowserConstants } from '../utils/BrowserConstants.mjs';
|
|
@@ -12,438 +12,464 @@ import { InteractionHandler } from '../interaction_handler/InteractionHandler.mj
|
|
|
12
12
|
import { deserializeResponse } from '../response/ResponseHandler.mjs';
|
|
13
13
|
import { nativeConnectionNotEstablished, emptyNavigateUri, userCancelled, emptyWindowError, popupWindowError } from '../error/BrowserAuthErrorCodes.mjs';
|
|
14
14
|
|
|
15
|
-
/*
|
|
16
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
17
|
-
* Licensed under the MIT License.
|
|
18
|
-
*/
|
|
19
|
-
class PopupClient extends StandardInteractionClient {
|
|
20
|
-
constructor(config, storageImpl, browserCrypto, logger, eventHandler, navigationClient, performanceClient, nativeStorageImpl, nativeMessageHandler, correlationId) {
|
|
21
|
-
super(config, storageImpl, browserCrypto, logger, eventHandler, navigationClient, performanceClient, nativeMessageHandler, correlationId);
|
|
22
|
-
// Properly sets this reference for the unload event.
|
|
23
|
-
this.unloadWindow = this.unloadWindow.bind(this);
|
|
24
|
-
this.nativeStorage = nativeStorageImpl;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Acquires tokens by opening a popup window to the /authorize endpoint of the authority
|
|
28
|
-
* @param request
|
|
29
|
-
*/
|
|
30
|
-
acquireToken(request) {
|
|
31
|
-
try {
|
|
32
|
-
const popupName = this.generatePopupName(request.scopes || OIDC_DEFAULT_SCOPES, request.authority || this.config.auth.authority);
|
|
33
|
-
const popupWindowAttributes = request.popupWindowAttributes || {};
|
|
34
|
-
// asyncPopups flag is true. Acquires token without first opening popup. Popup will be opened later asynchronously.
|
|
35
|
-
if (this.config.system.asyncPopups) {
|
|
36
|
-
this.logger.verbose("asyncPopups set to true, acquiring token");
|
|
37
|
-
// Passes on popup position and dimensions if in request
|
|
38
|
-
return this.acquireTokenPopupAsync(request, popupName, popupWindowAttributes);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
// asyncPopups flag is set to false. Opens popup before acquiring token.
|
|
42
|
-
this.logger.verbose("asyncPopup set to false, opening popup before acquiring token");
|
|
43
|
-
const popup = this.openSizedPopup("about:blank", popupName, popupWindowAttributes);
|
|
44
|
-
return this.acquireTokenPopupAsync(request, popupName, popupWindowAttributes, popup);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
catch (e) {
|
|
48
|
-
return Promise.reject(e);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Clears local cache for the current user then opens a popup window prompting the user to sign-out of the server
|
|
53
|
-
* @param logoutRequest
|
|
54
|
-
*/
|
|
55
|
-
logout(logoutRequest) {
|
|
56
|
-
try {
|
|
57
|
-
this.logger.verbose("logoutPopup called");
|
|
58
|
-
const validLogoutRequest = this.initializeLogoutRequest(logoutRequest);
|
|
59
|
-
const popupName = this.generateLogoutPopupName(validLogoutRequest);
|
|
60
|
-
const authority = logoutRequest && logoutRequest.authority;
|
|
61
|
-
const mainWindowRedirectUri = logoutRequest && logoutRequest.mainWindowRedirectUri;
|
|
62
|
-
const popupWindowAttributes = logoutRequest?.popupWindowAttributes || {};
|
|
63
|
-
// asyncPopups flag is true. Acquires token without first opening popup. Popup will be opened later asynchronously.
|
|
64
|
-
if (this.config.system.asyncPopups) {
|
|
65
|
-
this.logger.verbose("asyncPopups set to true");
|
|
66
|
-
// Passes on popup position and dimensions if in request
|
|
67
|
-
return this.logoutPopupAsync(validLogoutRequest, popupName, popupWindowAttributes, authority, undefined, mainWindowRedirectUri);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
// asyncPopups flag is set to false. Opens popup before logging out.
|
|
71
|
-
this.logger.verbose("asyncPopup set to false, opening popup");
|
|
72
|
-
const popup = this.openSizedPopup("about:blank", popupName, popupWindowAttributes);
|
|
73
|
-
return this.logoutPopupAsync(validLogoutRequest, popupName, popupWindowAttributes, authority, popup, mainWindowRedirectUri);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
// Since this function is synchronous we need to reject
|
|
78
|
-
return Promise.reject(e);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Helper which
|
|
83
|
-
* @param validRequest
|
|
84
|
-
* @param popupName
|
|
85
|
-
* @param popup
|
|
86
|
-
* @param popupWindowAttributes
|
|
87
|
-
*
|
|
88
|
-
* @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
|
|
89
|
-
*/
|
|
90
|
-
async acquireTokenPopupAsync(request, popupName, popupWindowAttributes, popup) {
|
|
91
|
-
this.logger.verbose("acquireTokenPopupAsync called");
|
|
92
|
-
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenPopup);
|
|
93
|
-
const validRequest = await invokeAsync(this.initializeAuthorizationRequest.bind(this), PerformanceEvents.StandardInteractionClientInitializeAuthorizationRequest, this.logger, this.performanceClient, this.correlationId)(request, InteractionType.Popup);
|
|
94
|
-
preconnect(validRequest.authority);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
};
|
|
120
|
-
const
|
|
121
|
-
this.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
this.logger.
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
*
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
15
|
+
/*
|
|
16
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
17
|
+
* Licensed under the MIT License.
|
|
18
|
+
*/
|
|
19
|
+
class PopupClient extends StandardInteractionClient {
|
|
20
|
+
constructor(config, storageImpl, browserCrypto, logger, eventHandler, navigationClient, performanceClient, nativeStorageImpl, nativeMessageHandler, correlationId) {
|
|
21
|
+
super(config, storageImpl, browserCrypto, logger, eventHandler, navigationClient, performanceClient, nativeMessageHandler, correlationId);
|
|
22
|
+
// Properly sets this reference for the unload event.
|
|
23
|
+
this.unloadWindow = this.unloadWindow.bind(this);
|
|
24
|
+
this.nativeStorage = nativeStorageImpl;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Acquires tokens by opening a popup window to the /authorize endpoint of the authority
|
|
28
|
+
* @param request
|
|
29
|
+
*/
|
|
30
|
+
acquireToken(request) {
|
|
31
|
+
try {
|
|
32
|
+
const popupName = this.generatePopupName(request.scopes || OIDC_DEFAULT_SCOPES, request.authority || this.config.auth.authority);
|
|
33
|
+
const popupWindowAttributes = request.popupWindowAttributes || {};
|
|
34
|
+
// asyncPopups flag is true. Acquires token without first opening popup. Popup will be opened later asynchronously.
|
|
35
|
+
if (this.config.system.asyncPopups) {
|
|
36
|
+
this.logger.verbose("asyncPopups set to true, acquiring token");
|
|
37
|
+
// Passes on popup position and dimensions if in request
|
|
38
|
+
return this.acquireTokenPopupAsync(request, popupName, popupWindowAttributes);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// asyncPopups flag is set to false. Opens popup before acquiring token.
|
|
42
|
+
this.logger.verbose("asyncPopup set to false, opening popup before acquiring token");
|
|
43
|
+
const popup = this.openSizedPopup("about:blank", popupName, popupWindowAttributes);
|
|
44
|
+
return this.acquireTokenPopupAsync(request, popupName, popupWindowAttributes, popup);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
return Promise.reject(e);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Clears local cache for the current user then opens a popup window prompting the user to sign-out of the server
|
|
53
|
+
* @param logoutRequest
|
|
54
|
+
*/
|
|
55
|
+
logout(logoutRequest) {
|
|
56
|
+
try {
|
|
57
|
+
this.logger.verbose("logoutPopup called");
|
|
58
|
+
const validLogoutRequest = this.initializeLogoutRequest(logoutRequest);
|
|
59
|
+
const popupName = this.generateLogoutPopupName(validLogoutRequest);
|
|
60
|
+
const authority = logoutRequest && logoutRequest.authority;
|
|
61
|
+
const mainWindowRedirectUri = logoutRequest && logoutRequest.mainWindowRedirectUri;
|
|
62
|
+
const popupWindowAttributes = logoutRequest?.popupWindowAttributes || {};
|
|
63
|
+
// asyncPopups flag is true. Acquires token without first opening popup. Popup will be opened later asynchronously.
|
|
64
|
+
if (this.config.system.asyncPopups) {
|
|
65
|
+
this.logger.verbose("asyncPopups set to true");
|
|
66
|
+
// Passes on popup position and dimensions if in request
|
|
67
|
+
return this.logoutPopupAsync(validLogoutRequest, popupName, popupWindowAttributes, authority, undefined, mainWindowRedirectUri);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// asyncPopups flag is set to false. Opens popup before logging out.
|
|
71
|
+
this.logger.verbose("asyncPopup set to false, opening popup");
|
|
72
|
+
const popup = this.openSizedPopup("about:blank", popupName, popupWindowAttributes);
|
|
73
|
+
return this.logoutPopupAsync(validLogoutRequest, popupName, popupWindowAttributes, authority, popup, mainWindowRedirectUri);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
// Since this function is synchronous we need to reject
|
|
78
|
+
return Promise.reject(e);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Helper which initializes authorization clients and requests
|
|
83
|
+
* @param validRequest
|
|
84
|
+
* @param popupName
|
|
85
|
+
* @param popup
|
|
86
|
+
* @param popupWindowAttributes
|
|
87
|
+
*
|
|
88
|
+
* @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
|
|
89
|
+
*/
|
|
90
|
+
async acquireTokenPopupAsync(request, popupName, popupWindowAttributes, popup) {
|
|
91
|
+
this.logger.verbose("acquireTokenPopupAsync called");
|
|
92
|
+
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenPopup);
|
|
93
|
+
const validRequest = await invokeAsync(this.initializeAuthorizationRequest.bind(this), PerformanceEvents.StandardInteractionClientInitializeAuthorizationRequest, this.logger, this.performanceClient, this.correlationId)(request, InteractionType.Popup);
|
|
94
|
+
preconnect(validRequest.authority);
|
|
95
|
+
let authClient;
|
|
96
|
+
try {
|
|
97
|
+
// Create auth code request and generate PKCE params
|
|
98
|
+
const authCodeRequest = await invokeAsync(this.initializeAuthorizationCodeRequest.bind(this), PerformanceEvents.StandardInteractionClientInitializeAuthorizationCodeRequest, this.logger, this.performanceClient, this.correlationId)(validRequest);
|
|
99
|
+
// Initialize the client
|
|
100
|
+
authClient = await invokeAsync(this.createAuthCodeClient.bind(this), PerformanceEvents.StandardInteractionClientCreateAuthCodeClient, this.logger, this.performanceClient, this.correlationId)(serverTelemetryManager, validRequest.authority, validRequest.azureCloudOptions, validRequest.account);
|
|
101
|
+
return await invokeAsync(this.acquireTokenPopupAsyncHelper.bind(this), PerformanceEvents.PopupClientTokenHelper, this.logger, this.performanceClient, this.correlationId)(authClient, authCodeRequest, validRequest, request, popupName, popupWindowAttributes, popup);
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
if (popup) {
|
|
105
|
+
// Close the synchronous popup if an error is thrown before the window unload event is registered
|
|
106
|
+
popup.close();
|
|
107
|
+
}
|
|
108
|
+
if (e instanceof AuthError) {
|
|
109
|
+
e.setCorrelationId(this.correlationId);
|
|
110
|
+
serverTelemetryManager.cacheFailedRequest(e);
|
|
111
|
+
}
|
|
112
|
+
if (!authClient ||
|
|
113
|
+
!(e instanceof ServerError) ||
|
|
114
|
+
e.errorCode !== BrowserConstants.INVALID_GRANT_ERROR) {
|
|
115
|
+
throw e;
|
|
116
|
+
}
|
|
117
|
+
this.performanceClient.addFields({
|
|
118
|
+
retryError: e.errorCode,
|
|
119
|
+
}, this.correlationId);
|
|
120
|
+
const retryAuthCodeRequest = await invokeAsync(this.initializeAuthorizationCodeRequest.bind(this), PerformanceEvents.StandardInteractionClientInitializeAuthorizationCodeRequest, this.logger, this.performanceClient, this.correlationId)(validRequest);
|
|
121
|
+
return await invokeAsync(this.acquireTokenPopupAsyncHelper.bind(this), PerformanceEvents.PopupClientTokenHelper, this.logger, this.performanceClient, this.correlationId)(authClient, retryAuthCodeRequest, validRequest, request, popupName, popupWindowAttributes, popup);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Helper which obtains an access_token for your API via opening a popup window in the user's browser
|
|
126
|
+
* @param authClient
|
|
127
|
+
* @param authCodeRequest
|
|
128
|
+
* @param validRequest
|
|
129
|
+
* @param request
|
|
130
|
+
* @param popupName
|
|
131
|
+
* @param popupWindowAttributes
|
|
132
|
+
* @param popup
|
|
133
|
+
* @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
|
|
134
|
+
*/
|
|
135
|
+
async acquireTokenPopupAsyncHelper(authClient, authCodeRequest, validRequest, request, popupName, popupWindowAttributes, popup) {
|
|
136
|
+
const correlationId = validRequest.correlationId;
|
|
137
|
+
this.performanceClient.addQueueMeasurement(PerformanceEvents.PopupClientTokenHelper, correlationId);
|
|
138
|
+
const isNativeBroker = NativeMessageHandler.isNativeAvailable(this.config, this.logger, this.nativeMessageHandler, request.authenticationScheme);
|
|
139
|
+
// Start measurement for server calls with native brokering enabled
|
|
140
|
+
let fetchNativeAccountIdMeasurement;
|
|
141
|
+
if (isNativeBroker) {
|
|
142
|
+
fetchNativeAccountIdMeasurement =
|
|
143
|
+
this.performanceClient.startMeasurement(PerformanceEvents.FetchAccountIdWithNativeBroker, request.correlationId);
|
|
144
|
+
}
|
|
145
|
+
// Create acquire token url.
|
|
146
|
+
const navigateUrl = await authClient.getAuthCodeUrl({
|
|
147
|
+
...validRequest,
|
|
148
|
+
nativeBroker: isNativeBroker,
|
|
149
|
+
});
|
|
150
|
+
// Create popup interaction handler.
|
|
151
|
+
const interactionHandler = new InteractionHandler(authClient, this.browserStorage, authCodeRequest, this.logger, this.performanceClient);
|
|
152
|
+
// Show the UI once the url has been created. Get the window handle for the popup.
|
|
153
|
+
const popupParameters = {
|
|
154
|
+
popup,
|
|
155
|
+
popupName,
|
|
156
|
+
popupWindowAttributes,
|
|
157
|
+
};
|
|
158
|
+
const popupWindow = this.initiateAuthRequest(navigateUrl, popupParameters);
|
|
159
|
+
this.eventHandler.emitEvent(EventType.POPUP_OPENED, InteractionType.Popup, { popupWindow }, null);
|
|
160
|
+
// Monitor the window for the hash. Return the string value and close the popup when the hash is received. Default timeout is 60 seconds.
|
|
161
|
+
const responseString = await this.monitorPopupForHash(popupWindow);
|
|
162
|
+
const serverParams = invoke(deserializeResponse, PerformanceEvents.DeserializeResponse, this.logger, this.performanceClient, this.correlationId)(responseString, this.config.auth.OIDCOptions.serverResponseType, this.logger);
|
|
163
|
+
// Remove throttle if it exists
|
|
164
|
+
ThrottlingUtils.removeThrottle(this.browserStorage, this.config.auth.clientId, authCodeRequest);
|
|
165
|
+
if (serverParams.accountId) {
|
|
166
|
+
this.logger.verbose("Account id found in hash, calling WAM for token");
|
|
167
|
+
// end measurement for server call with native brokering enabled
|
|
168
|
+
if (fetchNativeAccountIdMeasurement) {
|
|
169
|
+
fetchNativeAccountIdMeasurement.end({
|
|
170
|
+
success: true,
|
|
171
|
+
isNativeBroker: true,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
if (!this.nativeMessageHandler) {
|
|
175
|
+
throw createBrowserAuthError(nativeConnectionNotEstablished);
|
|
176
|
+
}
|
|
177
|
+
const nativeInteractionClient = new NativeInteractionClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, ApiId.acquireTokenPopup, this.performanceClient, this.nativeMessageHandler, serverParams.accountId, this.nativeStorage, validRequest.correlationId);
|
|
178
|
+
const { userRequestState } = ProtocolUtils.parseRequestState(this.browserCrypto, validRequest.state);
|
|
179
|
+
return nativeInteractionClient.acquireToken({
|
|
180
|
+
...validRequest,
|
|
181
|
+
state: userRequestState,
|
|
182
|
+
prompt: undefined, // Server should handle the prompt, ideally native broker can do this part silently
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
// Handle response from hash string.
|
|
186
|
+
const result = await interactionHandler.handleCodeResponse(serverParams, validRequest);
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
*
|
|
191
|
+
* @param validRequest
|
|
192
|
+
* @param popupName
|
|
193
|
+
* @param requestAuthority
|
|
194
|
+
* @param popup
|
|
195
|
+
* @param mainWindowRedirectUri
|
|
196
|
+
* @param popupWindowAttributes
|
|
197
|
+
*/
|
|
198
|
+
async logoutPopupAsync(validRequest, popupName, popupWindowAttributes, requestAuthority, popup, mainWindowRedirectUri) {
|
|
199
|
+
this.logger.verbose("logoutPopupAsync called");
|
|
200
|
+
this.eventHandler.emitEvent(EventType.LOGOUT_START, InteractionType.Popup, validRequest);
|
|
201
|
+
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.logoutPopup);
|
|
202
|
+
try {
|
|
203
|
+
// Clear cache on logout
|
|
204
|
+
await this.clearCacheOnLogout(validRequest.account);
|
|
205
|
+
// Initialize the client
|
|
206
|
+
const authClient = await invokeAsync(this.createAuthCodeClient.bind(this), PerformanceEvents.StandardInteractionClientCreateAuthCodeClient, this.logger, this.performanceClient, this.correlationId)(serverTelemetryManager, requestAuthority, undefined, // AzureCloudOptions
|
|
207
|
+
validRequest.account || undefined);
|
|
208
|
+
try {
|
|
209
|
+
authClient.authority.endSessionEndpoint;
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
if (validRequest.account?.homeAccountId &&
|
|
213
|
+
validRequest.postLogoutRedirectUri &&
|
|
214
|
+
authClient.authority.protocolMode === ProtocolMode.OIDC) {
|
|
215
|
+
void this.browserStorage.removeAccount(validRequest.account?.homeAccountId);
|
|
216
|
+
this.eventHandler.emitEvent(EventType.LOGOUT_SUCCESS, InteractionType.Popup, validRequest);
|
|
217
|
+
if (mainWindowRedirectUri) {
|
|
218
|
+
const navigationOptions = {
|
|
219
|
+
apiId: ApiId.logoutPopup,
|
|
220
|
+
timeout: this.config.system.redirectNavigationTimeout,
|
|
221
|
+
noHistory: false,
|
|
222
|
+
};
|
|
223
|
+
const absoluteUrl = UrlString.getAbsoluteUrl(mainWindowRedirectUri, getCurrentUri());
|
|
224
|
+
await this.navigationClient.navigateInternal(absoluteUrl, navigationOptions);
|
|
225
|
+
}
|
|
226
|
+
if (popup) {
|
|
227
|
+
popup.close();
|
|
228
|
+
}
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Create logout string and navigate user window to logout.
|
|
233
|
+
const logoutUri = authClient.getLogoutUri(validRequest);
|
|
234
|
+
this.eventHandler.emitEvent(EventType.LOGOUT_SUCCESS, InteractionType.Popup, validRequest);
|
|
235
|
+
// Open the popup window to requestUrl.
|
|
236
|
+
const popupWindow = this.openPopup(logoutUri, {
|
|
237
|
+
popupName,
|
|
238
|
+
popupWindowAttributes,
|
|
239
|
+
popup,
|
|
240
|
+
});
|
|
241
|
+
this.eventHandler.emitEvent(EventType.POPUP_OPENED, InteractionType.Popup, { popupWindow }, null);
|
|
242
|
+
await this.monitorPopupForHash(popupWindow).catch(() => {
|
|
243
|
+
// Swallow any errors related to monitoring the window. Server logout is best effort
|
|
244
|
+
});
|
|
245
|
+
if (mainWindowRedirectUri) {
|
|
246
|
+
const navigationOptions = {
|
|
247
|
+
apiId: ApiId.logoutPopup,
|
|
248
|
+
timeout: this.config.system.redirectNavigationTimeout,
|
|
249
|
+
noHistory: false,
|
|
250
|
+
};
|
|
251
|
+
const absoluteUrl = UrlString.getAbsoluteUrl(mainWindowRedirectUri, getCurrentUri());
|
|
252
|
+
this.logger.verbose("Redirecting main window to url specified in the request");
|
|
253
|
+
this.logger.verbosePii(`Redirecting main window to: ${absoluteUrl}`);
|
|
254
|
+
await this.navigationClient.navigateInternal(absoluteUrl, navigationOptions);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
this.logger.verbose("No main window navigation requested");
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
if (popup) {
|
|
262
|
+
// Close the synchronous popup if an error is thrown before the window unload event is registered
|
|
263
|
+
popup.close();
|
|
264
|
+
}
|
|
265
|
+
if (e instanceof AuthError) {
|
|
266
|
+
e.setCorrelationId(this.correlationId);
|
|
267
|
+
serverTelemetryManager.cacheFailedRequest(e);
|
|
268
|
+
}
|
|
269
|
+
this.browserStorage.setInteractionInProgress(false);
|
|
270
|
+
this.eventHandler.emitEvent(EventType.LOGOUT_FAILURE, InteractionType.Popup, null, e);
|
|
271
|
+
this.eventHandler.emitEvent(EventType.LOGOUT_END, InteractionType.Popup);
|
|
272
|
+
throw e;
|
|
273
|
+
}
|
|
274
|
+
this.eventHandler.emitEvent(EventType.LOGOUT_END, InteractionType.Popup);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Opens a popup window with given request Url.
|
|
278
|
+
* @param requestUrl
|
|
279
|
+
*/
|
|
280
|
+
initiateAuthRequest(requestUrl, params) {
|
|
281
|
+
// Check that request url is not empty.
|
|
282
|
+
if (requestUrl) {
|
|
283
|
+
this.logger.infoPii(`Navigate to: ${requestUrl}`);
|
|
284
|
+
// Open the popup window to requestUrl.
|
|
285
|
+
return this.openPopup(requestUrl, params);
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
// Throw error if request URL is empty.
|
|
289
|
+
this.logger.error("Navigate url is empty");
|
|
290
|
+
throw createBrowserAuthError(emptyNavigateUri);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Monitors a window until it loads a url with the same origin.
|
|
295
|
+
* @param popupWindow - window that is being monitored
|
|
296
|
+
* @param timeout - timeout for processing hash once popup is redirected back to application
|
|
297
|
+
*/
|
|
298
|
+
monitorPopupForHash(popupWindow) {
|
|
299
|
+
return new Promise((resolve, reject) => {
|
|
300
|
+
this.logger.verbose("PopupHandler.monitorPopupForHash - polling started");
|
|
301
|
+
const intervalId = setInterval(() => {
|
|
302
|
+
// Window is closed
|
|
303
|
+
if (popupWindow.closed) {
|
|
304
|
+
this.logger.error("PopupHandler.monitorPopupForHash - window closed");
|
|
305
|
+
clearInterval(intervalId);
|
|
306
|
+
reject(createBrowserAuthError(userCancelled));
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
let href = "";
|
|
310
|
+
try {
|
|
311
|
+
/*
|
|
312
|
+
* Will throw if cross origin,
|
|
313
|
+
* which should be caught and ignored
|
|
314
|
+
* since we need the interval to keep running while on STS UI.
|
|
315
|
+
*/
|
|
316
|
+
href = popupWindow.location.href;
|
|
317
|
+
}
|
|
318
|
+
catch (e) { }
|
|
319
|
+
// Don't process blank pages or cross domain
|
|
320
|
+
if (!href || href === "about:blank") {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
clearInterval(intervalId);
|
|
324
|
+
let responseString = "";
|
|
325
|
+
const responseType = this.config.auth.OIDCOptions.serverResponseType;
|
|
326
|
+
if (popupWindow) {
|
|
327
|
+
if (responseType === ServerResponseType.QUERY) {
|
|
328
|
+
responseString = popupWindow.location.search;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
responseString = popupWindow.location.hash;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
this.logger.verbose("PopupHandler.monitorPopupForHash - popup window is on same origin as caller");
|
|
335
|
+
resolve(responseString);
|
|
336
|
+
}, this.config.system.pollIntervalMilliseconds);
|
|
337
|
+
}).finally(() => {
|
|
338
|
+
this.cleanPopup(popupWindow);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* @hidden
|
|
343
|
+
*
|
|
344
|
+
* Configures popup window for login.
|
|
345
|
+
*
|
|
346
|
+
* @param urlNavigate
|
|
347
|
+
* @param title
|
|
348
|
+
* @param popUpWidth
|
|
349
|
+
* @param popUpHeight
|
|
350
|
+
* @param popupWindowAttributes
|
|
351
|
+
* @ignore
|
|
352
|
+
* @hidden
|
|
353
|
+
*/
|
|
354
|
+
openPopup(urlNavigate, popupParams) {
|
|
355
|
+
try {
|
|
356
|
+
let popupWindow;
|
|
357
|
+
// Popup window passed in, setting url to navigate to
|
|
358
|
+
if (popupParams.popup) {
|
|
359
|
+
popupWindow = popupParams.popup;
|
|
360
|
+
this.logger.verbosePii(`Navigating popup window to: ${urlNavigate}`);
|
|
361
|
+
popupWindow.location.assign(urlNavigate);
|
|
362
|
+
}
|
|
363
|
+
else if (typeof popupParams.popup === "undefined") {
|
|
364
|
+
// Popup will be undefined if it was not passed in
|
|
365
|
+
this.logger.verbosePii(`Opening popup window to: ${urlNavigate}`);
|
|
366
|
+
popupWindow = this.openSizedPopup(urlNavigate, popupParams.popupName, popupParams.popupWindowAttributes);
|
|
367
|
+
}
|
|
368
|
+
// Popup will be null if popups are blocked
|
|
369
|
+
if (!popupWindow) {
|
|
370
|
+
throw createBrowserAuthError(emptyWindowError);
|
|
371
|
+
}
|
|
372
|
+
if (popupWindow.focus) {
|
|
373
|
+
popupWindow.focus();
|
|
374
|
+
}
|
|
375
|
+
this.currentWindow = popupWindow;
|
|
376
|
+
window.addEventListener("beforeunload", this.unloadWindow);
|
|
377
|
+
return popupWindow;
|
|
378
|
+
}
|
|
379
|
+
catch (e) {
|
|
380
|
+
this.logger.error("error opening popup " + e.message);
|
|
381
|
+
this.browserStorage.setInteractionInProgress(false);
|
|
382
|
+
throw createBrowserAuthError(popupWindowError);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Helper function to set popup window dimensions and position
|
|
387
|
+
* @param urlNavigate
|
|
388
|
+
* @param popupName
|
|
389
|
+
* @param popupWindowAttributes
|
|
390
|
+
* @returns
|
|
391
|
+
*/
|
|
392
|
+
openSizedPopup(urlNavigate, popupName, popupWindowAttributes) {
|
|
393
|
+
/**
|
|
394
|
+
* adding winLeft and winTop to account for dual monitor
|
|
395
|
+
* using screenLeft and screenTop for IE8 and earlier
|
|
396
|
+
*/
|
|
397
|
+
const winLeft = window.screenLeft ? window.screenLeft : window.screenX;
|
|
398
|
+
const winTop = window.screenTop ? window.screenTop : window.screenY;
|
|
399
|
+
/**
|
|
400
|
+
* window.innerWidth displays browser window"s height and width excluding toolbars
|
|
401
|
+
* using document.documentElement.clientWidth for IE8 and earlier
|
|
402
|
+
*/
|
|
403
|
+
const winWidth = window.innerWidth ||
|
|
404
|
+
document.documentElement.clientWidth ||
|
|
405
|
+
document.body.clientWidth;
|
|
406
|
+
const winHeight = window.innerHeight ||
|
|
407
|
+
document.documentElement.clientHeight ||
|
|
408
|
+
document.body.clientHeight;
|
|
409
|
+
let width = popupWindowAttributes.popupSize?.width;
|
|
410
|
+
let height = popupWindowAttributes.popupSize?.height;
|
|
411
|
+
let top = popupWindowAttributes.popupPosition?.top;
|
|
412
|
+
let left = popupWindowAttributes.popupPosition?.left;
|
|
413
|
+
if (!width || width < 0 || width > winWidth) {
|
|
414
|
+
this.logger.verbose("Default popup window width used. Window width not configured or invalid.");
|
|
415
|
+
width = BrowserConstants.POPUP_WIDTH;
|
|
416
|
+
}
|
|
417
|
+
if (!height || height < 0 || height > winHeight) {
|
|
418
|
+
this.logger.verbose("Default popup window height used. Window height not configured or invalid.");
|
|
419
|
+
height = BrowserConstants.POPUP_HEIGHT;
|
|
420
|
+
}
|
|
421
|
+
if (!top || top < 0 || top > winHeight) {
|
|
422
|
+
this.logger.verbose("Default popup window top position used. Window top not configured or invalid.");
|
|
423
|
+
top = Math.max(0, winHeight / 2 - BrowserConstants.POPUP_HEIGHT / 2 + winTop);
|
|
424
|
+
}
|
|
425
|
+
if (!left || left < 0 || left > winWidth) {
|
|
426
|
+
this.logger.verbose("Default popup window left position used. Window left not configured or invalid.");
|
|
427
|
+
left = Math.max(0, winWidth / 2 - BrowserConstants.POPUP_WIDTH / 2 + winLeft);
|
|
428
|
+
}
|
|
429
|
+
return window.open(urlNavigate, popupName, `width=${width}, height=${height}, top=${top}, left=${left}, scrollbars=yes`);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Event callback to unload main window.
|
|
433
|
+
*/
|
|
434
|
+
unloadWindow(e) {
|
|
435
|
+
this.browserStorage.cleanRequestByInteractionType(InteractionType.Popup);
|
|
436
|
+
if (this.currentWindow) {
|
|
437
|
+
this.currentWindow.close();
|
|
438
|
+
}
|
|
439
|
+
// Guarantees browser unload will happen, so no other errors will be thrown.
|
|
440
|
+
e.preventDefault();
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Closes popup, removes any state vars created during popup calls.
|
|
444
|
+
* @param popupWindow
|
|
445
|
+
*/
|
|
446
|
+
cleanPopup(popupWindow) {
|
|
447
|
+
if (popupWindow) {
|
|
448
|
+
// Close window.
|
|
449
|
+
popupWindow.close();
|
|
450
|
+
}
|
|
451
|
+
// Remove window unload function
|
|
452
|
+
window.removeEventListener("beforeunload", this.unloadWindow);
|
|
453
|
+
// Interaction is completed - remove interaction status.
|
|
454
|
+
this.browserStorage.setInteractionInProgress(false);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Generates the name for the popup based on the client id and request
|
|
458
|
+
* @param clientId
|
|
459
|
+
* @param request
|
|
460
|
+
*/
|
|
461
|
+
generatePopupName(scopes, authority) {
|
|
462
|
+
return `${BrowserConstants.POPUP_NAME_PREFIX}.${this.config.auth.clientId}.${scopes.join("-")}.${authority}.${this.correlationId}`;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Generates the name for the popup based on the client id and request for logouts
|
|
466
|
+
* @param clientId
|
|
467
|
+
* @param request
|
|
468
|
+
*/
|
|
469
|
+
generateLogoutPopupName(request) {
|
|
470
|
+
const homeAccountId = request.account && request.account.homeAccountId;
|
|
471
|
+
return `${BrowserConstants.POPUP_NAME_PREFIX}.${this.config.auth.clientId}.${homeAccountId}.${this.correlationId}`;
|
|
472
|
+
}
|
|
447
473
|
}
|
|
448
474
|
|
|
449
475
|
export { PopupClient };
|