@azure/msal-browser 2.16.1 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/CHANGELOG.json +283 -0
  2. package/{changelog.md → CHANGELOG.md} +73 -1
  3. package/README.md +12 -4
  4. package/dist/_virtual/_tslib.js +1 -1
  5. package/dist/app/ClientApplication.d.ts +35 -137
  6. package/dist/app/ClientApplication.d.ts.map +1 -1
  7. package/dist/app/ClientApplication.js +178 -883
  8. package/dist/app/ClientApplication.js.map +1 -1
  9. package/dist/app/IPublicClientApplication.d.ts +8 -0
  10. package/dist/app/IPublicClientApplication.d.ts.map +1 -1
  11. package/dist/app/IPublicClientApplication.js +16 -1
  12. package/dist/app/IPublicClientApplication.js.map +1 -1
  13. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  14. package/dist/app/PublicClientApplication.js +35 -41
  15. package/dist/app/PublicClientApplication.js.map +1 -1
  16. package/dist/cache/AsyncMemoryStorage.d.ts +46 -0
  17. package/dist/cache/AsyncMemoryStorage.d.ts.map +1 -0
  18. package/dist/cache/AsyncMemoryStorage.js +195 -0
  19. package/dist/cache/AsyncMemoryStorage.js.map +1 -0
  20. package/dist/cache/BrowserCacheManager.d.ts +19 -2
  21. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  22. package/dist/cache/BrowserCacheManager.js +104 -15
  23. package/dist/cache/BrowserCacheManager.js.map +1 -1
  24. package/dist/cache/BrowserStorage.d.ts +1 -1
  25. package/dist/cache/BrowserStorage.d.ts.map +1 -1
  26. package/dist/cache/BrowserStorage.js +1 -1
  27. package/dist/cache/BrowserStorage.js.map +1 -1
  28. package/dist/cache/DatabaseStorage.d.ts +29 -4
  29. package/dist/cache/DatabaseStorage.d.ts.map +1 -1
  30. package/dist/cache/DatabaseStorage.js +151 -45
  31. package/dist/cache/DatabaseStorage.js.map +1 -1
  32. package/dist/cache/IAsyncMemoryStorage.d.ts +28 -0
  33. package/dist/cache/IAsyncMemoryStorage.d.ts.map +1 -0
  34. package/dist/cache/ITokenCache.d.ts +8 -0
  35. package/dist/cache/ITokenCache.d.ts.map +1 -0
  36. package/dist/cache/IWindowStorage.d.ts +3 -3
  37. package/dist/cache/IWindowStorage.d.ts.map +1 -1
  38. package/dist/cache/MemoryStorage.d.ts +3 -3
  39. package/dist/cache/MemoryStorage.d.ts.map +1 -1
  40. package/dist/cache/MemoryStorage.js +1 -1
  41. package/dist/cache/MemoryStorage.js.map +1 -1
  42. package/dist/cache/TokenCache.d.ts +48 -0
  43. package/dist/cache/TokenCache.d.ts.map +1 -0
  44. package/dist/cache/TokenCache.js +124 -0
  45. package/dist/cache/TokenCache.js.map +1 -0
  46. package/dist/config/Configuration.js +1 -1
  47. package/dist/crypto/BrowserCrypto.d.ts +3 -1
  48. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  49. package/dist/crypto/BrowserCrypto.js +3 -2
  50. package/dist/crypto/BrowserCrypto.js.map +1 -1
  51. package/dist/crypto/CryptoOps.d.ts +21 -6
  52. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  53. package/dist/crypto/CryptoOps.js +67 -15
  54. package/dist/crypto/CryptoOps.js.map +1 -1
  55. package/dist/crypto/GuidGenerator.js +1 -1
  56. package/dist/crypto/PkceGenerator.js +1 -1
  57. package/dist/crypto/SignedHttpRequest.d.ts +31 -0
  58. package/dist/crypto/SignedHttpRequest.d.ts.map +1 -0
  59. package/dist/crypto/SignedHttpRequest.js +70 -0
  60. package/dist/crypto/SignedHttpRequest.js.map +1 -0
  61. package/dist/encode/Base64Decode.js +1 -1
  62. package/dist/encode/Base64Encode.js +1 -1
  63. package/dist/error/BrowserAuthError.d.ts +36 -4
  64. package/dist/error/BrowserAuthError.d.ts.map +1 -1
  65. package/dist/error/BrowserAuthError.js +51 -11
  66. package/dist/error/BrowserAuthError.js.map +1 -1
  67. package/dist/error/BrowserConfigurationAuthError.js +1 -1
  68. package/dist/event/EventHandler.d.ts +13 -0
  69. package/dist/event/EventHandler.d.ts.map +1 -1
  70. package/dist/event/EventHandler.js +66 -1
  71. package/dist/event/EventHandler.js.map +1 -1
  72. package/dist/event/EventMessage.d.ts +4 -3
  73. package/dist/event/EventMessage.d.ts.map +1 -1
  74. package/dist/event/EventMessage.js +24 -5
  75. package/dist/event/EventMessage.js.map +1 -1
  76. package/dist/event/EventType.d.ts +5 -0
  77. package/dist/event/EventType.d.ts.map +1 -1
  78. package/dist/event/EventType.js +6 -1
  79. package/dist/event/EventType.js.map +1 -1
  80. package/dist/index.cjs.js +4678 -2996
  81. package/dist/index.cjs.js.map +1 -1
  82. package/dist/index.d.ts +6 -2
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +4 -2
  85. package/dist/index.js.map +1 -1
  86. package/dist/interaction_client/BaseInteractionClient.d.ts +42 -0
  87. package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -0
  88. package/dist/interaction_client/BaseInteractionClient.js +131 -0
  89. package/dist/interaction_client/BaseInteractionClient.js.map +1 -0
  90. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.d.ts +5 -0
  91. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.d.ts.map +1 -0
  92. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.js +21 -0
  93. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.js.map +1 -0
  94. package/dist/interaction_client/PopupClient.d.ts +37 -0
  95. package/dist/interaction_client/PopupClient.d.ts.map +1 -0
  96. package/dist/interaction_client/PopupClient.js +234 -0
  97. package/dist/interaction_client/PopupClient.js.map +1 -0
  98. package/dist/interaction_client/RedirectClient.d.ts +42 -0
  99. package/dist/interaction_client/RedirectClient.d.ts.map +1 -0
  100. package/dist/interaction_client/RedirectClient.js +301 -0
  101. package/dist/interaction_client/RedirectClient.js.map +1 -0
  102. package/dist/interaction_client/SilentAuthCodeClient.d.ts +22 -0
  103. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -0
  104. package/dist/interaction_client/SilentAuthCodeClient.js +80 -0
  105. package/dist/interaction_client/SilentAuthCodeClient.js.map +1 -0
  106. package/dist/interaction_client/SilentCacheClient.d.ts +22 -0
  107. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -0
  108. package/dist/interaction_client/SilentCacheClient.js +85 -0
  109. package/dist/interaction_client/SilentCacheClient.js.map +1 -0
  110. package/dist/interaction_client/SilentIframeClient.d.ts +29 -0
  111. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -0
  112. package/dist/interaction_client/SilentIframeClient.js +107 -0
  113. package/dist/interaction_client/SilentIframeClient.js.map +1 -0
  114. package/dist/interaction_client/SilentRefreshClient.d.ts +20 -0
  115. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -0
  116. package/dist/interaction_client/SilentRefreshClient.js +76 -0
  117. package/dist/interaction_client/SilentRefreshClient.js.map +1 -0
  118. package/dist/interaction_client/StandardInteractionClient.d.ts +66 -0
  119. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -0
  120. package/dist/interaction_client/StandardInteractionClient.js +249 -0
  121. package/dist/interaction_client/StandardInteractionClient.js.map +1 -0
  122. package/dist/interaction_handler/InteractionHandler.d.ts +11 -2
  123. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  124. package/dist/interaction_handler/InteractionHandler.js +36 -10
  125. package/dist/interaction_handler/InteractionHandler.js.map +1 -1
  126. package/dist/interaction_handler/PopupHandler.d.ts +2 -0
  127. package/dist/interaction_handler/PopupHandler.d.ts.map +1 -1
  128. package/dist/interaction_handler/PopupHandler.js +3 -4
  129. package/dist/interaction_handler/PopupHandler.js.map +1 -1
  130. package/dist/interaction_handler/RedirectHandler.d.ts +1 -1
  131. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  132. package/dist/interaction_handler/RedirectHandler.js +7 -6
  133. package/dist/interaction_handler/RedirectHandler.js.map +1 -1
  134. package/dist/interaction_handler/SilentHandler.js +1 -1
  135. package/dist/navigation/NavigationClient.js +1 -1
  136. package/dist/network/FetchClient.js +1 -1
  137. package/dist/network/XhrClient.js +1 -1
  138. package/dist/packageMetadata.d.ts +1 -1
  139. package/dist/packageMetadata.js +2 -2
  140. package/dist/packageMetadata.js.map +1 -1
  141. package/dist/request/AuthorizationCodeRequest.d.ts +8 -0
  142. package/dist/request/AuthorizationCodeRequest.d.ts.map +1 -0
  143. package/dist/request/EndSessionPopupRequest.d.ts +3 -0
  144. package/dist/request/EndSessionPopupRequest.d.ts.map +1 -1
  145. package/dist/request/PopupRequest.d.ts +3 -0
  146. package/dist/request/PopupRequest.d.ts.map +1 -1
  147. package/dist/request/RedirectRequest.d.ts.map +1 -1
  148. package/dist/utils/BrowserConstants.d.ts +13 -1
  149. package/dist/utils/BrowserConstants.d.ts.map +1 -1
  150. package/dist/utils/BrowserConstants.js +17 -3
  151. package/dist/utils/BrowserConstants.js.map +1 -1
  152. package/dist/utils/BrowserProtocolUtils.js +1 -1
  153. package/dist/utils/BrowserStringUtils.js +1 -1
  154. package/dist/utils/BrowserUtils.js +1 -1
  155. package/dist/utils/MathUtils.js +1 -1
  156. package/dist/utils/PopupUtils.d.ts +26 -2
  157. package/dist/utils/PopupUtils.d.ts.map +1 -1
  158. package/dist/utils/PopupUtils.js +42 -15
  159. package/dist/utils/PopupUtils.js.map +1 -1
  160. package/lib/msal-browser.js +4678 -2996
  161. package/lib/msal-browser.js.map +1 -1
  162. package/lib/msal-browser.min.js +32 -32
  163. package/package.json +9 -2
