@azure/msal-browser 2.16.0 → 2.19.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/CHANGELOG.json +240 -0
- package/{changelog.md → CHANGELOG.md} +489 -430
- package/LICENSE +21 -21
- package/README.md +212 -206
- package/dist/_virtual/_tslib.js +1 -1
- package/dist/app/ClientApplication.d.ts +19 -140
- package/dist/app/ClientApplication.d.ts.map +1 -1
- package/dist/app/ClientApplication.js +115 -895
- package/dist/app/ClientApplication.js.map +1 -1
- package/dist/app/IPublicClientApplication.d.ts +6 -0
- package/dist/app/IPublicClientApplication.d.ts.map +1 -1
- package/dist/app/IPublicClientApplication.js +13 -1
- package/dist/app/IPublicClientApplication.js.map +1 -1
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.js +35 -41
- package/dist/app/PublicClientApplication.js.map +1 -1
- package/dist/cache/AsyncMemoryStorage.d.ts +46 -0
- package/dist/cache/AsyncMemoryStorage.d.ts.map +1 -0
- package/dist/cache/AsyncMemoryStorage.js +195 -0
- package/dist/cache/AsyncMemoryStorage.js.map +1 -0
- package/dist/cache/BrowserCacheManager.d.ts +19 -2
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.js +104 -15
- package/dist/cache/BrowserCacheManager.js.map +1 -1
- package/dist/cache/BrowserStorage.d.ts +1 -1
- package/dist/cache/BrowserStorage.d.ts.map +1 -1
- package/dist/cache/BrowserStorage.js +1 -1
- package/dist/cache/BrowserStorage.js.map +1 -1
- package/dist/cache/DatabaseStorage.d.ts +29 -4
- package/dist/cache/DatabaseStorage.d.ts.map +1 -1
- package/dist/cache/DatabaseStorage.js +151 -45
- package/dist/cache/DatabaseStorage.js.map +1 -1
- package/dist/cache/IAsyncMemoryStorage.d.ts +28 -0
- package/dist/cache/IAsyncMemoryStorage.d.ts.map +1 -0
- package/dist/cache/ITokenCache.d.ts +8 -0
- package/dist/cache/ITokenCache.d.ts.map +1 -0
- package/dist/cache/IWindowStorage.d.ts +3 -3
- package/dist/cache/IWindowStorage.d.ts.map +1 -1
- package/dist/cache/MemoryStorage.d.ts +3 -3
- package/dist/cache/MemoryStorage.d.ts.map +1 -1
- package/dist/cache/MemoryStorage.js +1 -1
- package/dist/cache/MemoryStorage.js.map +1 -1
- package/dist/cache/TokenCache.d.ts +48 -0
- package/dist/cache/TokenCache.d.ts.map +1 -0
- package/dist/cache/TokenCache.js +124 -0
- package/dist/cache/TokenCache.js.map +1 -0
- package/dist/config/Configuration.js +1 -1
- package/dist/config/Configuration.js.map +1 -1
- package/dist/crypto/BrowserCrypto.d.ts +3 -1
- package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
- package/dist/crypto/BrowserCrypto.js +3 -2
- package/dist/crypto/BrowserCrypto.js.map +1 -1
- package/dist/crypto/CryptoOps.d.ts +21 -6
- package/dist/crypto/CryptoOps.d.ts.map +1 -1
- package/dist/crypto/CryptoOps.js +67 -15
- package/dist/crypto/CryptoOps.js.map +1 -1
- package/dist/crypto/GuidGenerator.js +1 -1
- package/dist/crypto/GuidGenerator.js.map +1 -1
- package/dist/crypto/PkceGenerator.js +1 -1
- package/dist/crypto/PkceGenerator.js.map +1 -1
- package/dist/crypto/SignedHttpRequest.d.ts +31 -0
- package/dist/crypto/SignedHttpRequest.d.ts.map +1 -0
- package/dist/crypto/SignedHttpRequest.js +70 -0
- package/dist/crypto/SignedHttpRequest.js.map +1 -0
- package/dist/encode/Base64Decode.js +1 -1
- package/dist/encode/Base64Decode.js.map +1 -1
- package/dist/encode/Base64Encode.js +1 -1
- package/dist/encode/Base64Encode.js.map +1 -1
- package/dist/error/BrowserAuthError.d.ts +28 -4
- package/dist/error/BrowserAuthError.d.ts.map +1 -1
- package/dist/error/BrowserAuthError.js +41 -11
- package/dist/error/BrowserAuthError.js.map +1 -1
- package/dist/error/BrowserConfigurationAuthError.js +1 -1
- package/dist/error/BrowserConfigurationAuthError.js.map +1 -1
- package/dist/event/EventHandler.d.ts +13 -0
- package/dist/event/EventHandler.d.ts.map +1 -1
- package/dist/event/EventHandler.js +66 -1
- package/dist/event/EventHandler.js.map +1 -1
- package/dist/event/EventMessage.d.ts +4 -3
- package/dist/event/EventMessage.d.ts.map +1 -1
- package/dist/event/EventMessage.js +24 -5
- package/dist/event/EventMessage.js.map +1 -1
- package/dist/event/EventType.d.ts +2 -0
- package/dist/event/EventType.d.ts.map +1 -1
- package/dist/event/EventType.js +3 -1
- package/dist/event/EventType.js.map +1 -1
- package/dist/index.cjs.js +4505 -3045
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts +42 -0
- package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -0
- package/dist/interaction_client/BaseInteractionClient.js +131 -0
- package/dist/interaction_client/BaseInteractionClient.js.map +1 -0
- package/dist/interaction_client/PopupClient.d.ts +37 -0
- package/dist/interaction_client/PopupClient.d.ts.map +1 -0
- package/dist/interaction_client/PopupClient.js +234 -0
- package/dist/interaction_client/PopupClient.js.map +1 -0
- package/dist/interaction_client/RedirectClient.d.ts +42 -0
- package/dist/interaction_client/RedirectClient.d.ts.map +1 -0
- package/dist/interaction_client/RedirectClient.js +301 -0
- package/dist/interaction_client/RedirectClient.js.map +1 -0
- package/dist/interaction_client/SilentCacheClient.d.ts +22 -0
- package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -0
- package/dist/interaction_client/SilentCacheClient.js +85 -0
- package/dist/interaction_client/SilentCacheClient.js.map +1 -0
- package/dist/interaction_client/SilentIframeClient.d.ts +29 -0
- package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -0
- package/dist/interaction_client/SilentIframeClient.js +107 -0
- package/dist/interaction_client/SilentIframeClient.js.map +1 -0
- package/dist/interaction_client/SilentRefreshClient.d.ts +20 -0
- package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -0
- package/dist/interaction_client/SilentRefreshClient.js +76 -0
- package/dist/interaction_client/SilentRefreshClient.js.map +1 -0
- package/dist/interaction_client/StandardInteractionClient.d.ts +66 -0
- package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -0
- package/dist/interaction_client/StandardInteractionClient.js +249 -0
- package/dist/interaction_client/StandardInteractionClient.js.map +1 -0
- package/dist/interaction_handler/InteractionHandler.js +1 -1
- package/dist/interaction_handler/InteractionHandler.js.map +1 -1
- package/dist/interaction_handler/PopupHandler.d.ts +2 -0
- package/dist/interaction_handler/PopupHandler.d.ts.map +1 -1
- package/dist/interaction_handler/PopupHandler.js +3 -4
- package/dist/interaction_handler/PopupHandler.js.map +1 -1
- package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
- package/dist/interaction_handler/RedirectHandler.js +6 -5
- package/dist/interaction_handler/RedirectHandler.js.map +1 -1
- package/dist/interaction_handler/SilentHandler.js +1 -1
- package/dist/interaction_handler/SilentHandler.js.map +1 -1
- package/dist/navigation/NavigationClient.js +1 -1
- package/dist/navigation/NavigationClient.js.map +1 -1
- package/dist/network/FetchClient.js +1 -1
- package/dist/network/FetchClient.js.map +1 -1
- package/dist/network/XhrClient.js +1 -1
- package/dist/network/XhrClient.js.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.js +2 -2
- package/dist/packageMetadata.js.map +1 -1
- package/dist/request/EndSessionPopupRequest.d.ts +3 -0
- package/dist/request/EndSessionPopupRequest.d.ts.map +1 -1
- package/dist/request/PopupRequest.d.ts +3 -0
- package/dist/request/PopupRequest.d.ts.map +1 -1
- package/dist/request/RedirectRequest.d.ts.map +1 -1
- package/dist/utils/BrowserConstants.d.ts +12 -1
- package/dist/utils/BrowserConstants.d.ts.map +1 -1
- package/dist/utils/BrowserConstants.js +16 -3
- package/dist/utils/BrowserConstants.js.map +1 -1
- package/dist/utils/BrowserProtocolUtils.js +1 -1
- package/dist/utils/BrowserProtocolUtils.js.map +1 -1
- package/dist/utils/BrowserStringUtils.js +1 -1
- package/dist/utils/BrowserStringUtils.js.map +1 -1
- package/dist/utils/BrowserUtils.js +1 -1
- package/dist/utils/BrowserUtils.js.map +1 -1
- package/dist/utils/MathUtils.js +1 -1
- package/dist/utils/MathUtils.js.map +1 -1
- package/dist/utils/PopupUtils.d.ts +26 -2
- package/dist/utils/PopupUtils.d.ts.map +1 -1
- package/dist/utils/PopupUtils.js +42 -15
- package/dist/utils/PopupUtils.js.map +1 -1
- package/lib/msal-browser.js +4505 -3045
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +42 -42
- package/package.json +8 -2
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
/*! @azure/msal-browser v2.
|
|
1
|
+
/*! @azure/msal-browser v2.19.0 2021-11-02 */
|
|
2
2
|
'use strict';
|
|
3
|
-
import { __awaiter, __generator
|
|
3
|
+
import { __awaiter, __generator } from '../_virtual/_tslib.js';
|
|
4
4
|
import { CryptoOps } from '../crypto/CryptoOps.js';
|
|
5
|
-
import {
|
|
5
|
+
import { StringUtils, Logger, DEFAULT_CRYPTO_IMPLEMENTATION, Constants, ServerError, InteractionRequiredAuthError } from '@azure/msal-common';
|
|
6
6
|
import { BrowserCacheManager, DEFAULT_BROWSER_CACHE_MANAGER } from '../cache/BrowserCacheManager.js';
|
|
7
7
|
import { buildConfiguration } from '../config/Configuration.js';
|
|
8
|
-
import { InteractionType, TemporaryCacheKeys, ApiId,
|
|
8
|
+
import { InteractionType, TemporaryCacheKeys, ApiId, BrowserCacheLocation, BrowserConstants } from '../utils/BrowserConstants.js';
|
|
9
9
|
import { BrowserUtils } from '../utils/BrowserUtils.js';
|
|
10
|
-
import { BrowserProtocolUtils } from '../utils/BrowserProtocolUtils.js';
|
|
11
|
-
import { RedirectHandler } from '../interaction_handler/RedirectHandler.js';
|
|
12
|
-
import { PopupHandler } from '../interaction_handler/PopupHandler.js';
|
|
13
|
-
import { SilentHandler } from '../interaction_handler/SilentHandler.js';
|
|
14
|
-
import { BrowserAuthError } from '../error/BrowserAuthError.js';
|
|
15
10
|
import { name, version } from '../packageMetadata.js';
|
|
16
11
|
import { EventType } from '../event/EventType.js';
|
|
17
12
|
import { BrowserConfigurationAuthError } from '../error/BrowserConfigurationAuthError.js';
|
|
18
|
-
import { PopupUtils } from '../utils/PopupUtils.js';
|
|
19
13
|
import { EventHandler } from '../event/EventHandler.js';
|
|
14
|
+
import { PopupClient } from '../interaction_client/PopupClient.js';
|
|
15
|
+
import { RedirectClient } from '../interaction_client/RedirectClient.js';
|
|
16
|
+
import { SilentIframeClient } from '../interaction_client/SilentIframeClient.js';
|
|
17
|
+
import { SilentRefreshClient } from '../interaction_client/SilentRefreshClient.js';
|
|
18
|
+
import { TokenCache } from '../cache/TokenCache.js';
|
|
20
19
|
|
|
21
20
|
/*
|
|
22
21
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -62,12 +61,14 @@ var ClientApplication = /** @class */ (function () {
|
|
|
62
61
|
// Initialize redirectResponse Map
|
|
63
62
|
this.redirectResponse = new Map();
|
|
64
63
|
// Initialize the crypto class.
|
|
65
|
-
this.browserCrypto = this.isBrowserEnvironment ? new CryptoOps() : DEFAULT_CRYPTO_IMPLEMENTATION;
|
|
64
|
+
this.browserCrypto = this.isBrowserEnvironment ? new CryptoOps(this.logger) : DEFAULT_CRYPTO_IMPLEMENTATION;
|
|
66
65
|
this.eventHandler = new EventHandler(this.logger, this.browserCrypto);
|
|
67
66
|
// Initialize the browser storage class.
|
|
68
67
|
this.browserStorage = this.isBrowserEnvironment ?
|
|
69
68
|
new BrowserCacheManager(this.config.auth.clientId, this.config.cache, this.browserCrypto, this.logger) :
|
|
70
69
|
DEFAULT_BROWSER_CACHE_MANAGER(this.config.auth.clientId, this.logger);
|
|
70
|
+
// Initialize the token cache
|
|
71
|
+
this.tokenCache = new TokenCache(this.config, this.browserStorage, this.logger, this.browserCrypto);
|
|
71
72
|
}
|
|
72
73
|
// #region Redirect Flow
|
|
73
74
|
/**
|
|
@@ -79,18 +80,20 @@ var ClientApplication = /** @class */ (function () {
|
|
|
79
80
|
*/
|
|
80
81
|
ClientApplication.prototype.handleRedirectPromise = function (hash) {
|
|
81
82
|
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
-
var loggedInAccounts, redirectResponseKey, response;
|
|
83
|
+
var loggedInAccounts, redirectResponseKey, response, correlationId, redirectClient;
|
|
83
84
|
var _this = this;
|
|
84
85
|
return __generator(this, function (_a) {
|
|
85
|
-
this.eventHandler.emitEvent(EventType.HANDLE_REDIRECT_START, InteractionType.Redirect);
|
|
86
86
|
this.logger.verbose("handleRedirectPromise called");
|
|
87
87
|
loggedInAccounts = this.getAllAccounts();
|
|
88
88
|
if (this.isBrowserEnvironment) {
|
|
89
89
|
redirectResponseKey = hash || Constants.EMPTY_STRING;
|
|
90
90
|
response = this.redirectResponse.get(redirectResponseKey);
|
|
91
91
|
if (typeof response === "undefined") {
|
|
92
|
+
this.eventHandler.emitEvent(EventType.HANDLE_REDIRECT_START, InteractionType.Redirect);
|
|
92
93
|
this.logger.verbose("handleRedirectPromise has been called for the first time, storing the promise");
|
|
93
|
-
|
|
94
|
+
correlationId = this.browserStorage.getTemporaryCache(TemporaryCacheKeys.CORRELATION_ID, true) || "";
|
|
95
|
+
redirectClient = new RedirectClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, correlationId);
|
|
96
|
+
response = redirectClient.handleRedirectPromise(hash)
|
|
94
97
|
.then(function (result) {
|
|
95
98
|
if (result) {
|
|
96
99
|
// Emit login event if number of accounts change
|
|
@@ -130,175 +133,6 @@ var ClientApplication = /** @class */ (function () {
|
|
|
130
133
|
});
|
|
131
134
|
});
|
|
132
135
|
};
|
|
133
|
-
/**
|
|
134
|
-
* Checks if navigateToLoginRequestUrl is set, and:
|
|
135
|
-
* - if true, performs logic to cache and navigate
|
|
136
|
-
* - if false, handles hash string and parses response
|
|
137
|
-
* @param hash
|
|
138
|
-
*/
|
|
139
|
-
ClientApplication.prototype.handleRedirectResponse = function (hash) {
|
|
140
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
141
|
-
var responseHash, state, loginRequestUrl, loginRequestUrlNormalized, currentUrlNormalized, handleHashResult, navigationOptions, processHashOnRedirect, homepage;
|
|
142
|
-
return __generator(this, function (_a) {
|
|
143
|
-
switch (_a.label) {
|
|
144
|
-
case 0:
|
|
145
|
-
if (!this.interactionInProgress()) {
|
|
146
|
-
this.logger.info("handleRedirectPromise called but there is no interaction in progress, returning null.");
|
|
147
|
-
return [2 /*return*/, null];
|
|
148
|
-
}
|
|
149
|
-
responseHash = this.getRedirectResponseHash(hash || window.location.hash);
|
|
150
|
-
if (!responseHash) {
|
|
151
|
-
// Not a recognized server response hash or hash not associated with a redirect request
|
|
152
|
-
this.logger.info("handleRedirectPromise did not detect a response hash as a result of a redirect. Cleaning temporary cache.");
|
|
153
|
-
this.browserStorage.cleanRequestByInteractionType(InteractionType.Redirect);
|
|
154
|
-
return [2 /*return*/, null];
|
|
155
|
-
}
|
|
156
|
-
try {
|
|
157
|
-
state = this.validateAndExtractStateFromHash(responseHash, InteractionType.Redirect);
|
|
158
|
-
BrowserUtils.clearHash(window);
|
|
159
|
-
this.logger.verbose("State extracted from hash");
|
|
160
|
-
}
|
|
161
|
-
catch (e) {
|
|
162
|
-
this.logger.info("handleRedirectPromise was unable to extract state due to: " + e);
|
|
163
|
-
this.browserStorage.cleanRequestByInteractionType(InteractionType.Redirect);
|
|
164
|
-
return [2 /*return*/, null];
|
|
165
|
-
}
|
|
166
|
-
loginRequestUrl = this.browserStorage.getTemporaryCache(TemporaryCacheKeys.ORIGIN_URI, true) || "";
|
|
167
|
-
loginRequestUrlNormalized = UrlString.removeHashFromUrl(loginRequestUrl);
|
|
168
|
-
currentUrlNormalized = UrlString.removeHashFromUrl(window.location.href);
|
|
169
|
-
if (!(loginRequestUrlNormalized === currentUrlNormalized && this.config.auth.navigateToLoginRequestUrl)) return [3 /*break*/, 2];
|
|
170
|
-
// We are on the page we need to navigate to - handle hash
|
|
171
|
-
this.logger.verbose("Current page is loginRequestUrl, handling hash");
|
|
172
|
-
return [4 /*yield*/, this.handleHash(responseHash, state)];
|
|
173
|
-
case 1:
|
|
174
|
-
handleHashResult = _a.sent();
|
|
175
|
-
if (loginRequestUrl.indexOf("#") > -1) {
|
|
176
|
-
// Replace current hash with non-msal hash, if present
|
|
177
|
-
BrowserUtils.replaceHash(loginRequestUrl);
|
|
178
|
-
}
|
|
179
|
-
return [2 /*return*/, handleHashResult];
|
|
180
|
-
case 2:
|
|
181
|
-
if (!!this.config.auth.navigateToLoginRequestUrl) return [3 /*break*/, 3];
|
|
182
|
-
this.logger.verbose("NavigateToLoginRequestUrl set to false, handling hash");
|
|
183
|
-
return [2 /*return*/, this.handleHash(responseHash, state)];
|
|
184
|
-
case 3:
|
|
185
|
-
if (!!BrowserUtils.isInIframe()) return [3 /*break*/, 8];
|
|
186
|
-
/*
|
|
187
|
-
* Returned from authority using redirect - need to perform navigation before processing response
|
|
188
|
-
* Cache the hash to be retrieved after the next redirect
|
|
189
|
-
*/
|
|
190
|
-
this.browserStorage.setTemporaryCache(TemporaryCacheKeys.URL_HASH, responseHash, true);
|
|
191
|
-
navigationOptions = {
|
|
192
|
-
apiId: ApiId.handleRedirectPromise,
|
|
193
|
-
timeout: this.config.system.redirectNavigationTimeout,
|
|
194
|
-
noHistory: true
|
|
195
|
-
};
|
|
196
|
-
processHashOnRedirect = true;
|
|
197
|
-
if (!(!loginRequestUrl || loginRequestUrl === "null")) return [3 /*break*/, 5];
|
|
198
|
-
homepage = BrowserUtils.getHomepage();
|
|
199
|
-
// Cache the homepage under ORIGIN_URI to ensure cached hash is processed on homepage
|
|
200
|
-
this.browserStorage.setTemporaryCache(TemporaryCacheKeys.ORIGIN_URI, homepage, true);
|
|
201
|
-
this.logger.warning("Unable to get valid login request url from cache, redirecting to home page");
|
|
202
|
-
return [4 /*yield*/, this.navigationClient.navigateInternal(homepage, navigationOptions)];
|
|
203
|
-
case 4:
|
|
204
|
-
processHashOnRedirect = _a.sent();
|
|
205
|
-
return [3 /*break*/, 7];
|
|
206
|
-
case 5:
|
|
207
|
-
// Navigate to page that initiated the redirect request
|
|
208
|
-
this.logger.verbose("Navigating to loginRequestUrl: " + loginRequestUrl);
|
|
209
|
-
return [4 /*yield*/, this.navigationClient.navigateInternal(loginRequestUrl, navigationOptions)];
|
|
210
|
-
case 6:
|
|
211
|
-
processHashOnRedirect = _a.sent();
|
|
212
|
-
_a.label = 7;
|
|
213
|
-
case 7:
|
|
214
|
-
// If navigateInternal implementation returns false, handle the hash now
|
|
215
|
-
if (!processHashOnRedirect) {
|
|
216
|
-
return [2 /*return*/, this.handleHash(responseHash, state)];
|
|
217
|
-
}
|
|
218
|
-
_a.label = 8;
|
|
219
|
-
case 8: return [2 /*return*/, null];
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
};
|
|
224
|
-
/**
|
|
225
|
-
* Gets the response hash for a redirect request
|
|
226
|
-
* Returns null if interactionType in the state value is not "redirect" or the hash does not contain known properties
|
|
227
|
-
* @param hash
|
|
228
|
-
*/
|
|
229
|
-
ClientApplication.prototype.getRedirectResponseHash = function (hash) {
|
|
230
|
-
this.logger.verbose("getRedirectResponseHash called");
|
|
231
|
-
// Get current location hash from window or cache.
|
|
232
|
-
var isResponseHash = UrlString.hashContainsKnownProperties(hash);
|
|
233
|
-
var cachedHash = this.browserStorage.getTemporaryCache(TemporaryCacheKeys.URL_HASH, true);
|
|
234
|
-
this.browserStorage.removeItem(this.browserStorage.generateCacheKey(TemporaryCacheKeys.URL_HASH));
|
|
235
|
-
if (isResponseHash) {
|
|
236
|
-
this.logger.verbose("Hash contains known properties, returning response hash");
|
|
237
|
-
return hash;
|
|
238
|
-
}
|
|
239
|
-
this.logger.verbose("Hash does not contain known properties, returning cached hash");
|
|
240
|
-
return cachedHash;
|
|
241
|
-
};
|
|
242
|
-
/**
|
|
243
|
-
* @param hash
|
|
244
|
-
* @param interactionType
|
|
245
|
-
*/
|
|
246
|
-
ClientApplication.prototype.validateAndExtractStateFromHash = function (hash, interactionType, requestCorrelationId) {
|
|
247
|
-
this.logger.verbose("validateAndExtractStateFromHash called", requestCorrelationId);
|
|
248
|
-
// Deserialize hash fragment response parameters.
|
|
249
|
-
var serverParams = UrlString.getDeserializedHash(hash);
|
|
250
|
-
if (!serverParams.state) {
|
|
251
|
-
throw BrowserAuthError.createHashDoesNotContainStateError();
|
|
252
|
-
}
|
|
253
|
-
var platformStateObj = BrowserProtocolUtils.extractBrowserRequestState(this.browserCrypto, serverParams.state);
|
|
254
|
-
if (!platformStateObj) {
|
|
255
|
-
throw BrowserAuthError.createUnableToParseStateError();
|
|
256
|
-
}
|
|
257
|
-
if (platformStateObj.interactionType !== interactionType) {
|
|
258
|
-
throw BrowserAuthError.createStateInteractionTypeMismatchError();
|
|
259
|
-
}
|
|
260
|
-
this.logger.verbose("Returning state from hash", requestCorrelationId);
|
|
261
|
-
return serverParams.state;
|
|
262
|
-
};
|
|
263
|
-
/**
|
|
264
|
-
* Checks if hash exists and handles in window.
|
|
265
|
-
* @param hash
|
|
266
|
-
* @param state
|
|
267
|
-
*/
|
|
268
|
-
ClientApplication.prototype.handleHash = function (hash, state) {
|
|
269
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
270
|
-
var cachedRequest, browserRequestLogger, serverTelemetryManager, currentAuthority, authClient, interactionHandler, e_1;
|
|
271
|
-
return __generator(this, function (_a) {
|
|
272
|
-
switch (_a.label) {
|
|
273
|
-
case 0:
|
|
274
|
-
cachedRequest = this.browserStorage.getCachedRequest(state, this.browserCrypto);
|
|
275
|
-
browserRequestLogger = this.logger.clone(name, version, cachedRequest.correlationId);
|
|
276
|
-
browserRequestLogger.verbose("handleHash called, retrieved cached request");
|
|
277
|
-
serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.handleRedirectPromise, cachedRequest.correlationId);
|
|
278
|
-
_a.label = 1;
|
|
279
|
-
case 1:
|
|
280
|
-
_a.trys.push([1, 4, , 5]);
|
|
281
|
-
currentAuthority = this.browserStorage.getCachedAuthority(state);
|
|
282
|
-
if (!currentAuthority) {
|
|
283
|
-
throw BrowserAuthError.createNoCachedAuthorityError();
|
|
284
|
-
}
|
|
285
|
-
return [4 /*yield*/, this.createAuthCodeClient(serverTelemetryManager, currentAuthority, cachedRequest.correlationId)];
|
|
286
|
-
case 2:
|
|
287
|
-
authClient = _a.sent();
|
|
288
|
-
browserRequestLogger.verbose("Auth code client created");
|
|
289
|
-
interactionHandler = new RedirectHandler(authClient, this.browserStorage, cachedRequest, browserRequestLogger, this.browserCrypto);
|
|
290
|
-
return [4 /*yield*/, interactionHandler.handleCodeResponse(hash, state, authClient.authority, this.networkClient, this.config.auth.clientId)];
|
|
291
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
292
|
-
case 4:
|
|
293
|
-
e_1 = _a.sent();
|
|
294
|
-
serverTelemetryManager.cacheFailedRequest(e_1);
|
|
295
|
-
this.browserStorage.cleanRequestByInteractionType(InteractionType.Redirect);
|
|
296
|
-
throw e_1;
|
|
297
|
-
case 5: return [2 /*return*/];
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
};
|
|
302
136
|
/**
|
|
303
137
|
* Use when you want to obtain an access_token for your API by redirecting the user's browser window to the authorization endpoint. This function redirects
|
|
304
138
|
* the page, so any code that follows this function will not execute.
|
|
@@ -310,60 +144,30 @@ var ClientApplication = /** @class */ (function () {
|
|
|
310
144
|
*/
|
|
311
145
|
ClientApplication.prototype.acquireTokenRedirect = function (request) {
|
|
312
146
|
return __awaiter(this, void 0, void 0, function () {
|
|
313
|
-
var isLoggedIn,
|
|
147
|
+
var isLoggedIn, redirectClient;
|
|
148
|
+
var _this = this;
|
|
314
149
|
return __generator(this, function (_a) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
validRequest = this.preflightInteractiveRequest(request, InteractionType.Redirect);
|
|
328
|
-
browserRequestLogger = this.logger.clone(name, version, validRequest.correlationId);
|
|
329
|
-
serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenRedirect, validRequest.correlationId);
|
|
330
|
-
_a.label = 1;
|
|
331
|
-
case 1:
|
|
332
|
-
_a.trys.push([1, 5, , 6]);
|
|
333
|
-
return [4 /*yield*/, this.initializeAuthorizationCodeRequest(validRequest)];
|
|
334
|
-
case 2:
|
|
335
|
-
authCodeRequest = _a.sent();
|
|
336
|
-
return [4 /*yield*/, this.createAuthCodeClient(serverTelemetryManager, validRequest.authority, validRequest.correlationId)];
|
|
337
|
-
case 3:
|
|
338
|
-
authClient = _a.sent();
|
|
339
|
-
browserRequestLogger.verbose("Auth code client created");
|
|
340
|
-
interactionHandler = new RedirectHandler(authClient, this.browserStorage, authCodeRequest, browserRequestLogger, this.browserCrypto);
|
|
341
|
-
return [4 /*yield*/, authClient.getAuthCodeUrl(validRequest)];
|
|
342
|
-
case 4:
|
|
343
|
-
navigateUrl = _a.sent();
|
|
344
|
-
redirectStartPage = this.getRedirectStartPage(request.redirectStartPage);
|
|
345
|
-
browserRequestLogger.verbosePii("Redirect start page: " + redirectStartPage);
|
|
346
|
-
// Show the UI once the url has been created. Response will come back in the hash, which will be handled in the handleRedirectCallback function.
|
|
347
|
-
return [2 /*return*/, interactionHandler.initiateAuthRequest(navigateUrl, {
|
|
348
|
-
navigationClient: this.navigationClient,
|
|
349
|
-
redirectTimeout: this.config.system.redirectNavigationTimeout,
|
|
350
|
-
redirectStartPage: redirectStartPage,
|
|
351
|
-
onRedirectNavigate: request.onRedirectNavigate
|
|
352
|
-
})];
|
|
353
|
-
case 5:
|
|
354
|
-
e_2 = _a.sent();
|
|
150
|
+
// Preflight request
|
|
151
|
+
this.preflightBrowserEnvironmentCheck(InteractionType.Redirect);
|
|
152
|
+
this.logger.verbose("acquireTokenRedirect called");
|
|
153
|
+
isLoggedIn = this.getAllAccounts().length > 0;
|
|
154
|
+
if (isLoggedIn) {
|
|
155
|
+
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_START, InteractionType.Redirect, request);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this.eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Redirect, request);
|
|
159
|
+
}
|
|
160
|
+
redirectClient = new RedirectClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, request.correlationId);
|
|
161
|
+
return [2 /*return*/, redirectClient.acquireToken(request).catch(function (e) {
|
|
355
162
|
// If logged in, emit acquire token events
|
|
356
163
|
if (isLoggedIn) {
|
|
357
|
-
|
|
164
|
+
_this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Redirect, null, e);
|
|
358
165
|
}
|
|
359
166
|
else {
|
|
360
|
-
|
|
167
|
+
_this.eventHandler.emitEvent(EventType.LOGIN_FAILURE, InteractionType.Redirect, null, e);
|
|
361
168
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
throw e_2;
|
|
365
|
-
case 6: return [2 /*return*/];
|
|
366
|
-
}
|
|
169
|
+
throw e;
|
|
170
|
+
})];
|
|
367
171
|
});
|
|
368
172
|
});
|
|
369
173
|
};
|
|
@@ -377,108 +181,43 @@ var ClientApplication = /** @class */ (function () {
|
|
|
377
181
|
* @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
|
|
378
182
|
*/
|
|
379
183
|
ClientApplication.prototype.acquireTokenPopup = function (request) {
|
|
380
|
-
var
|
|
184
|
+
var _this = this;
|
|
381
185
|
try {
|
|
382
186
|
this.preflightBrowserEnvironmentCheck(InteractionType.Popup);
|
|
383
187
|
this.logger.verbose("acquireTokenPopup called", request.correlationId);
|
|
384
|
-
validRequest = this.preflightInteractiveRequest(request, InteractionType.Popup);
|
|
385
188
|
}
|
|
386
189
|
catch (e) {
|
|
387
190
|
// Since this function is syncronous we need to reject
|
|
388
191
|
return Promise.reject(e);
|
|
389
192
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
if (
|
|
393
|
-
this.
|
|
394
|
-
return this.acquireTokenPopupAsync(validRequest, popupName);
|
|
193
|
+
// If logged in, emit acquire token events
|
|
194
|
+
var loggedInAccounts = this.getAllAccounts();
|
|
195
|
+
if (loggedInAccounts.length > 0) {
|
|
196
|
+
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_START, InteractionType.Popup, request);
|
|
395
197
|
}
|
|
396
198
|
else {
|
|
397
|
-
|
|
398
|
-
this.logger.verbose("asyncPopup set to false, opening popup before acquiring token", validRequest.correlationId);
|
|
399
|
-
var popup = PopupUtils.openSizedPopup("about:blank", popupName);
|
|
400
|
-
return this.acquireTokenPopupAsync(validRequest, popupName, popup);
|
|
199
|
+
this.eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Popup, request);
|
|
401
200
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
else {
|
|
423
|
-
this.eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Popup, validRequest);
|
|
424
|
-
}
|
|
425
|
-
browserRequestLogger = this.logger.clone(name, version, validRequest.correlationId);
|
|
426
|
-
serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenPopup, validRequest.correlationId);
|
|
427
|
-
_a.label = 1;
|
|
428
|
-
case 1:
|
|
429
|
-
_a.trys.push([1, 7, , 8]);
|
|
430
|
-
return [4 /*yield*/, this.initializeAuthorizationCodeRequest(validRequest)];
|
|
431
|
-
case 2:
|
|
432
|
-
authCodeRequest = _a.sent();
|
|
433
|
-
return [4 /*yield*/, this.createAuthCodeClient(serverTelemetryManager, validRequest.authority, validRequest.correlationId)];
|
|
434
|
-
case 3:
|
|
435
|
-
authClient = _a.sent();
|
|
436
|
-
browserRequestLogger.verbose("Auth code client created");
|
|
437
|
-
return [4 /*yield*/, authClient.getAuthCodeUrl(validRequest)];
|
|
438
|
-
case 4:
|
|
439
|
-
navigateUrl = _a.sent();
|
|
440
|
-
interactionHandler = new PopupHandler(authClient, this.browserStorage, authCodeRequest, browserRequestLogger);
|
|
441
|
-
popupParameters = {
|
|
442
|
-
popup: popup,
|
|
443
|
-
popupName: popupName
|
|
444
|
-
};
|
|
445
|
-
popupWindow = interactionHandler.initiateAuthRequest(navigateUrl, popupParameters);
|
|
446
|
-
this.eventHandler.emitEvent(EventType.POPUP_OPENED, InteractionType.Popup, { popupWindow: popupWindow }, null);
|
|
447
|
-
return [4 /*yield*/, interactionHandler.monitorPopupForHash(popupWindow)];
|
|
448
|
-
case 5:
|
|
449
|
-
hash = _a.sent();
|
|
450
|
-
state = this.validateAndExtractStateFromHash(hash, InteractionType.Popup, validRequest.correlationId);
|
|
451
|
-
// Remove throttle if it exists
|
|
452
|
-
ThrottlingUtils.removeThrottle(this.browserStorage, this.config.auth.clientId, authCodeRequest.authority, authCodeRequest.scopes);
|
|
453
|
-
return [4 /*yield*/, interactionHandler.handleCodeResponse(hash, state, authClient.authority, this.networkClient)];
|
|
454
|
-
case 6:
|
|
455
|
-
result = _a.sent();
|
|
456
|
-
isLoggingIn = loggedInAccounts.length < this.getAllAccounts().length;
|
|
457
|
-
if (isLoggingIn) {
|
|
458
|
-
this.eventHandler.emitEvent(EventType.LOGIN_SUCCESS, InteractionType.Popup, result);
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
461
|
-
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, InteractionType.Popup, result);
|
|
462
|
-
}
|
|
463
|
-
return [2 /*return*/, result];
|
|
464
|
-
case 7:
|
|
465
|
-
e_3 = _a.sent();
|
|
466
|
-
if (loggedInAccounts.length > 0) {
|
|
467
|
-
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Popup, null, e_3);
|
|
468
|
-
}
|
|
469
|
-
else {
|
|
470
|
-
this.eventHandler.emitEvent(EventType.LOGIN_FAILURE, InteractionType.Popup, null, e_3);
|
|
471
|
-
}
|
|
472
|
-
if (popup) {
|
|
473
|
-
// Close the synchronous popup if an error is thrown before the window unload event is registered
|
|
474
|
-
popup.close();
|
|
475
|
-
}
|
|
476
|
-
serverTelemetryManager.cacheFailedRequest(e_3);
|
|
477
|
-
this.browserStorage.cleanRequestByState(validRequest.state);
|
|
478
|
-
throw e_3;
|
|
479
|
-
case 8: return [2 /*return*/];
|
|
480
|
-
}
|
|
481
|
-
});
|
|
201
|
+
var popupClient = new PopupClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, request.correlationId);
|
|
202
|
+
return popupClient.acquireToken(request).then(function (result) {
|
|
203
|
+
// If logged in, emit acquire token events
|
|
204
|
+
var isLoggingIn = loggedInAccounts.length < _this.getAllAccounts().length;
|
|
205
|
+
if (isLoggingIn) {
|
|
206
|
+
_this.eventHandler.emitEvent(EventType.LOGIN_SUCCESS, InteractionType.Popup, result);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
_this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, InteractionType.Popup, result);
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
}).catch(function (e) {
|
|
213
|
+
if (loggedInAccounts.length > 0) {
|
|
214
|
+
_this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Popup, null, e);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
_this.eventHandler.emitEvent(EventType.LOGIN_FAILURE, InteractionType.Popup, null, e);
|
|
218
|
+
}
|
|
219
|
+
// Since this function is syncronous we need to reject
|
|
220
|
+
return Promise.reject(e);
|
|
482
221
|
});
|
|
483
222
|
};
|
|
484
223
|
// #endregion
|
|
@@ -500,7 +239,7 @@ var ClientApplication = /** @class */ (function () {
|
|
|
500
239
|
*/
|
|
501
240
|
ClientApplication.prototype.ssoSilent = function (request) {
|
|
502
241
|
return __awaiter(this, void 0, void 0, function () {
|
|
503
|
-
var silentTokenResult,
|
|
242
|
+
var silentIframeClient, silentTokenResult, e_1;
|
|
504
243
|
return __generator(this, function (_a) {
|
|
505
244
|
switch (_a.label) {
|
|
506
245
|
case 0:
|
|
@@ -510,68 +249,21 @@ var ClientApplication = /** @class */ (function () {
|
|
|
510
249
|
_a.label = 1;
|
|
511
250
|
case 1:
|
|
512
251
|
_a.trys.push([1, 3, , 4]);
|
|
513
|
-
|
|
252
|
+
silentIframeClient = new SilentIframeClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, ApiId.ssoSilent, request.correlationId);
|
|
253
|
+
return [4 /*yield*/, silentIframeClient.acquireToken(request)];
|
|
514
254
|
case 2:
|
|
515
255
|
silentTokenResult = _a.sent();
|
|
516
256
|
this.eventHandler.emitEvent(EventType.SSO_SILENT_SUCCESS, InteractionType.Silent, silentTokenResult);
|
|
517
257
|
return [2 /*return*/, silentTokenResult];
|
|
518
258
|
case 3:
|
|
519
|
-
|
|
520
|
-
this.eventHandler.emitEvent(EventType.SSO_SILENT_FAILURE, InteractionType.Silent, null,
|
|
521
|
-
throw
|
|
259
|
+
e_1 = _a.sent();
|
|
260
|
+
this.eventHandler.emitEvent(EventType.SSO_SILENT_FAILURE, InteractionType.Silent, null, e_1);
|
|
261
|
+
throw e_1;
|
|
522
262
|
case 4: return [2 /*return*/];
|
|
523
263
|
}
|
|
524
264
|
});
|
|
525
265
|
});
|
|
526
266
|
};
|
|
527
|
-
/**
|
|
528
|
-
* This function uses a hidden iframe to fetch an authorization code from the eSTS. To be used for silent refresh token acquisition and renewal.
|
|
529
|
-
* @param request
|
|
530
|
-
* @param apiId - ApiId of the calling function. Used for telemetry.
|
|
531
|
-
*/
|
|
532
|
-
ClientApplication.prototype.acquireTokenByIframe = function (request, apiId) {
|
|
533
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
534
|
-
var silentRequest, browserRequestLogger, serverTelemetryManager, authCodeRequest, authClient, navigateUrl, e_5;
|
|
535
|
-
return __generator(this, function (_a) {
|
|
536
|
-
switch (_a.label) {
|
|
537
|
-
case 0:
|
|
538
|
-
this.logger.verbose("acquireTokenByIframe called", request.correlationId);
|
|
539
|
-
// Check that we have some SSO data
|
|
540
|
-
if (StringUtils.isEmpty(request.loginHint) && StringUtils.isEmpty(request.sid) && (!request.account || StringUtils.isEmpty(request.account.username))) {
|
|
541
|
-
throw BrowserAuthError.createSilentSSOInsufficientInfoError();
|
|
542
|
-
}
|
|
543
|
-
// Check that prompt is set to none, throw error if it is set to anything else.
|
|
544
|
-
if (request.prompt && request.prompt !== PromptValue.NONE) {
|
|
545
|
-
throw BrowserAuthError.createSilentPromptValueError(request.prompt);
|
|
546
|
-
}
|
|
547
|
-
silentRequest = this.initializeAuthorizationRequest(__assign(__assign({}, request), { prompt: PromptValue.NONE }), InteractionType.Silent);
|
|
548
|
-
browserRequestLogger = this.logger.clone(name, version, silentRequest.correlationId);
|
|
549
|
-
serverTelemetryManager = this.initializeServerTelemetryManager(apiId, silentRequest.correlationId);
|
|
550
|
-
_a.label = 1;
|
|
551
|
-
case 1:
|
|
552
|
-
_a.trys.push([1, 6, , 7]);
|
|
553
|
-
return [4 /*yield*/, this.initializeAuthorizationCodeRequest(silentRequest)];
|
|
554
|
-
case 2:
|
|
555
|
-
authCodeRequest = _a.sent();
|
|
556
|
-
return [4 /*yield*/, this.createAuthCodeClient(serverTelemetryManager, silentRequest.authority, silentRequest.correlationId)];
|
|
557
|
-
case 3:
|
|
558
|
-
authClient = _a.sent();
|
|
559
|
-
browserRequestLogger.verbose("Auth code client created");
|
|
560
|
-
return [4 /*yield*/, authClient.getAuthCodeUrl(silentRequest)];
|
|
561
|
-
case 4:
|
|
562
|
-
navigateUrl = _a.sent();
|
|
563
|
-
return [4 /*yield*/, this.silentTokenHelper(navigateUrl, authCodeRequest, authClient, browserRequestLogger)];
|
|
564
|
-
case 5: return [2 /*return*/, _a.sent()];
|
|
565
|
-
case 6:
|
|
566
|
-
e_5 = _a.sent();
|
|
567
|
-
serverTelemetryManager.cacheFailedRequest(e_5);
|
|
568
|
-
this.browserStorage.cleanRequestByState(silentRequest.state);
|
|
569
|
-
throw e_5;
|
|
570
|
-
case 7: return [2 /*return*/];
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
});
|
|
574
|
-
};
|
|
575
267
|
/**
|
|
576
268
|
* Use this function to obtain a token before every call to the API / resource provider
|
|
577
269
|
*
|
|
@@ -585,66 +277,24 @@ var ClientApplication = /** @class */ (function () {
|
|
|
585
277
|
*/
|
|
586
278
|
ClientApplication.prototype.acquireTokenByRefreshToken = function (request) {
|
|
587
279
|
return __awaiter(this, void 0, void 0, function () {
|
|
588
|
-
var
|
|
589
|
-
|
|
590
|
-
switch (_a.label) {
|
|
591
|
-
case 0:
|
|
592
|
-
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_NETWORK_START, InteractionType.Silent, request);
|
|
593
|
-
// block the reload if it occurred inside a hidden iframe
|
|
594
|
-
BrowserUtils.blockReloadInHiddenIframes();
|
|
595
|
-
silentRequest = __assign(__assign({}, request), this.initializeBaseRequest(request));
|
|
596
|
-
browserRequestLogger = this.logger.clone(name, version, silentRequest.correlationId);
|
|
597
|
-
serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent_silentFlow, silentRequest.correlationId);
|
|
598
|
-
_a.label = 1;
|
|
599
|
-
case 1:
|
|
600
|
-
_a.trys.push([1, 4, , 7]);
|
|
601
|
-
return [4 /*yield*/, this.createRefreshTokenClient(serverTelemetryManager, silentRequest.authority, silentRequest.correlationId)];
|
|
602
|
-
case 2:
|
|
603
|
-
refreshTokenClient = _a.sent();
|
|
604
|
-
browserRequestLogger.verbose("Refresh token client created");
|
|
605
|
-
return [4 /*yield*/, refreshTokenClient.acquireTokenByRefreshToken(silentRequest)];
|
|
606
|
-
case 3:
|
|
607
|
-
// Send request to renew token. Auth module will throw errors if token cannot be renewed.
|
|
608
|
-
return [2 /*return*/, _a.sent()];
|
|
609
|
-
case 4:
|
|
610
|
-
e_6 = _a.sent();
|
|
611
|
-
serverTelemetryManager.cacheFailedRequest(e_6);
|
|
612
|
-
isServerError = e_6 instanceof ServerError;
|
|
613
|
-
isInteractionRequiredError = e_6 instanceof InteractionRequiredAuthError;
|
|
614
|
-
isInvalidGrantError = (e_6.errorCode === BrowserConstants.INVALID_GRANT_ERROR);
|
|
615
|
-
if (!(isServerError && isInvalidGrantError && !isInteractionRequiredError)) return [3 /*break*/, 6];
|
|
616
|
-
browserRequestLogger.verbose("Refresh token expired or invalid, attempting acquire token by iframe");
|
|
617
|
-
return [4 /*yield*/, this.acquireTokenByIframe(request, ApiId.acquireTokenSilent_authCode)];
|
|
618
|
-
case 5: return [2 /*return*/, _a.sent()];
|
|
619
|
-
case 6: throw e_6;
|
|
620
|
-
case 7: return [2 /*return*/];
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
});
|
|
624
|
-
};
|
|
625
|
-
/**
|
|
626
|
-
* Helper which acquires an authorization code silently using a hidden iframe from given url
|
|
627
|
-
* using the scopes requested as part of the id, and exchanges the code for a set of OAuth tokens.
|
|
628
|
-
* @param navigateUrl
|
|
629
|
-
* @param userRequestScopes
|
|
630
|
-
*/
|
|
631
|
-
ClientApplication.prototype.silentTokenHelper = function (navigateUrl, authCodeRequest, authClient, browserRequestLogger) {
|
|
632
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
633
|
-
var silentHandler, msalFrame, hash, state;
|
|
280
|
+
var silentRefreshClient;
|
|
281
|
+
var _this = this;
|
|
634
282
|
return __generator(this, function (_a) {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
283
|
+
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_NETWORK_START, InteractionType.Silent, request);
|
|
284
|
+
// block the reload if it occurred inside a hidden iframe
|
|
285
|
+
BrowserUtils.blockReloadInHiddenIframes();
|
|
286
|
+
silentRefreshClient = new SilentRefreshClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, request.correlationId);
|
|
287
|
+
return [2 /*return*/, silentRefreshClient.acquireToken(request).catch(function (e) {
|
|
288
|
+
var isServerError = e instanceof ServerError;
|
|
289
|
+
var isInteractionRequiredError = e instanceof InteractionRequiredAuthError;
|
|
290
|
+
var isInvalidGrantError = (e.errorCode === BrowserConstants.INVALID_GRANT_ERROR);
|
|
291
|
+
if (isServerError && isInvalidGrantError && !isInteractionRequiredError) {
|
|
292
|
+
_this.logger.verbose("Refresh token expired or invalid, attempting acquire token by iframe", request.correlationId);
|
|
293
|
+
var silentIframeClient = new SilentIframeClient(_this.config, _this.browserStorage, _this.browserCrypto, _this.logger, _this.eventHandler, _this.navigationClient, ApiId.acquireTokenSilent_authCode, request.correlationId);
|
|
294
|
+
return silentIframeClient.acquireToken(request);
|
|
295
|
+
}
|
|
296
|
+
throw e;
|
|
297
|
+
})];
|
|
648
298
|
});
|
|
649
299
|
});
|
|
650
300
|
};
|
|
@@ -670,60 +320,11 @@ var ClientApplication = /** @class */ (function () {
|
|
|
670
320
|
*/
|
|
671
321
|
ClientApplication.prototype.logoutRedirect = function (logoutRequest) {
|
|
672
322
|
return __awaiter(this, void 0, void 0, function () {
|
|
673
|
-
var
|
|
323
|
+
var redirectClient;
|
|
674
324
|
return __generator(this, function (_a) {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
this.logger.verbose("logoutRedirect called", logoutRequest === null || logoutRequest === void 0 ? void 0 : logoutRequest.correlationId);
|
|
679
|
-
validLogoutRequest = this.initializeLogoutRequest(logoutRequest);
|
|
680
|
-
browserRequestLogger = this.logger.clone(name, version, validLogoutRequest.correlationId);
|
|
681
|
-
serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.logout, validLogoutRequest.correlationId);
|
|
682
|
-
_a.label = 1;
|
|
683
|
-
case 1:
|
|
684
|
-
_a.trys.push([1, 9, , 10]);
|
|
685
|
-
this.eventHandler.emitEvent(EventType.LOGOUT_START, InteractionType.Redirect, logoutRequest);
|
|
686
|
-
return [4 /*yield*/, this.createAuthCodeClient(serverTelemetryManager, logoutRequest && logoutRequest.authority, validLogoutRequest === null || validLogoutRequest === void 0 ? void 0 : validLogoutRequest.correlationId)];
|
|
687
|
-
case 2:
|
|
688
|
-
authClient = _a.sent();
|
|
689
|
-
browserRequestLogger.verbose("Auth code client created");
|
|
690
|
-
logoutUri = authClient.getLogoutUri(validLogoutRequest);
|
|
691
|
-
if (!validLogoutRequest.account || AccountEntity.accountInfoIsEqual(validLogoutRequest.account, this.getActiveAccount(), false)) {
|
|
692
|
-
browserRequestLogger.verbose("Setting active account to null");
|
|
693
|
-
this.setActiveAccount(null);
|
|
694
|
-
}
|
|
695
|
-
navigationOptions = {
|
|
696
|
-
apiId: ApiId.logout,
|
|
697
|
-
timeout: this.config.system.redirectNavigationTimeout,
|
|
698
|
-
noHistory: false
|
|
699
|
-
};
|
|
700
|
-
this.eventHandler.emitEvent(EventType.LOGOUT_SUCCESS, InteractionType.Redirect, validLogoutRequest);
|
|
701
|
-
if (!(logoutRequest && typeof logoutRequest.onRedirectNavigate === "function")) return [3 /*break*/, 6];
|
|
702
|
-
navigate = logoutRequest.onRedirectNavigate(logoutUri);
|
|
703
|
-
if (!(navigate !== false)) return [3 /*break*/, 4];
|
|
704
|
-
browserRequestLogger.verbose("Logout onRedirectNavigate did not return false, navigating");
|
|
705
|
-
return [4 /*yield*/, this.navigationClient.navigateExternal(logoutUri, navigationOptions)];
|
|
706
|
-
case 3:
|
|
707
|
-
_a.sent();
|
|
708
|
-
return [2 /*return*/];
|
|
709
|
-
case 4:
|
|
710
|
-
browserRequestLogger.verbose("Logout onRedirectNavigate returned false, stopping navigation");
|
|
711
|
-
_a.label = 5;
|
|
712
|
-
case 5: return [3 /*break*/, 8];
|
|
713
|
-
case 6: return [4 /*yield*/, this.navigationClient.navigateExternal(logoutUri, navigationOptions)];
|
|
714
|
-
case 7:
|
|
715
|
-
_a.sent();
|
|
716
|
-
return [2 /*return*/];
|
|
717
|
-
case 8: return [3 /*break*/, 10];
|
|
718
|
-
case 9:
|
|
719
|
-
e_7 = _a.sent();
|
|
720
|
-
serverTelemetryManager.cacheFailedRequest(e_7);
|
|
721
|
-
this.eventHandler.emitEvent(EventType.LOGOUT_FAILURE, InteractionType.Redirect, null, e_7);
|
|
722
|
-
throw e_7;
|
|
723
|
-
case 10:
|
|
724
|
-
this.eventHandler.emitEvent(EventType.LOGOUT_END, InteractionType.Redirect);
|
|
725
|
-
return [2 /*return*/];
|
|
726
|
-
}
|
|
325
|
+
this.preflightBrowserEnvironmentCheck(InteractionType.Redirect);
|
|
326
|
+
redirectClient = new RedirectClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, logoutRequest === null || logoutRequest === void 0 ? void 0 : logoutRequest.correlationId);
|
|
327
|
+
return [2 /*return*/, redirectClient.logout(logoutRequest)];
|
|
727
328
|
});
|
|
728
329
|
});
|
|
729
330
|
};
|
|
@@ -732,112 +333,15 @@ var ClientApplication = /** @class */ (function () {
|
|
|
732
333
|
* @param logoutRequest
|
|
733
334
|
*/
|
|
734
335
|
ClientApplication.prototype.logoutPopup = function (logoutRequest) {
|
|
735
|
-
var validLogoutRequest;
|
|
736
336
|
try {
|
|
737
337
|
this.preflightBrowserEnvironmentCheck(InteractionType.Popup);
|
|
738
|
-
this.logger.
|
|
739
|
-
|
|
338
|
+
var popupClient = new PopupClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, logoutRequest === null || logoutRequest === void 0 ? void 0 : logoutRequest.correlationId);
|
|
339
|
+
return popupClient.logout(logoutRequest);
|
|
740
340
|
}
|
|
741
341
|
catch (e) {
|
|
742
|
-
// Since this function is
|
|
342
|
+
// Since this function is syncronous we need to reject
|
|
743
343
|
return Promise.reject(e);
|
|
744
344
|
}
|
|
745
|
-
var popupName = PopupUtils.generateLogoutPopupName(this.config.auth.clientId, validLogoutRequest);
|
|
746
|
-
var popup;
|
|
747
|
-
// asyncPopups flag is true. Acquires token without first opening popup. Popup will be opened later asynchronously.
|
|
748
|
-
if (this.config.system.asyncPopups) {
|
|
749
|
-
this.logger.verbose("asyncPopups set to true", validLogoutRequest.correlationId);
|
|
750
|
-
}
|
|
751
|
-
else {
|
|
752
|
-
// asyncPopups flag is set to false. Opens popup before logging out.
|
|
753
|
-
this.logger.verbose("asyncPopup set to false, opening popup", validLogoutRequest.correlationId);
|
|
754
|
-
popup = PopupUtils.openSizedPopup("about:blank", popupName);
|
|
755
|
-
}
|
|
756
|
-
var authority = logoutRequest && logoutRequest.authority;
|
|
757
|
-
var mainWindowRedirectUri = logoutRequest && logoutRequest.mainWindowRedirectUri;
|
|
758
|
-
return this.logoutPopupAsync(validLogoutRequest, popupName, authority, popup, mainWindowRedirectUri);
|
|
759
|
-
};
|
|
760
|
-
/**
|
|
761
|
-
*
|
|
762
|
-
* @param request
|
|
763
|
-
* @param popupName
|
|
764
|
-
* @param requestAuthority
|
|
765
|
-
* @param popup
|
|
766
|
-
*/
|
|
767
|
-
ClientApplication.prototype.logoutPopupAsync = function (validRequest, popupName, requestAuthority, popup, mainWindowRedirectUri) {
|
|
768
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
769
|
-
var browserRequestLogger, serverTelemetryManager, authClient, logoutUri, popupUtils, popupWindow, e_8, navigationOptions, absoluteUrl, e_9;
|
|
770
|
-
return __generator(this, function (_a) {
|
|
771
|
-
switch (_a.label) {
|
|
772
|
-
case 0:
|
|
773
|
-
this.logger.verbose("logoutPopupAsync called", validRequest.correlationId);
|
|
774
|
-
this.eventHandler.emitEvent(EventType.LOGOUT_START, InteractionType.Popup, validRequest);
|
|
775
|
-
browserRequestLogger = this.logger.clone(name, version, validRequest.correlationId);
|
|
776
|
-
serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.logoutPopup, validRequest.correlationId);
|
|
777
|
-
_a.label = 1;
|
|
778
|
-
case 1:
|
|
779
|
-
_a.trys.push([1, 7, , 8]);
|
|
780
|
-
this.browserStorage.setTemporaryCache(TemporaryCacheKeys.INTERACTION_STATUS_KEY, BrowserConstants.INTERACTION_IN_PROGRESS_VALUE, true);
|
|
781
|
-
return [4 /*yield*/, this.createAuthCodeClient(serverTelemetryManager, requestAuthority, validRequest.correlationId)];
|
|
782
|
-
case 2:
|
|
783
|
-
authClient = _a.sent();
|
|
784
|
-
browserRequestLogger.verbose("Auth code client created");
|
|
785
|
-
logoutUri = authClient.getLogoutUri(validRequest);
|
|
786
|
-
if (!validRequest.account || AccountEntity.accountInfoIsEqual(validRequest.account, this.getActiveAccount(), false)) {
|
|
787
|
-
browserRequestLogger.verbose("Setting active account to null");
|
|
788
|
-
this.setActiveAccount(null);
|
|
789
|
-
}
|
|
790
|
-
this.eventHandler.emitEvent(EventType.LOGOUT_SUCCESS, InteractionType.Popup, validRequest);
|
|
791
|
-
popupUtils = new PopupUtils(this.browserStorage, this.logger);
|
|
792
|
-
popupWindow = popupUtils.openPopup(logoutUri, popupName, popup);
|
|
793
|
-
this.eventHandler.emitEvent(EventType.POPUP_OPENED, InteractionType.Popup, { popupWindow: popupWindow }, null);
|
|
794
|
-
_a.label = 3;
|
|
795
|
-
case 3:
|
|
796
|
-
_a.trys.push([3, 5, , 6]);
|
|
797
|
-
// Don't care if this throws an error (User Cancelled)
|
|
798
|
-
return [4 /*yield*/, popupUtils.monitorPopupForSameOrigin(popupWindow)];
|
|
799
|
-
case 4:
|
|
800
|
-
// Don't care if this throws an error (User Cancelled)
|
|
801
|
-
_a.sent();
|
|
802
|
-
browserRequestLogger.verbose("Popup successfully redirected to postLogoutRedirectUri");
|
|
803
|
-
return [3 /*break*/, 6];
|
|
804
|
-
case 5:
|
|
805
|
-
e_8 = _a.sent();
|
|
806
|
-
browserRequestLogger.verbose("Error occurred while monitoring popup for same origin. Session on server may remain active. Error: " + e_8);
|
|
807
|
-
return [3 /*break*/, 6];
|
|
808
|
-
case 6:
|
|
809
|
-
popupUtils.cleanPopup(popupWindow);
|
|
810
|
-
if (mainWindowRedirectUri) {
|
|
811
|
-
navigationOptions = {
|
|
812
|
-
apiId: ApiId.logoutPopup,
|
|
813
|
-
timeout: this.config.system.redirectNavigationTimeout,
|
|
814
|
-
noHistory: false
|
|
815
|
-
};
|
|
816
|
-
absoluteUrl = UrlString.getAbsoluteUrl(mainWindowRedirectUri, BrowserUtils.getCurrentUri());
|
|
817
|
-
browserRequestLogger.verbose("Redirecting main window to url specified in the request");
|
|
818
|
-
browserRequestLogger.verbosePii("Redirecing main window to: " + absoluteUrl);
|
|
819
|
-
this.navigationClient.navigateInternal(absoluteUrl, navigationOptions);
|
|
820
|
-
}
|
|
821
|
-
else {
|
|
822
|
-
browserRequestLogger.verbose("No main window navigation requested");
|
|
823
|
-
}
|
|
824
|
-
return [3 /*break*/, 8];
|
|
825
|
-
case 7:
|
|
826
|
-
e_9 = _a.sent();
|
|
827
|
-
if (popup) {
|
|
828
|
-
// Close the synchronous popup if an error is thrown before the window unload event is registered
|
|
829
|
-
popup.close();
|
|
830
|
-
}
|
|
831
|
-
this.browserStorage.removeItem(this.browserStorage.generateCacheKey(TemporaryCacheKeys.INTERACTION_STATUS_KEY));
|
|
832
|
-
this.eventHandler.emitEvent(EventType.LOGOUT_FAILURE, InteractionType.Popup, null, e_9);
|
|
833
|
-
serverTelemetryManager.cacheFailedRequest(e_9);
|
|
834
|
-
throw e_9;
|
|
835
|
-
case 8:
|
|
836
|
-
this.eventHandler.emitEvent(EventType.LOGOUT_END, InteractionType.Popup);
|
|
837
|
-
return [2 /*return*/];
|
|
838
|
-
}
|
|
839
|
-
});
|
|
840
|
-
});
|
|
841
345
|
};
|
|
842
346
|
// #endregion
|
|
843
347
|
// #region Account APIs
|
|
@@ -924,179 +428,6 @@ var ClientApplication = /** @class */ (function () {
|
|
|
924
428
|
};
|
|
925
429
|
// #endregion
|
|
926
430
|
// #region Helpers
|
|
927
|
-
/**
|
|
928
|
-
*
|
|
929
|
-
* Use to get the redirect uri configured in MSAL or null.
|
|
930
|
-
* @param requestRedirectUri
|
|
931
|
-
* @returns Redirect URL
|
|
932
|
-
*
|
|
933
|
-
*/
|
|
934
|
-
ClientApplication.prototype.getRedirectUri = function (requestRedirectUri) {
|
|
935
|
-
this.logger.verbose("getRedirectUri called");
|
|
936
|
-
var redirectUri = requestRedirectUri || this.config.auth.redirectUri || BrowserUtils.getCurrentUri();
|
|
937
|
-
return UrlString.getAbsoluteUrl(redirectUri, BrowserUtils.getCurrentUri());
|
|
938
|
-
};
|
|
939
|
-
/**
|
|
940
|
-
* Use to get the redirectStartPage either from request or use current window
|
|
941
|
-
* @param requestStartPage
|
|
942
|
-
*/
|
|
943
|
-
ClientApplication.prototype.getRedirectStartPage = function (requestStartPage) {
|
|
944
|
-
var redirectStartPage = requestStartPage || window.location.href;
|
|
945
|
-
return UrlString.getAbsoluteUrl(redirectStartPage, BrowserUtils.getCurrentUri());
|
|
946
|
-
};
|
|
947
|
-
/**
|
|
948
|
-
* Used to get a discovered version of the default authority.
|
|
949
|
-
* @param requestAuthority
|
|
950
|
-
* @param requestCorrelationId
|
|
951
|
-
*/
|
|
952
|
-
ClientApplication.prototype.getDiscoveredAuthority = function (requestAuthority, requestCorrelationId) {
|
|
953
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
954
|
-
var authorityOptions;
|
|
955
|
-
return __generator(this, function (_a) {
|
|
956
|
-
switch (_a.label) {
|
|
957
|
-
case 0:
|
|
958
|
-
this.logger.verbose("getDiscoveredAuthority called", requestCorrelationId);
|
|
959
|
-
authorityOptions = {
|
|
960
|
-
protocolMode: this.config.auth.protocolMode,
|
|
961
|
-
knownAuthorities: this.config.auth.knownAuthorities,
|
|
962
|
-
cloudDiscoveryMetadata: this.config.auth.cloudDiscoveryMetadata,
|
|
963
|
-
authorityMetadata: this.config.auth.authorityMetadata
|
|
964
|
-
};
|
|
965
|
-
if (!requestAuthority) return [3 /*break*/, 2];
|
|
966
|
-
this.logger.verbose("Creating discovered authority with request authority", requestCorrelationId);
|
|
967
|
-
return [4 /*yield*/, AuthorityFactory.createDiscoveredInstance(requestAuthority, this.config.system.networkClient, this.browserStorage, authorityOptions)];
|
|
968
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
969
|
-
case 2:
|
|
970
|
-
this.logger.verbose("Creating discovered authority with configured authority", requestCorrelationId);
|
|
971
|
-
return [4 /*yield*/, AuthorityFactory.createDiscoveredInstance(this.config.auth.authority, this.config.system.networkClient, this.browserStorage, authorityOptions)];
|
|
972
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
973
|
-
}
|
|
974
|
-
});
|
|
975
|
-
});
|
|
976
|
-
};
|
|
977
|
-
/**
|
|
978
|
-
* Helper to check whether interaction is in progress.
|
|
979
|
-
*/
|
|
980
|
-
ClientApplication.prototype.interactionInProgress = function () {
|
|
981
|
-
// Check whether value in cache is present and equal to expected value
|
|
982
|
-
return (this.browserStorage.getTemporaryCache(TemporaryCacheKeys.INTERACTION_STATUS_KEY, true)) === BrowserConstants.INTERACTION_IN_PROGRESS_VALUE;
|
|
983
|
-
};
|
|
984
|
-
/**
|
|
985
|
-
* Creates an Authorization Code Client with the given authority, or the default authority.
|
|
986
|
-
* @param serverTelemetryManager
|
|
987
|
-
* @param authorityUrl
|
|
988
|
-
*/
|
|
989
|
-
ClientApplication.prototype.createAuthCodeClient = function (serverTelemetryManager, authorityUrl, correlationId) {
|
|
990
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
991
|
-
var clientConfig;
|
|
992
|
-
return __generator(this, function (_a) {
|
|
993
|
-
switch (_a.label) {
|
|
994
|
-
case 0: return [4 /*yield*/, this.getClientConfiguration(serverTelemetryManager, authorityUrl, correlationId)];
|
|
995
|
-
case 1:
|
|
996
|
-
clientConfig = _a.sent();
|
|
997
|
-
return [2 /*return*/, new AuthorizationCodeClient(clientConfig)];
|
|
998
|
-
}
|
|
999
|
-
});
|
|
1000
|
-
});
|
|
1001
|
-
};
|
|
1002
|
-
/**
|
|
1003
|
-
* Creates an Silent Flow Client with the given authority, or the default authority.
|
|
1004
|
-
* @param serverTelemetryManager
|
|
1005
|
-
* @param authorityUrl
|
|
1006
|
-
*/
|
|
1007
|
-
ClientApplication.prototype.createSilentFlowClient = function (serverTelemetryManager, authorityUrl, correlationId) {
|
|
1008
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1009
|
-
var clientConfig;
|
|
1010
|
-
return __generator(this, function (_a) {
|
|
1011
|
-
switch (_a.label) {
|
|
1012
|
-
case 0: return [4 /*yield*/, this.getClientConfiguration(serverTelemetryManager, authorityUrl, correlationId)];
|
|
1013
|
-
case 1:
|
|
1014
|
-
clientConfig = _a.sent();
|
|
1015
|
-
return [2 /*return*/, new SilentFlowClient(clientConfig)];
|
|
1016
|
-
}
|
|
1017
|
-
});
|
|
1018
|
-
});
|
|
1019
|
-
};
|
|
1020
|
-
/**
|
|
1021
|
-
* Creates a Refresh Client with the given authority, or the default authority.
|
|
1022
|
-
* @param serverTelemetryManager
|
|
1023
|
-
* @param authorityUrl
|
|
1024
|
-
*/
|
|
1025
|
-
ClientApplication.prototype.createRefreshTokenClient = function (serverTelemetryManager, authorityUrl, correlationId) {
|
|
1026
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1027
|
-
var clientConfig;
|
|
1028
|
-
return __generator(this, function (_a) {
|
|
1029
|
-
switch (_a.label) {
|
|
1030
|
-
case 0: return [4 /*yield*/, this.getClientConfiguration(serverTelemetryManager, authorityUrl, correlationId)];
|
|
1031
|
-
case 1:
|
|
1032
|
-
clientConfig = _a.sent();
|
|
1033
|
-
return [2 /*return*/, new RefreshTokenClient(clientConfig)];
|
|
1034
|
-
}
|
|
1035
|
-
});
|
|
1036
|
-
});
|
|
1037
|
-
};
|
|
1038
|
-
/**
|
|
1039
|
-
* Creates a Client Configuration object with the given request authority, or the default authority.
|
|
1040
|
-
* @param serverTelemetryManager
|
|
1041
|
-
* @param requestAuthority
|
|
1042
|
-
* @param requestCorrelationId
|
|
1043
|
-
*/
|
|
1044
|
-
ClientApplication.prototype.getClientConfiguration = function (serverTelemetryManager, requestAuthority, requestCorrelationId) {
|
|
1045
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1046
|
-
var discoveredAuthority;
|
|
1047
|
-
return __generator(this, function (_a) {
|
|
1048
|
-
switch (_a.label) {
|
|
1049
|
-
case 0:
|
|
1050
|
-
this.logger.verbose("getClientConfiguration called", requestCorrelationId);
|
|
1051
|
-
return [4 /*yield*/, this.getDiscoveredAuthority(requestAuthority, requestCorrelationId)];
|
|
1052
|
-
case 1:
|
|
1053
|
-
discoveredAuthority = _a.sent();
|
|
1054
|
-
return [2 /*return*/, {
|
|
1055
|
-
authOptions: {
|
|
1056
|
-
clientId: this.config.auth.clientId,
|
|
1057
|
-
authority: discoveredAuthority,
|
|
1058
|
-
clientCapabilities: this.config.auth.clientCapabilities
|
|
1059
|
-
},
|
|
1060
|
-
systemOptions: {
|
|
1061
|
-
tokenRenewalOffsetSeconds: this.config.system.tokenRenewalOffsetSeconds,
|
|
1062
|
-
preventCorsPreflight: true
|
|
1063
|
-
},
|
|
1064
|
-
loggerOptions: {
|
|
1065
|
-
loggerCallback: this.config.system.loggerOptions.loggerCallback,
|
|
1066
|
-
piiLoggingEnabled: this.config.system.loggerOptions.piiLoggingEnabled,
|
|
1067
|
-
logLevel: this.config.system.loggerOptions.logLevel,
|
|
1068
|
-
correlationId: requestCorrelationId
|
|
1069
|
-
},
|
|
1070
|
-
cryptoInterface: this.browserCrypto,
|
|
1071
|
-
networkInterface: this.networkClient,
|
|
1072
|
-
storageInterface: this.browserStorage,
|
|
1073
|
-
serverTelemetryManager: serverTelemetryManager,
|
|
1074
|
-
libraryInfo: {
|
|
1075
|
-
sku: BrowserConstants.MSAL_SKU,
|
|
1076
|
-
version: version,
|
|
1077
|
-
cpu: "",
|
|
1078
|
-
os: ""
|
|
1079
|
-
}
|
|
1080
|
-
}];
|
|
1081
|
-
}
|
|
1082
|
-
});
|
|
1083
|
-
});
|
|
1084
|
-
};
|
|
1085
|
-
/**
|
|
1086
|
-
* Helper to validate app environment before making a request.
|
|
1087
|
-
* @param request
|
|
1088
|
-
* @param interactionType
|
|
1089
|
-
*/
|
|
1090
|
-
ClientApplication.prototype.preflightInteractiveRequest = function (request, interactionType) {
|
|
1091
|
-
this.logger.verbose("preflightInteractiveRequest called, validating app environment", request === null || request === void 0 ? void 0 : request.correlationId);
|
|
1092
|
-
// block the reload if it occurred inside a hidden iframe
|
|
1093
|
-
BrowserUtils.blockReloadInHiddenIframes();
|
|
1094
|
-
// Check if interaction is in progress. Throw error if true.
|
|
1095
|
-
if (this.interactionInProgress()) {
|
|
1096
|
-
throw BrowserAuthError.createInteractionInProgressError();
|
|
1097
|
-
}
|
|
1098
|
-
return this.initializeAuthorizationRequest(request, interactionType);
|
|
1099
|
-
};
|
|
1100
431
|
/**
|
|
1101
432
|
* Helper to validate app environment before making an auth request
|
|
1102
433
|
* * @param interactionType
|
|
@@ -1119,152 +450,36 @@ var ClientApplication = /** @class */ (function () {
|
|
|
1119
450
|
}
|
|
1120
451
|
};
|
|
1121
452
|
/**
|
|
1122
|
-
*
|
|
1123
|
-
* @param
|
|
1124
|
-
*/
|
|
1125
|
-
ClientApplication.prototype.initializeBaseRequest = function (request) {
|
|
1126
|
-
this.logger.verbose("Initializing BaseAuthRequest", request.correlationId);
|
|
1127
|
-
var authority = request.authority || this.config.auth.authority;
|
|
1128
|
-
var scopes = __spread(((request && request.scopes) || []));
|
|
1129
|
-
var correlationId = (request && request.correlationId) || this.browserCrypto.createNewGuid();
|
|
1130
|
-
// Set authenticationScheme to BEARER if not explicitly set in the request
|
|
1131
|
-
if (!request.authenticationScheme) {
|
|
1132
|
-
request.authenticationScheme = AuthenticationScheme.BEARER;
|
|
1133
|
-
this.logger.verbose("Authentication Scheme wasn't explicitly set in request, defaulting to \"Bearer\" request", request.correlationId);
|
|
1134
|
-
}
|
|
1135
|
-
else {
|
|
1136
|
-
this.logger.verbose("Authentication Scheme set to \"" + request.authenticationScheme + "\" as configured in Auth request", request.correlationId);
|
|
1137
|
-
}
|
|
1138
|
-
var validatedRequest = __assign(__assign({}, request), { correlationId: correlationId,
|
|
1139
|
-
authority: authority,
|
|
1140
|
-
scopes: scopes });
|
|
1141
|
-
return validatedRequest;
|
|
1142
|
-
};
|
|
1143
|
-
/**
|
|
1144
|
-
*
|
|
1145
|
-
* @param apiId
|
|
1146
|
-
* @param correlationId
|
|
1147
|
-
* @param forceRefresh
|
|
1148
|
-
*/
|
|
1149
|
-
ClientApplication.prototype.initializeServerTelemetryManager = function (apiId, correlationId, forceRefresh) {
|
|
1150
|
-
this.logger.verbose("initializeServerTelemetryManager called", correlationId);
|
|
1151
|
-
var telemetryPayload = {
|
|
1152
|
-
clientId: this.config.auth.clientId,
|
|
1153
|
-
correlationId: correlationId,
|
|
1154
|
-
apiId: apiId,
|
|
1155
|
-
forceRefresh: forceRefresh || false,
|
|
1156
|
-
wrapperSKU: this.wrapperSKU,
|
|
1157
|
-
wrapperVer: this.wrapperVer
|
|
1158
|
-
};
|
|
1159
|
-
return new ServerTelemetryManager(telemetryPayload, this.browserStorage);
|
|
1160
|
-
};
|
|
1161
|
-
/**
|
|
1162
|
-
* Helper to initialize required request parameters for interactive APIs and ssoSilent()
|
|
1163
|
-
* @param request
|
|
1164
|
-
* @param interactionType
|
|
453
|
+
* Adds event callbacks to array
|
|
454
|
+
* @param callback
|
|
1165
455
|
*/
|
|
1166
|
-
ClientApplication.prototype.
|
|
1167
|
-
this.
|
|
1168
|
-
var redirectUri = this.getRedirectUri(request.redirectUri);
|
|
1169
|
-
var browserState = {
|
|
1170
|
-
interactionType: interactionType
|
|
1171
|
-
};
|
|
1172
|
-
var state = ProtocolUtils.setRequestState(this.browserCrypto, (request && request.state) || "", browserState);
|
|
1173
|
-
var validatedRequest = __assign(__assign({}, this.initializeBaseRequest(request)), { redirectUri: redirectUri, state: state, nonce: request.nonce || this.browserCrypto.createNewGuid(), responseMode: ResponseMode.FRAGMENT });
|
|
1174
|
-
var account = request.account || this.getActiveAccount();
|
|
1175
|
-
if (account) {
|
|
1176
|
-
this.logger.verbose("Setting validated request account");
|
|
1177
|
-
this.logger.verbosePii("Setting validated request account: " + account);
|
|
1178
|
-
validatedRequest.account = account;
|
|
1179
|
-
}
|
|
1180
|
-
// Check for ADAL SSO
|
|
1181
|
-
if (StringUtils.isEmpty(validatedRequest.loginHint)) {
|
|
1182
|
-
// Only check for adal token if no SSO params are being used
|
|
1183
|
-
var adalIdTokenString = this.browserStorage.getTemporaryCache(PersistentCacheKeys.ADAL_ID_TOKEN);
|
|
1184
|
-
if (adalIdTokenString) {
|
|
1185
|
-
var adalIdToken = new IdToken(adalIdTokenString, this.browserCrypto);
|
|
1186
|
-
this.browserStorage.removeItem(PersistentCacheKeys.ADAL_ID_TOKEN);
|
|
1187
|
-
if (adalIdToken.claims && adalIdToken.claims.upn) {
|
|
1188
|
-
this.logger.verbose("No SSO params used and ADAL token retrieved, setting ADAL upn as loginHint");
|
|
1189
|
-
validatedRequest.loginHint = adalIdToken.claims.upn;
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
this.browserStorage.updateCacheEntries(validatedRequest.state, validatedRequest.nonce, validatedRequest.authority, validatedRequest.loginHint || "", validatedRequest.account || null);
|
|
1194
|
-
return validatedRequest;
|
|
456
|
+
ClientApplication.prototype.addEventCallback = function (callback) {
|
|
457
|
+
return this.eventHandler.addEventCallback(callback);
|
|
1195
458
|
};
|
|
1196
459
|
/**
|
|
1197
|
-
*
|
|
1198
|
-
* @param
|
|
460
|
+
* Removes callback with provided id from callback array
|
|
461
|
+
* @param callbackId
|
|
1199
462
|
*/
|
|
1200
|
-
ClientApplication.prototype.
|
|
1201
|
-
|
|
1202
|
-
var generatedPkceParams, authCodeRequest;
|
|
1203
|
-
return __generator(this, function (_a) {
|
|
1204
|
-
switch (_a.label) {
|
|
1205
|
-
case 0:
|
|
1206
|
-
this.logger.verbose("initializeAuthorizationRequest called", request.correlationId);
|
|
1207
|
-
return [4 /*yield*/, this.browserCrypto.generatePkceCodes()];
|
|
1208
|
-
case 1:
|
|
1209
|
-
generatedPkceParams = _a.sent();
|
|
1210
|
-
authCodeRequest = __assign(__assign({}, request), { redirectUri: request.redirectUri, code: "", codeVerifier: generatedPkceParams.verifier });
|
|
1211
|
-
request.codeChallenge = generatedPkceParams.challenge;
|
|
1212
|
-
request.codeChallengeMethod = Constants.S256_CODE_CHALLENGE_METHOD;
|
|
1213
|
-
return [2 /*return*/, authCodeRequest];
|
|
1214
|
-
}
|
|
1215
|
-
});
|
|
1216
|
-
});
|
|
463
|
+
ClientApplication.prototype.removeEventCallback = function (callbackId) {
|
|
464
|
+
this.eventHandler.removeEventCallback(callbackId);
|
|
1217
465
|
};
|
|
1218
466
|
/**
|
|
1219
|
-
*
|
|
1220
|
-
* @param logoutRequest
|
|
467
|
+
* Adds event listener that emits an event when a user account is added or removed from localstorage in a different browser tab or window
|
|
1221
468
|
*/
|
|
1222
|
-
ClientApplication.prototype.
|
|
1223
|
-
this.
|
|
1224
|
-
// Check if interaction is in progress. Throw error if true.
|
|
1225
|
-
if (this.interactionInProgress()) {
|
|
1226
|
-
throw BrowserAuthError.createInteractionInProgressError();
|
|
1227
|
-
}
|
|
1228
|
-
var validLogoutRequest = __assign({ correlationId: this.browserCrypto.createNewGuid() }, logoutRequest);
|
|
1229
|
-
/*
|
|
1230
|
-
* Only set redirect uri if logout request isn't provided or the set uri isn't null.
|
|
1231
|
-
* Otherwise, use passed uri, config, or current page.
|
|
1232
|
-
*/
|
|
1233
|
-
if (!logoutRequest || logoutRequest.postLogoutRedirectUri !== null) {
|
|
1234
|
-
if (logoutRequest && logoutRequest.postLogoutRedirectUri) {
|
|
1235
|
-
this.logger.verbose("Setting postLogoutRedirectUri to uri set on logout request", validLogoutRequest.correlationId);
|
|
1236
|
-
validLogoutRequest.postLogoutRedirectUri = UrlString.getAbsoluteUrl(logoutRequest.postLogoutRedirectUri, BrowserUtils.getCurrentUri());
|
|
1237
|
-
}
|
|
1238
|
-
else if (this.config.auth.postLogoutRedirectUri === null) {
|
|
1239
|
-
this.logger.verbose("postLogoutRedirectUri configured as null and no uri set on request, not passing post logout redirect", validLogoutRequest.correlationId);
|
|
1240
|
-
}
|
|
1241
|
-
else if (this.config.auth.postLogoutRedirectUri) {
|
|
1242
|
-
this.logger.verbose("Setting postLogoutRedirectUri to configured uri", validLogoutRequest.correlationId);
|
|
1243
|
-
validLogoutRequest.postLogoutRedirectUri = UrlString.getAbsoluteUrl(this.config.auth.postLogoutRedirectUri, BrowserUtils.getCurrentUri());
|
|
1244
|
-
}
|
|
1245
|
-
else {
|
|
1246
|
-
this.logger.verbose("Setting postLogoutRedirectUri to current page", validLogoutRequest.correlationId);
|
|
1247
|
-
validLogoutRequest.postLogoutRedirectUri = UrlString.getAbsoluteUrl(BrowserUtils.getCurrentUri(), BrowserUtils.getCurrentUri());
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
else {
|
|
1251
|
-
this.logger.verbose("postLogoutRedirectUri passed as null, not setting post logout redirect uri", validLogoutRequest.correlationId);
|
|
1252
|
-
}
|
|
1253
|
-
return validLogoutRequest;
|
|
469
|
+
ClientApplication.prototype.enableAccountStorageEvents = function () {
|
|
470
|
+
this.eventHandler.enableAccountStorageEvents();
|
|
1254
471
|
};
|
|
1255
472
|
/**
|
|
1256
|
-
*
|
|
1257
|
-
* @param callback
|
|
473
|
+
* Removes event listener that emits an event when a user account is added or removed from localstorage in a different browser tab or window
|
|
1258
474
|
*/
|
|
1259
|
-
ClientApplication.prototype.
|
|
1260
|
-
|
|
475
|
+
ClientApplication.prototype.disableAccountStorageEvents = function () {
|
|
476
|
+
this.eventHandler.disableAccountStorageEvents();
|
|
1261
477
|
};
|
|
1262
478
|
/**
|
|
1263
|
-
*
|
|
1264
|
-
* @param callbackId
|
|
479
|
+
* Gets the token cache for the application.
|
|
1265
480
|
*/
|
|
1266
|
-
ClientApplication.prototype.
|
|
1267
|
-
this.
|
|
481
|
+
ClientApplication.prototype.getTokenCache = function () {
|
|
482
|
+
return this.tokenCache;
|
|
1268
483
|
};
|
|
1269
484
|
/**
|
|
1270
485
|
* Returns the logger instance
|
|
@@ -1286,8 +501,7 @@ var ClientApplication = /** @class */ (function () {
|
|
|
1286
501
|
*/
|
|
1287
502
|
ClientApplication.prototype.initializeWrapperLibrary = function (sku, version) {
|
|
1288
503
|
// Validate the SKU passed in is one we expect
|
|
1289
|
-
this.
|
|
1290
|
-
this.wrapperVer = version;
|
|
504
|
+
this.browserStorage.setWrapperMetadata(sku, version);
|
|
1291
505
|
};
|
|
1292
506
|
/**
|
|
1293
507
|
* Sets navigation client
|
|
@@ -1296,6 +510,12 @@ var ClientApplication = /** @class */ (function () {
|
|
|
1296
510
|
ClientApplication.prototype.setNavigationClient = function (navigationClient) {
|
|
1297
511
|
this.navigationClient = navigationClient;
|
|
1298
512
|
};
|
|
513
|
+
/**
|
|
514
|
+
* Returns the configuration object
|
|
515
|
+
*/
|
|
516
|
+
ClientApplication.prototype.getConfiguration = function () {
|
|
517
|
+
return this.config;
|
|
518
|
+
};
|
|
1299
519
|
return ClientApplication;
|
|
1300
520
|
}());
|
|
1301
521
|
|