@@ -1,22 +1,23 @@
1
- /*! @azure/msal-browser v2.16.1 2021-08-02 */
1
+ /*! @azure/msal-browser v2.20.0 2021-12-07 */
2
2
  'use strict';
3
- import { __awaiter, __generator, __assign, __spread } from '../_virtual/_tslib.js';
3
+ import { __awaiter, __generator } from '../_virtual/_tslib.js';
4
4
  import { CryptoOps } from '../crypto/CryptoOps.js';
5
- import { UrlString, ThrottlingUtils, StringUtils, PromptValue, AccountEntity, AuthorityFactory, AuthorizationCodeClient, SilentFlowClient, RefreshTokenClient, AuthenticationScheme, ServerTelemetryManager, ProtocolUtils, ResponseMode, PersistentCacheKeys, IdToken, Constants, Logger, DEFAULT_CRYPTO_IMPLEMENTATION, ServerError, InteractionRequiredAuthError } from '@azure/msal-common';
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, BrowserConstants, BrowserCacheLocation } from '../utils/BrowserConstants.js';
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';
19
+ import { SilentAuthCodeClient } from '../interaction_client/SilentAuthCodeClient.js';
20
+ import { BrowserAuthError } from '../error/BrowserAuthError.js';
20
21
 
21
22
  /*
22
23
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -61,13 +62,17 @@ var ClientApplication = /** @class */ (function () {
61
62
  this.navigationClient = this.config.system.navigationClient;
62
63
  // Initialize redirectResponse Map
63
64
  this.redirectResponse = new Map();
65
+ // Initial hybrid spa map
66
+ this.hybridAuthCodeResponses = new Map();
64
67
  // Initialize the crypto class.
65
- this.browserCrypto = this.isBrowserEnvironment ? new CryptoOps() : DEFAULT_CRYPTO_IMPLEMENTATION;
68
+ this.browserCrypto = this.isBrowserEnvironment ? new CryptoOps(this.logger) : DEFAULT_CRYPTO_IMPLEMENTATION;
66
69
  this.eventHandler = new EventHandler(this.logger, this.browserCrypto);
67
70
  // Initialize the browser storage class.
68
71
  this.browserStorage = this.isBrowserEnvironment ?
69
72
  new BrowserCacheManager(this.config.auth.clientId, this.config.cache, this.browserCrypto, this.logger) :
70
73
  DEFAULT_BROWSER_CACHE_MANAGER(this.config.auth.clientId, this.logger);
74
+ // Initialize the token cache
75
+ this.tokenCache = new TokenCache(this.config, this.browserStorage, this.logger, this.browserCrypto);
71
76
  }
72
77
  // #region Redirect Flow
73
78
  /**
@@ -79,18 +84,20 @@ var ClientApplication = /** @class */ (function () {
79
84
  */
80
85
  ClientApplication.prototype.handleRedirectPromise = function (hash) {
81
86
  return __awaiter(this, void 0, void 0, function () {
82
- var loggedInAccounts, redirectResponseKey, response;
87
+ var loggedInAccounts, redirectResponseKey, response, correlationId, redirectClient;
83
88
  var _this = this;
84
89
  return __generator(this, function (_a) {
85
- this.eventHandler.emitEvent(EventType.HANDLE_REDIRECT_START, InteractionType.Redirect);
86
90
  this.logger.verbose("handleRedirectPromise called");
87
91
  loggedInAccounts = this.getAllAccounts();
88
92
  if (this.isBrowserEnvironment) {
89
93
  redirectResponseKey = hash || Constants.EMPTY_STRING;
90
94
  response = this.redirectResponse.get(redirectResponseKey);
91
95
  if (typeof response === "undefined") {
96
+ this.eventHandler.emitEvent(EventType.HANDLE_REDIRECT_START, InteractionType.Redirect);
92
97
  this.logger.verbose("handleRedirectPromise has been called for the first time, storing the promise");
93
- response = this.handleRedirectResponse(hash)
98
+ correlationId = this.browserStorage.getTemporaryCache(TemporaryCacheKeys.CORRELATION_ID, true) || "";
99
+ redirectClient = new RedirectClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, correlationId);
100
+ response = redirectClient.handleRedirectPromise(hash)
94
101
  .then(function (result) {
95
102
  if (result) {
96
103
  // Emit login event if number of accounts change
@@ -130,175 +137,6 @@ var ClientApplication = /** @class */ (function () {
130
137
  });
131
138
  });
132
139
  };
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
140
  /**
303
141
  * 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
142
  * the page, so any code that follows this function will not execute.
@@ -310,60 +148,30 @@ var ClientApplication = /** @class */ (function () {
310
148
  */
311
149
  ClientApplication.prototype.acquireTokenRedirect = function (request) {
312
150
  return __awaiter(this, void 0, void 0, function () {
313
- var isLoggedIn, validRequest, browserRequestLogger, serverTelemetryManager, authCodeRequest, authClient, interactionHandler, navigateUrl, redirectStartPage, e_2;
151
+ var isLoggedIn, redirectClient;
152
+ var _this = this;
314
153
  return __generator(this, function (_a) {
315
- switch (_a.label) {
316
- case 0:
317
- // Preflight request
318
- this.preflightBrowserEnvironmentCheck(InteractionType.Redirect);
319
- this.logger.verbose("acquireTokenRedirect called");
320
- isLoggedIn = this.getAllAccounts().length > 0;
321
- if (isLoggedIn) {
322
- this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_START, InteractionType.Redirect, request);
323
- }
324
- else {
325
- this.eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Redirect, request);
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();
154
+ // Preflight request
155
+ this.preflightBrowserEnvironmentCheck(InteractionType.Redirect);
156
+ this.logger.verbose("acquireTokenRedirect called");
157
+ isLoggedIn = this.getAllAccounts().length > 0;
158
+ if (isLoggedIn) {
159
+ this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_START, InteractionType.Redirect, request);
160
+ }
161
+ else {
162
+ this.eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Redirect, request);
163
+ }
164
+ redirectClient = new RedirectClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, request.correlationId);
165
+ return [2 /*return*/, redirectClient.acquireToken(request).catch(function (e) {
355
166
  // If logged in, emit acquire token events
356
167
  if (isLoggedIn) {
357
- this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Redirect, null, e_2);
168
+ _this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Redirect, null, e);
358
169
  }
359
170
  else {
360
- this.eventHandler.emitEvent(EventType.LOGIN_FAILURE, InteractionType.Redirect, null, e_2);
171
+ _this.eventHandler.emitEvent(EventType.LOGIN_FAILURE, InteractionType.Redirect, null, e);
361
172
  }
362
- serverTelemetryManager.cacheFailedRequest(e_2);
363
- this.browserStorage.cleanRequestByState(validRequest.state);
364
- throw e_2;
365
- case 6: return [2 /*return*/];
366
- }
173
+ throw e;
174
+ })];
367
175
  });
368
176
  });
369
177
  };
@@ -377,108 +185,43 @@ var ClientApplication = /** @class */ (function () {
377
185
  * @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
378
186
  */
379
187
  ClientApplication.prototype.acquireTokenPopup = function (request) {
380
- var validRequest;
188
+ var _this = this;
381
189
  try {
382
190
  this.preflightBrowserEnvironmentCheck(InteractionType.Popup);
383
191
  this.logger.verbose("acquireTokenPopup called", request.correlationId);
384
- validRequest = this.preflightInteractiveRequest(request, InteractionType.Popup);
385
192
  }
386
193
  catch (e) {
387
194
  // Since this function is syncronous we need to reject
388
195
  return Promise.reject(e);
389
196
  }
390
- var popupName = PopupUtils.generatePopupName(this.config.auth.clientId, validRequest);
391
- // asyncPopups flag is true. Acquires token without first opening popup. Popup will be opened later asynchronously.
392
- if (this.config.system.asyncPopups) {
393
- this.logger.verbose("asyncPopups set to true, acquiring token", validRequest.correlationId);
394
- return this.acquireTokenPopupAsync(validRequest, popupName);
197
+ // If logged in, emit acquire token events
198
+ var loggedInAccounts = this.getAllAccounts();
199
+ if (loggedInAccounts.length > 0) {
200
+ this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_START, InteractionType.Popup, request);
395
201
  }
396
202
  else {
397
- // asyncPopups flag is set to false. Opens popup before acquiring token.
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);
203
+ this.eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Popup, request);
401
204
  }
402
- };
403
- /**
404
- * Helper which obtains an access_token for your API via opening a popup window in the user's browser
405
- * @param validRequest
406
- * @param popupName
407
- * @param popup
408
- *
409
- * @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
410
- */
411
- ClientApplication.prototype.acquireTokenPopupAsync = function (validRequest, popupName, popup) {
412
- return __awaiter(this, void 0, void 0, function () {
413
- var loggedInAccounts, browserRequestLogger, serverTelemetryManager, authCodeRequest, authClient, navigateUrl, interactionHandler, popupParameters, popupWindow, hash, state, result, isLoggingIn, e_3;
414
- return __generator(this, function (_a) {
415
- switch (_a.label) {
416
- case 0:
417
- this.logger.verbose("acquireTokenPopupAsync called", validRequest.correlationId);
418
- loggedInAccounts = this.getAllAccounts();
419
- if (loggedInAccounts.length > 0) {
420
- this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_START, InteractionType.Popup, validRequest);
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
- });
205
+ var popupClient = new PopupClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, request.correlationId);
206
+ return popupClient.acquireToken(request).then(function (result) {
207
+ // If logged in, emit acquire token events
208
+ var isLoggingIn = loggedInAccounts.length < _this.getAllAccounts().length;
209
+ if (isLoggingIn) {
210
+ _this.eventHandler.emitEvent(EventType.LOGIN_SUCCESS, InteractionType.Popup, result);
211
+ }
212
+ else {
213
+ _this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, InteractionType.Popup, result);
214
+ }
215
+ return result;
216
+ }).catch(function (e) {
217
+ if (loggedInAccounts.length > 0) {
218
+ _this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Popup, null, e);
219
+ }
220
+ else {
221
+ _this.eventHandler.emitEvent(EventType.LOGIN_FAILURE, InteractionType.Popup, null, e);
222
+ }
223
+ // Since this function is syncronous we need to reject
224
+ return Promise.reject(e);
482
225
  });
483
226
  };
484
227
  // #endregion
@@ -500,7 +243,7 @@ var ClientApplication = /** @class */ (function () {
500
243
  */
501
244
  ClientApplication.prototype.ssoSilent = function (request) {
502
245
  return __awaiter(this, void 0, void 0, function () {
503
- var silentTokenResult, e_4;
246
+ var silentIframeClient, silentTokenResult, e_1;
504
247
  return __generator(this, function (_a) {
505
248
  switch (_a.label) {
506
249
  case 0:
@@ -510,64 +253,88 @@ var ClientApplication = /** @class */ (function () {
510
253
  _a.label = 1;
511
254
  case 1:
512
255
  _a.trys.push([1, 3, , 4]);
513
- return [4 /*yield*/, this.acquireTokenByIframe(request, ApiId.ssoSilent)];
256
+ silentIframeClient = new SilentIframeClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, ApiId.ssoSilent, request.correlationId);
257
+ return [4 /*yield*/, silentIframeClient.acquireToken(request)];
514
258
  case 2:
515
259
  silentTokenResult = _a.sent();
516
260
  this.eventHandler.emitEvent(EventType.SSO_SILENT_SUCCESS, InteractionType.Silent, silentTokenResult);
517
261
  return [2 /*return*/, silentTokenResult];
518
262
  case 3:
519
- e_4 = _a.sent();
520
- this.eventHandler.emitEvent(EventType.SSO_SILENT_FAILURE, InteractionType.Silent, null, e_4);
521
- throw e_4;
263
+ e_1 = _a.sent();
264
+ this.eventHandler.emitEvent(EventType.SSO_SILENT_FAILURE, InteractionType.Silent, null, e_1);
265
+ throw e_1;
522
266
  case 4: return [2 /*return*/];
523
267
  }
524
268
  });
525
269
  });
526
270
  };
527
271
  /**
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.
272
+ * This function redeems an authorization code (passed as code) from the eSTS token endpoint.
273
+ * This authorization code should be acquired server-side using a confidential client to acquire a spa_code.
274
+ * This API is not indended for normal authorization code acquisition and redemption.
275
+ *
276
+ * Redemption of this authorization code will not require PKCE, as it was acquired by a confidential client.
277
+ *
278
+ * @param request {@link AuthorizationCodeRequest}
279
+ * @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
280
+ */
281
+ ClientApplication.prototype.acquireTokenByCode = function (request) {
282
+ return __awaiter(this, void 0, void 0, function () {
283
+ var response;
284
+ var _this = this;
285
+ return __generator(this, function (_a) {
286
+ this.preflightBrowserEnvironmentCheck(InteractionType.Silent);
287
+ this.logger.trace("acquireTokenByCode called", request.correlationId);
288
+ this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_START, InteractionType.Silent, request);
289
+ try {
290
+ if (!request.code) {
291
+ throw BrowserAuthError.createAuthCodeRequiredError();
292
+ }
293
+ response = this.hybridAuthCodeResponses.get(request.code);
294
+ if (!response) {
295
+ this.logger.verbose("Initiating new acquireTokenByCode request", request.correlationId);
296
+ response = this.acquireTokenByCodeAsync(request)
297
+ .then(function (result) {
298
+ _this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_SUCCESS, InteractionType.Silent, result);
299
+ _this.hybridAuthCodeResponses.delete(request.code);
300
+ return result;
301
+ })
302
+ .catch(function (error) {
303
+ _this.hybridAuthCodeResponses.delete(request.code);
304
+ throw error;
305
+ });
306
+ this.hybridAuthCodeResponses.set(request.code, response);
307
+ }
308
+ else {
309
+ this.logger.verbose("Existing acquireTokenByCode request found", request.correlationId);
310
+ }
311
+ return [2 /*return*/, response];
312
+ }
313
+ catch (e) {
314
+ this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_FAILURE, InteractionType.Silent, null, e);
315
+ throw e;
316
+ }
317
+ return [2 /*return*/];
318
+ });
319
+ });
320
+ };
321
+ /**
322
+ * Creates a SilentAuthCodeClient to redeem an authorization code.
529
323
  * @param request
530
- * @param apiId - ApiId of the calling function. Used for telemetry.
324
+ * @returns Result of the operation to redeem the authorization code
531
325
  */
532
- ClientApplication.prototype.acquireTokenByIframe = function (request, apiId) {
326
+ ClientApplication.prototype.acquireTokenByCodeAsync = function (request) {
533
327
  return __awaiter(this, void 0, void 0, function () {
534
- var silentRequest, browserRequestLogger, serverTelemetryManager, authCodeRequest, authClient, navigateUrl, e_5;
328
+ var silentAuthCodeClient, silentTokenResult;
535
329
  return __generator(this, function (_a) {
536
330
  switch (_a.label) {
537
331
  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;
332
+ this.logger.trace("acquireTokenByCodeAsync called", request.correlationId);
333
+ silentAuthCodeClient = new SilentAuthCodeClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, ApiId.acquireTokenByCode, request.correlationId);
334
+ return [4 /*yield*/, silentAuthCodeClient.acquireToken(request)];
551
335
  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*/];
336
+ silentTokenResult = _a.sent();
337
+ return [2 /*return*/, silentTokenResult];
571
338
  }
572
339
  });
573
340
  });
@@ -585,66 +352,24 @@ var ClientApplication = /** @class */ (function () {
585
352
  */
586
353
  ClientApplication.prototype.acquireTokenByRefreshToken = function (request) {
587
354
  return __awaiter(this, void 0, void 0, function () {
588
- var silentRequest, browserRequestLogger, serverTelemetryManager, refreshTokenClient, e_6, isServerError, isInteractionRequiredError, isInvalidGrantError;
589
- return __generator(this, function (_a) {
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;
355
+ var silentRefreshClient;
356
+ var _this = this;
634
357
  return __generator(this, function (_a) {
635
- switch (_a.label) {
636
- case 0:
637
- silentHandler = new SilentHandler(authClient, this.browserStorage, authCodeRequest, browserRequestLogger, this.config.system.navigateFrameWait);
638
- return [4 /*yield*/, silentHandler.initiateAuthRequest(navigateUrl)];
639
- case 1:
640
- msalFrame = _a.sent();
641
- return [4 /*yield*/, silentHandler.monitorIframeForHash(msalFrame, this.config.system.iframeHashTimeout)];
642
- case 2:
643
- hash = _a.sent();
644
- state = this.validateAndExtractStateFromHash(hash, InteractionType.Silent, authCodeRequest.correlationId);
645
- // Handle response from hash string
646
- return [2 /*return*/, silentHandler.handleCodeResponse(hash, state, authClient.authority, this.networkClient)];
647
- }
358
+ this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_NETWORK_START, InteractionType.Silent, request);
359
+ // block the reload if it occurred inside a hidden iframe
360
+ BrowserUtils.blockReloadInHiddenIframes();
361
+ silentRefreshClient = new SilentRefreshClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, request.correlationId);
362
+ return [2 /*return*/, silentRefreshClient.acquireToken(request).catch(function (e) {
363
+ var isServerError = e instanceof ServerError;
364
+ var isInteractionRequiredError = e instanceof InteractionRequiredAuthError;
365
+ var isInvalidGrantError = (e.errorCode === BrowserConstants.INVALID_GRANT_ERROR);
366
+ if (isServerError && isInvalidGrantError && !isInteractionRequiredError) {
367
+ _this.logger.verbose("Refresh token expired or invalid, attempting acquire token by iframe", request.correlationId);
368
+ var silentIframeClient = new SilentIframeClient(_this.config, _this.browserStorage, _this.browserCrypto, _this.logger, _this.eventHandler, _this.navigationClient, ApiId.acquireTokenSilent_authCode, request.correlationId);
369
+ return silentIframeClient.acquireToken(request);
370
+ }
371
+ throw e;
372
+ })];
648
373
  });
649
374
  });
650
375
  };
@@ -670,60 +395,11 @@ var ClientApplication = /** @class */ (function () {
670
395
  */
671
396
  ClientApplication.prototype.logoutRedirect = function (logoutRequest) {
672
397
  return __awaiter(this, void 0, void 0, function () {
673
- var validLogoutRequest, browserRequestLogger, serverTelemetryManager, authClient, logoutUri, navigationOptions, navigate, e_7;
398
+ var redirectClient;
674
399
  return __generator(this, function (_a) {
675
- switch (_a.label) {
676
- case 0:
677
- this.preflightBrowserEnvironmentCheck(InteractionType.Redirect);
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
- }
400
+ this.preflightBrowserEnvironmentCheck(InteractionType.Redirect);
401
+ redirectClient = new RedirectClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, logoutRequest === null || logoutRequest === void 0 ? void 0 : logoutRequest.correlationId);
402
+ return [2 /*return*/, redirectClient.logout(logoutRequest)];
727
403
  });
728
404
  });
729
405
  };
@@ -732,112 +408,15 @@ var ClientApplication = /** @class */ (function () {
732
408
  * @param logoutRequest
733
409
  */
734
410
  ClientApplication.prototype.logoutPopup = function (logoutRequest) {
735
- var validLogoutRequest;
736
411
  try {
737
412
  this.preflightBrowserEnvironmentCheck(InteractionType.Popup);
738
- this.logger.verbose("logoutPopup called", logoutRequest === null || logoutRequest === void 0 ? void 0 : logoutRequest.correlationId);
739
- validLogoutRequest = this.initializeLogoutRequest(logoutRequest);
413
+ 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);
414
+ return popupClient.logout(logoutRequest);
740
415
  }
741
416
  catch (e) {
742
- // Since this function is synchronous we need to reject
417
+ // Since this function is syncronous we need to reject
743
418
  return Promise.reject(e);
744
419
  }
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
420
  };
842
421
  // #endregion
843
422
  // #region Account APIs
@@ -924,179 +503,6 @@ var ClientApplication = /** @class */ (function () {
924
503
  };
925
504
  // #endregion
926
505
  // #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
506
  /**
1101
507
  * Helper to validate app environment before making an auth request
1102
508
  * * @param interactionType
@@ -1119,152 +525,36 @@ var ClientApplication = /** @class */ (function () {
1119
525
  }
1120
526
  };
1121
527
  /**
1122
- * Initializer function for all request APIs
1123
- * @param request
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
528
+ * Adds event callbacks to array
529
+ * @param callback
1165
530
  */
1166
- ClientApplication.prototype.initializeAuthorizationRequest = function (request, interactionType) {
1167
- this.logger.verbose("initializeAuthorizationRequest called", request.correlationId);
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;
531
+ ClientApplication.prototype.addEventCallback = function (callback) {
532
+ return this.eventHandler.addEventCallback(callback);
1195
533
  };
1196
534
  /**
1197
- * Generates an auth code request tied to the url request.
1198
- * @param request
535
+ * Removes callback with provided id from callback array
536
+ * @param callbackId
1199
537
  */
1200
- ClientApplication.prototype.initializeAuthorizationCodeRequest = function (request) {
1201
- return __awaiter(this, void 0, void 0, function () {
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
- });
538
+ ClientApplication.prototype.removeEventCallback = function (callbackId) {
539
+ this.eventHandler.removeEventCallback(callbackId);
1217
540
  };
1218
541
  /**
1219
- * Initializer for the logout request.
1220
- * @param logoutRequest
542
+ * 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
543
  */
1222
- ClientApplication.prototype.initializeLogoutRequest = function (logoutRequest) {
1223
- this.logger.verbose("initializeLogoutRequest called", logoutRequest === null || logoutRequest === void 0 ? void 0 : logoutRequest.correlationId);
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;
544
+ ClientApplication.prototype.enableAccountStorageEvents = function () {
545
+ this.eventHandler.enableAccountStorageEvents();
1254
546
  };
1255
547
  /**
1256
- * Adds event callbacks to array
1257
- * @param callback
548
+ * 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
549
  */
1259
- ClientApplication.prototype.addEventCallback = function (callback) {
1260
- return this.eventHandler.addEventCallback(callback);
550
+ ClientApplication.prototype.disableAccountStorageEvents = function () {
551
+ this.eventHandler.disableAccountStorageEvents();
1261
552
  };
1262
553
  /**
1263
- * Removes callback with provided id from callback array
1264
- * @param callbackId
554
+ * Gets the token cache for the application.
1265
555
  */
1266
- ClientApplication.prototype.removeEventCallback = function (callbackId) {
1267
- this.eventHandler.removeEventCallback(callbackId);
556
+ ClientApplication.prototype.getTokenCache = function () {
557
+ return this.tokenCache;
1268
558
  };
1269
559
  /**
1270
560
  * Returns the logger instance
@@ -1286,8 +576,7 @@ var ClientApplication = /** @class */ (function () {
1286
576
  */
1287
577
  ClientApplication.prototype.initializeWrapperLibrary = function (sku, version) {
1288
578
  // Validate the SKU passed in is one we expect
1289
- this.wrapperSKU = sku;
1290
- this.wrapperVer = version;
579
+ this.browserStorage.setWrapperMetadata(sku, version);
1291
580
  };
1292
581
  /**
1293
582
  * Sets navigation client
@@ -1296,6 +585,12 @@ var ClientApplication = /** @class */ (function () {
1296
585
  ClientApplication.prototype.setNavigationClient = function (navigationClient) {
1297
586
  this.navigationClient = navigationClient;
1298
587
  };
588
+ /**
589
+ * Returns the configuration object
590
+ */
591
+ ClientApplication.prototype.getConfiguration = function () {
592
+ return this.config;
593
+ };
1299
594
  return ClientApplication;
1300
595
  }());
1301
596