@azure/msal-browser 2.23.0 → 2.25.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 (160) hide show
  1. package/README.md +1 -1
  2. package/dist/_virtual/_tslib.js +1 -1
  3. package/dist/app/ClientApplication.d.ts +58 -1
  4. package/dist/app/ClientApplication.d.ts.map +1 -1
  5. package/dist/app/ClientApplication.js +290 -75
  6. package/dist/app/ClientApplication.js.map +1 -1
  7. package/dist/app/IPublicClientApplication.d.ts +1 -0
  8. package/dist/app/IPublicClientApplication.d.ts.map +1 -1
  9. package/dist/app/IPublicClientApplication.js +4 -1
  10. package/dist/app/IPublicClientApplication.js.map +1 -1
  11. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  12. package/dist/app/PublicClientApplication.js +48 -42
  13. package/dist/app/PublicClientApplication.js.map +1 -1
  14. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +49 -0
  15. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -0
  16. package/dist/broker/nativeBroker/NativeMessageHandler.js +246 -0
  17. package/dist/broker/nativeBroker/NativeMessageHandler.js.map +1 -0
  18. package/dist/broker/nativeBroker/NativeRequest.d.ts +44 -0
  19. package/dist/broker/nativeBroker/NativeRequest.d.ts.map +1 -0
  20. package/dist/broker/nativeBroker/NativeResponse.d.ts +24 -0
  21. package/dist/broker/nativeBroker/NativeResponse.d.ts.map +1 -0
  22. package/dist/cache/AsyncMemoryStorage.js +1 -1
  23. package/dist/cache/BrowserCacheManager.d.ts +11 -0
  24. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  25. package/dist/cache/BrowserCacheManager.js +44 -2
  26. package/dist/cache/BrowserCacheManager.js.map +1 -1
  27. package/dist/cache/BrowserStorage.js +1 -1
  28. package/dist/cache/DatabaseStorage.js +1 -1
  29. package/dist/cache/MemoryStorage.js +1 -1
  30. package/dist/cache/TokenCache.d.ts +1 -0
  31. package/dist/cache/TokenCache.d.ts.map +1 -1
  32. package/dist/cache/TokenCache.js +2 -2
  33. package/dist/cache/TokenCache.js.map +1 -1
  34. package/dist/config/Configuration.d.ts +99 -38
  35. package/dist/config/Configuration.d.ts.map +1 -1
  36. package/dist/config/Configuration.js +4 -3
  37. package/dist/config/Configuration.js.map +1 -1
  38. package/dist/crypto/BrowserCrypto.js +1 -1
  39. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  40. package/dist/crypto/CryptoOps.js +7 -10
  41. package/dist/crypto/CryptoOps.js.map +1 -1
  42. package/dist/crypto/GuidGenerator.js +1 -1
  43. package/dist/crypto/PkceGenerator.js +1 -1
  44. package/dist/crypto/SignedHttpRequest.js +1 -1
  45. package/dist/encode/Base64Decode.js +1 -1
  46. package/dist/encode/Base64Encode.js +1 -1
  47. package/dist/error/BrowserAuthError.d.ts +58 -0
  48. package/dist/error/BrowserAuthError.d.ts.map +1 -1
  49. package/dist/error/BrowserAuthError.js +75 -3
  50. package/dist/error/BrowserAuthError.js.map +1 -1
  51. package/dist/error/BrowserConfigurationAuthError.js +1 -1
  52. package/dist/error/NativeAuthError.d.ts +47 -0
  53. package/dist/error/NativeAuthError.d.ts.map +1 -0
  54. package/dist/error/NativeAuthError.js +83 -0
  55. package/dist/error/NativeAuthError.js.map +1 -0
  56. package/dist/event/EventHandler.js +1 -1
  57. package/dist/event/EventMessage.js +1 -1
  58. package/dist/event/EventType.d.ts +2 -0
  59. package/dist/event/EventType.d.ts.map +1 -1
  60. package/dist/event/EventType.js +3 -1
  61. package/dist/event/EventType.js.map +1 -1
  62. package/dist/index.cjs.js +6130 -4824
  63. package/dist/index.cjs.js.map +1 -1
  64. package/dist/index.d.ts +6 -13
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +4 -13
  67. package/dist/index.js.map +1 -1
  68. package/dist/interaction_client/BaseInteractionClient.d.ts +12 -2
  69. package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
  70. package/dist/interaction_client/BaseInteractionClient.js +35 -3
  71. package/dist/interaction_client/BaseInteractionClient.js.map +1 -1
  72. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.js +1 -1
  73. package/dist/interaction_client/NativeInteractionClient.d.ts +57 -0
  74. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -0
  75. package/dist/interaction_client/NativeInteractionClient.js +337 -0
  76. package/dist/interaction_client/NativeInteractionClient.js.map +1 -0
  77. package/dist/interaction_client/PopupClient.d.ts +75 -2
  78. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  79. package/dist/interaction_client/PopupClient.js +315 -46
  80. package/dist/interaction_client/PopupClient.js.map +1 -1
  81. package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
  82. package/dist/interaction_client/RedirectClient.js +38 -9
  83. package/dist/interaction_client/RedirectClient.js.map +1 -1
  84. package/dist/interaction_client/SilentAuthCodeClient.d.ts +2 -1
  85. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  86. package/dist/interaction_client/SilentAuthCodeClient.js +3 -3
  87. package/dist/interaction_client/SilentAuthCodeClient.js.map +1 -1
  88. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  89. package/dist/interaction_client/SilentCacheClient.js +2 -4
  90. package/dist/interaction_client/SilentCacheClient.js.map +1 -1
  91. package/dist/interaction_client/SilentIframeClient.d.ts +5 -3
  92. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  93. package/dist/interaction_client/SilentIframeClient.js +38 -25
  94. package/dist/interaction_client/SilentIframeClient.js.map +1 -1
  95. package/dist/interaction_client/SilentRefreshClient.js +1 -1
  96. package/dist/interaction_client/StandardInteractionClient.d.ts +2 -8
  97. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  98. package/dist/interaction_client/StandardInteractionClient.js +5 -9
  99. package/dist/interaction_client/StandardInteractionClient.js.map +1 -1
  100. package/dist/interaction_handler/InteractionHandler.d.ts +3 -8
  101. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  102. package/dist/interaction_handler/InteractionHandler.js +19 -8
  103. package/dist/interaction_handler/InteractionHandler.js.map +1 -1
  104. package/dist/interaction_handler/RedirectHandler.d.ts +2 -2
  105. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  106. package/dist/interaction_handler/RedirectHandler.js +27 -20
  107. package/dist/interaction_handler/RedirectHandler.js.map +1 -1
  108. package/dist/interaction_handler/SilentHandler.d.ts +1 -1
  109. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  110. package/dist/interaction_handler/SilentHandler.js +5 -5
  111. package/dist/interaction_handler/SilentHandler.js.map +1 -1
  112. package/dist/internals.d.ts +17 -0
  113. package/dist/internals.d.ts.map +1 -0
  114. package/dist/internals.js +19 -0
  115. package/dist/internals.js.map +1 -0
  116. package/dist/navigation/NavigationClient.js +1 -1
  117. package/dist/network/FetchClient.js +1 -1
  118. package/dist/network/XhrClient.js +1 -1
  119. package/dist/packageMetadata.d.ts +1 -1
  120. package/dist/packageMetadata.js +2 -2
  121. package/dist/packageMetadata.js.map +1 -1
  122. package/dist/request/AuthorizationCodeRequest.d.ts +2 -1
  123. package/dist/request/AuthorizationCodeRequest.d.ts.map +1 -1
  124. package/dist/request/AuthorizationUrlRequest.d.ts +1 -1
  125. package/dist/request/AuthorizationUrlRequest.d.ts.map +1 -1
  126. package/dist/request/EndSessionPopupRequest.d.ts +1 -1
  127. package/dist/request/EndSessionPopupRequest.d.ts.map +1 -1
  128. package/dist/request/PopupRequest.d.ts +2 -2
  129. package/dist/request/PopupRequest.d.ts.map +1 -1
  130. package/dist/request/PopupWindowAttributes.d.ts +16 -0
  131. package/dist/request/PopupWindowAttributes.d.ts.map +1 -0
  132. package/dist/request/RedirectRequest.d.ts +1 -1
  133. package/dist/request/RedirectRequest.d.ts.map +1 -1
  134. package/dist/request/SsoSilentRequest.d.ts +2 -2
  135. package/dist/request/SsoSilentRequest.d.ts.map +1 -1
  136. package/dist/telemetry/BrowserPerformanceClient.js +1 -1
  137. package/dist/telemetry/BrowserPerformanceMeasurement.js +1 -1
  138. package/dist/utils/BrowserConstants.d.ts +12 -1
  139. package/dist/utils/BrowserConstants.d.ts.map +1 -1
  140. package/dist/utils/BrowserConstants.js +14 -2
  141. package/dist/utils/BrowserConstants.js.map +1 -1
  142. package/dist/utils/BrowserProtocolUtils.js +1 -1
  143. package/dist/utils/BrowserStringUtils.js +1 -1
  144. package/dist/utils/BrowserUtils.d.ts +6 -0
  145. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  146. package/dist/utils/BrowserUtils.js +11 -1
  147. package/dist/utils/BrowserUtils.js.map +1 -1
  148. package/dist/utils/MathUtils.js +1 -1
  149. package/lib/msal-browser.js +6130 -4824
  150. package/lib/msal-browser.js.map +1 -1
  151. package/lib/msal-browser.min.js +40 -40
  152. package/package.json +2 -2
  153. package/dist/interaction_handler/PopupHandler.d.ts +0 -29
  154. package/dist/interaction_handler/PopupHandler.d.ts.map +0 -1
  155. package/dist/interaction_handler/PopupHandler.js +0 -69
  156. package/dist/interaction_handler/PopupHandler.js.map +0 -1
  157. package/dist/utils/PopupUtils.d.ts +0 -73
  158. package/dist/utils/PopupUtils.d.ts.map +0 -1
  159. package/dist/utils/PopupUtils.js +0 -185
  160. package/dist/utils/PopupUtils.js.map +0 -1
@@ -1,11 +1,11 @@
1
- /*! @azure/msal-browser v2.23.0 2022-04-04 */
1
+ /*! @azure/msal-browser v2.25.0 2022-06-06 */
2
2
  'use strict';
3
3
  import { __awaiter, __generator, __assign } from '../_virtual/_tslib.js';
4
4
  import { CryptoOps } from '../crypto/CryptoOps.js';
5
- import { Constants, PerformanceEvents, StringUtils, Logger, StubPerformanceClient, DEFAULT_CRYPTO_IMPLEMENTATION, ServerError, InteractionRequiredAuthError } from '@azure/msal-common';
5
+ import { Constants, PerformanceEvents, PromptValue, StringUtils, Logger, StubPerformanceClient, DEFAULT_CRYPTO_IMPLEMENTATION, 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, BrowserCacheLocation, BrowserConstants } from '../utils/BrowserConstants.js';
8
+ import { InteractionType, ApiId, TemporaryCacheKeys, BrowserCacheLocation, BrowserConstants } from '../utils/BrowserConstants.js';
9
9
  import { BrowserUtils } from '../utils/BrowserUtils.js';
10
10
  import { name, version } from '../packageMetadata.js';
11
11
  import { EventType } from '../event/EventType.js';
@@ -16,6 +16,10 @@ import { RedirectClient } from '../interaction_client/RedirectClient.js';
16
16
  import { SilentIframeClient } from '../interaction_client/SilentIframeClient.js';
17
17
  import { SilentRefreshClient } from '../interaction_client/SilentRefreshClient.js';
18
18
  import { TokenCache } from '../cache/TokenCache.js';
19
+ import { NativeInteractionClient } from '../interaction_client/NativeInteractionClient.js';
20
+ import { NativeMessageHandler } from '../broker/nativeBroker/NativeMessageHandler.js';
21
+ import { NativeAuthError } from '../error/NativeAuthError.js';
22
+ import { SilentCacheClient } from '../interaction_client/SilentCacheClient.js';
19
23
  import { SilentAuthCodeClient } from '../interaction_client/SilentAuthCodeClient.js';
20
24
  import { BrowserAuthError } from '../error/BrowserAuthError.js';
21
25
  import { BrowserPerformanceClient } from '../telemetry/BrowserPerformanceClient.js';
@@ -55,6 +59,7 @@ var ClientApplication = /** @class */ (function () {
55
59
  this.isBrowserEnvironment = typeof window !== "undefined";
56
60
  // Set the configuration.
57
61
  this.config = buildConfiguration(configuration, this.isBrowserEnvironment);
62
+ this.initialized = false;
58
63
  // Initialize logger
59
64
  this.logger = new Logger(this.config.system.loggerOptions, name, version);
60
65
  // Initialize the network module class.
@@ -79,6 +84,42 @@ var ClientApplication = /** @class */ (function () {
79
84
  // Initialize the token cache
80
85
  this.tokenCache = new TokenCache(this.config, this.browserStorage, this.logger, this.browserCrypto);
81
86
  }
87
+ /**
88
+ * Initializer function to perform async startup tasks such as connecting to WAM extension
89
+ */
90
+ ClientApplication.prototype.initialize = function () {
91
+ return __awaiter(this, void 0, void 0, function () {
92
+ var _a, e_1;
93
+ return __generator(this, function (_b) {
94
+ switch (_b.label) {
95
+ case 0:
96
+ this.logger.trace("initialize called");
97
+ if (this.initialized) {
98
+ this.logger.info("initialize has already been called, exiting early.");
99
+ return [2 /*return*/];
100
+ }
101
+ this.eventHandler.emitEvent(EventType.INITIALIZE_START);
102
+ if (!this.config.system.allowNativeBroker) return [3 /*break*/, 4];
103
+ _b.label = 1;
104
+ case 1:
105
+ _b.trys.push([1, 3, , 4]);
106
+ _a = this;
107
+ return [4 /*yield*/, NativeMessageHandler.createProvider(this.logger, this.config.system.nativeBrokerHandshakeTimeout)];
108
+ case 2:
109
+ _a.nativeExtensionProvider = _b.sent();
110
+ return [3 /*break*/, 4];
111
+ case 3:
112
+ e_1 = _b.sent();
113
+ this.logger.verbose(e_1);
114
+ return [3 /*break*/, 4];
115
+ case 4:
116
+ this.initialized = true;
117
+ this.eventHandler.emitEvent(EventType.INITIALIZE_END);
118
+ return [2 /*return*/];
119
+ }
120
+ });
121
+ });
122
+ };
82
123
  // #region Redirect Flow
83
124
  /**
84
125
  * Event handler function which allows users to fire events after the PublicClientApplication object
@@ -89,10 +130,12 @@ var ClientApplication = /** @class */ (function () {
89
130
  */
90
131
  ClientApplication.prototype.handleRedirectPromise = function (hash) {
91
132
  return __awaiter(this, void 0, void 0, function () {
92
- var loggedInAccounts, redirectResponseKey, response, correlationId, redirectClient;
133
+ var loggedInAccounts, redirectResponseKey, response, request, redirectResponse, nativeClient, correlationId, redirectClient;
93
134
  var _this = this;
94
135
  return __generator(this, function (_a) {
95
136
  this.logger.verbose("handleRedirectPromise called");
137
+ // Block token acquisition before initialize has been called if native brokering is enabled
138
+ BrowserUtils.blockNativeBrokerCalledBeforeInitialized(this.config.system.allowNativeBroker, this.initialized);
96
139
  loggedInAccounts = this.getAllAccounts();
97
140
  if (this.isBrowserEnvironment) {
98
141
  redirectResponseKey = hash || Constants.EMPTY_STRING;
@@ -100,10 +143,20 @@ var ClientApplication = /** @class */ (function () {
100
143
  if (typeof response === "undefined") {
101
144
  this.eventHandler.emitEvent(EventType.HANDLE_REDIRECT_START, InteractionType.Redirect);
102
145
  this.logger.verbose("handleRedirectPromise has been called for the first time, storing the promise");
103
- correlationId = this.browserStorage.getTemporaryCache(TemporaryCacheKeys.CORRELATION_ID, true) || Constants.EMPTY_STRING;
104
- redirectClient = new RedirectClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, this.performanceClient, correlationId);
105
- response = redirectClient.handleRedirectPromise(hash)
106
- .then(function (result) {
146
+ request = this.browserStorage.getCachedNativeRequest();
147
+ redirectResponse = void 0;
148
+ if (request && NativeMessageHandler.isNativeAvailable(this.config, this.logger, this.nativeExtensionProvider) && this.nativeExtensionProvider && !hash) {
149
+ this.logger.trace("handleRedirectPromise - acquiring token from native platform");
150
+ nativeClient = new NativeInteractionClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, ApiId.handleRedirectPromise, this.performanceClient, this.nativeExtensionProvider, request.accountId, request.correlationId);
151
+ redirectResponse = nativeClient.handleRedirectPromise();
152
+ }
153
+ else {
154
+ this.logger.trace("handleRedirectPromise - acquiring token from web flow");
155
+ correlationId = this.browserStorage.getTemporaryCache(TemporaryCacheKeys.CORRELATION_ID, true) || Constants.EMPTY_STRING;
156
+ redirectClient = this.createRedirectClient(correlationId);
157
+ redirectResponse = redirectClient.handleRedirectPromise(hash);
158
+ }
159
+ response = redirectResponse.then(function (result) {
107
160
  if (result) {
108
161
  // Emit login event if number of accounts change
109
162
  var isLoggingIn = loggedInAccounts.length < _this.getAllAccounts().length;
@@ -118,8 +171,7 @@ var ClientApplication = /** @class */ (function () {
118
171
  }
119
172
  _this.eventHandler.emitEvent(EventType.HANDLE_REDIRECT_END, InteractionType.Redirect);
120
173
  return result;
121
- })
122
- .catch(function (e) {
174
+ }).catch(function (e) {
123
175
  // Emit login event if there is an account
124
176
  if (loggedInAccounts.length > 0) {
125
177
  _this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Redirect, null, e);
@@ -153,7 +205,7 @@ var ClientApplication = /** @class */ (function () {
153
205
  */
154
206
  ClientApplication.prototype.acquireTokenRedirect = function (request) {
155
207
  return __awaiter(this, void 0, void 0, function () {
156
- var correlationId, isLoggedIn, redirectClient;
208
+ var correlationId, isLoggedIn, result, nativeClient, redirectClient;
157
209
  var _this = this;
158
210
  return __generator(this, function (_a) {
159
211
  correlationId = this.getRequestCorrelationId(request);
@@ -166,8 +218,22 @@ var ClientApplication = /** @class */ (function () {
166
218
  else {
167
219
  this.eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Redirect, request);
168
220
  }
169
- redirectClient = new RedirectClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, this.performanceClient, correlationId);
170
- return [2 /*return*/, redirectClient.acquireToken(__assign(__assign({}, request), { correlationId: correlationId })).catch(function (e) {
221
+ if (this.nativeExtensionProvider && this.canUseNative(request)) {
222
+ nativeClient = new NativeInteractionClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, ApiId.acquireTokenRedirect, this.performanceClient, this.nativeExtensionProvider, this.getNativeAccountId(request), request.correlationId);
223
+ result = nativeClient.acquireTokenRedirect(request).catch(function (e) {
224
+ if (e instanceof NativeAuthError && e.isFatal()) {
225
+ _this.nativeExtensionProvider = undefined; // If extension gets uninstalled during session prevent future requests from continuing to attempt
226
+ var redirectClient = _this.createRedirectClient(request.correlationId);
227
+ return redirectClient.acquireToken(request);
228
+ }
229
+ throw e;
230
+ });
231
+ }
232
+ else {
233
+ redirectClient = this.createRedirectClient(request.correlationId);
234
+ result = redirectClient.acquireToken(request);
235
+ }
236
+ return [2 /*return*/, result.catch(function (e) {
171
237
  // If logged in, emit acquire token events
172
238
  if (isLoggedIn) {
173
239
  _this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Redirect, null, e);
@@ -192,6 +258,7 @@ var ClientApplication = /** @class */ (function () {
192
258
  ClientApplication.prototype.acquireTokenPopup = function (request) {
193
259
  var _this = this;
194
260
  var correlationId = this.getRequestCorrelationId(request);
261
+ var atPopupMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.AcquireTokenPopup, correlationId);
195
262
  try {
196
263
  this.logger.verbose("acquireTokenPopup called", correlationId);
197
264
  this.preflightBrowserEnvironmentCheck(InteractionType.Popup);
@@ -208,8 +275,30 @@ var ClientApplication = /** @class */ (function () {
208
275
  else {
209
276
  this.eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Popup, request);
210
277
  }
211
- var popupClient = new PopupClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, this.performanceClient, correlationId);
212
- return popupClient.acquireToken(__assign(__assign({}, request), { correlationId: correlationId })).then(function (result) {
278
+ var result;
279
+ if (this.canUseNative(request)) {
280
+ result = this.acquireTokenNative(request, ApiId.acquireTokenPopup).then(function (response) {
281
+ _this.browserStorage.setInteractionInProgress(false);
282
+ atPopupMeasurement.endMeasurement({
283
+ success: true,
284
+ isNativeBroker: true
285
+ });
286
+ atPopupMeasurement.flushMeasurement();
287
+ return response;
288
+ }).catch(function (e) {
289
+ if (e instanceof NativeAuthError && e.isFatal()) {
290
+ _this.nativeExtensionProvider = undefined; // If extension gets uninstalled during session prevent future requests from continuing to attempt
291
+ var popupClient = _this.createPopupClient(request.correlationId);
292
+ return popupClient.acquireToken(request);
293
+ }
294
+ throw e;
295
+ });
296
+ }
297
+ else {
298
+ var popupClient = this.createPopupClient(request.correlationId);
299
+ result = popupClient.acquireToken(request);
300
+ }
301
+ return result.then(function (result) {
213
302
  // If logged in, emit acquire token events
214
303
  var isLoggingIn = loggedInAccounts.length < _this.getAllAccounts().length;
215
304
  if (isLoggingIn) {
@@ -218,6 +307,10 @@ var ClientApplication = /** @class */ (function () {
218
307
  else {
219
308
  _this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, InteractionType.Popup, result);
220
309
  }
310
+ atPopupMeasurement.endMeasurement({
311
+ success: true
312
+ });
313
+ atPopupMeasurement.flushMeasurement();
221
314
  return result;
222
315
  }).catch(function (e) {
223
316
  if (loggedInAccounts.length > 0) {
@@ -226,6 +319,10 @@ var ClientApplication = /** @class */ (function () {
226
319
  else {
227
320
  _this.eventHandler.emitEvent(EventType.LOGIN_FAILURE, InteractionType.Popup, null, e);
228
321
  }
322
+ atPopupMeasurement.endMeasurement({
323
+ success: false
324
+ });
325
+ atPopupMeasurement.flushMeasurement();
229
326
  // Since this function is syncronous we need to reject
230
327
  return Promise.reject(e);
231
328
  });
@@ -249,38 +346,45 @@ var ClientApplication = /** @class */ (function () {
249
346
  */
250
347
  ClientApplication.prototype.ssoSilent = function (request) {
251
348
  return __awaiter(this, void 0, void 0, function () {
252
- var correlationId, ssoSilentMeasurement, silentIframeClient, silentTokenResult, e_1;
349
+ var correlationId, validRequest, ssoSilentMeasurement, result, silentIframeClient;
350
+ var _this = this;
253
351
  return __generator(this, function (_a) {
254
- switch (_a.label) {
255
- case 0:
256
- correlationId = this.getRequestCorrelationId(request);
257
- this.preflightBrowserEnvironmentCheck(InteractionType.Silent);
258
- ssoSilentMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.SsoSilent, correlationId);
259
- this.logger.verbose("ssoSilent called", correlationId);
260
- this.eventHandler.emitEvent(EventType.SSO_SILENT_START, InteractionType.Silent, request);
261
- _a.label = 1;
262
- case 1:
263
- _a.trys.push([1, 3, , 4]);
264
- silentIframeClient = new SilentIframeClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, ApiId.ssoSilent, this.performanceClient, correlationId);
265
- return [4 /*yield*/, silentIframeClient.acquireToken(__assign(__assign({}, request), { correlationId: correlationId }))];
266
- case 2:
267
- silentTokenResult = _a.sent();
268
- this.eventHandler.emitEvent(EventType.SSO_SILENT_SUCCESS, InteractionType.Silent, silentTokenResult);
352
+ correlationId = this.getRequestCorrelationId(request);
353
+ validRequest = __assign(__assign({}, request), { prompt: PromptValue.NONE, correlationId: correlationId });
354
+ this.preflightBrowserEnvironmentCheck(InteractionType.Silent);
355
+ ssoSilentMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.SsoSilent, correlationId);
356
+ this.logger.verbose("ssoSilent called", correlationId);
357
+ this.eventHandler.emitEvent(EventType.SSO_SILENT_START, InteractionType.Silent, validRequest);
358
+ if (this.canUseNative(validRequest)) {
359
+ result = this.acquireTokenNative(validRequest, ApiId.ssoSilent).catch(function (e) {
360
+ // If native token acquisition fails for availability reasons fallback to standard flow
361
+ if (e instanceof NativeAuthError && e.isFatal()) {
362
+ _this.nativeExtensionProvider = undefined; // If extension gets uninstalled during session prevent future requests from continuing to attempt
363
+ var silentIframeClient = _this.createSilentIframeClient(validRequest.correlationId);
364
+ return silentIframeClient.acquireToken(validRequest);
365
+ }
366
+ throw e;
367
+ });
368
+ }
369
+ else {
370
+ silentIframeClient = this.createSilentIframeClient(validRequest.correlationId);
371
+ result = silentIframeClient.acquireToken(validRequest);
372
+ }
373
+ return [2 /*return*/, result.then(function (response) {
374
+ _this.eventHandler.emitEvent(EventType.SSO_SILENT_SUCCESS, InteractionType.Silent, response);
269
375
  ssoSilentMeasurement.endMeasurement({
270
376
  success: true
271
377
  });
272
378
  ssoSilentMeasurement.flushMeasurement();
273
- return [2 /*return*/, silentTokenResult];
274
- case 3:
275
- e_1 = _a.sent();
276
- this.eventHandler.emitEvent(EventType.SSO_SILENT_FAILURE, InteractionType.Silent, null, e_1);
379
+ return response;
380
+ }).catch(function (e) {
381
+ _this.eventHandler.emitEvent(EventType.SSO_SILENT_FAILURE, InteractionType.Silent, null, e);
277
382
  ssoSilentMeasurement.endMeasurement({
278
383
  success: false
279
384
  });
280
385
  ssoSilentMeasurement.flushMeasurement();
281
- throw e_1;
282
- case 4: return [2 /*return*/];
283
- }
386
+ throw e;
387
+ })];
284
388
  });
285
389
  });
286
390
  };
@@ -296,7 +400,7 @@ var ClientApplication = /** @class */ (function () {
296
400
  */
297
401
  ClientApplication.prototype.acquireTokenByCode = function (request) {
298
402
  return __awaiter(this, void 0, void 0, function () {
299
- var correlationId, atbcMeasurement, response;
403
+ var correlationId, atbcMeasurement, hybridAuthCode_1, response;
300
404
  var _this = this;
301
405
  return __generator(this, function (_a) {
302
406
  correlationId = this.getRequestCorrelationId(request);
@@ -305,41 +409,58 @@ var ClientApplication = /** @class */ (function () {
305
409
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_START, InteractionType.Silent, request);
306
410
  atbcMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.AcquireTokenByCode, request.correlationId);
307
411
  try {
308
- if (!request.code) {
309
- throw BrowserAuthError.createAuthCodeRequiredError();
310
- }
311
- response = this.hybridAuthCodeResponses.get(request.code);
312
- if (!response) {
313
- this.logger.verbose("Initiating new acquireTokenByCode request", correlationId);
314
- response = this.acquireTokenByCodeAsync(__assign(__assign({}, request), { correlationId: correlationId }))
315
- .then(function (result) {
316
- _this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_SUCCESS, InteractionType.Silent, result);
317
- _this.hybridAuthCodeResponses.delete(request.code);
318
- atbcMeasurement.endMeasurement({
319
- success: true
412
+ if (request.code) {
413
+ hybridAuthCode_1 = request.code;
414
+ response = this.hybridAuthCodeResponses.get(hybridAuthCode_1);
415
+ if (!response) {
416
+ this.logger.verbose("Initiating new acquireTokenByCode request", correlationId);
417
+ response = this.acquireTokenByCodeAsync(__assign(__assign({}, request), { correlationId: correlationId }))
418
+ .then(function (result) {
419
+ _this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_SUCCESS, InteractionType.Silent, result);
420
+ _this.hybridAuthCodeResponses.delete(hybridAuthCode_1);
421
+ atbcMeasurement.endMeasurement({
422
+ success: true
423
+ });
424
+ atbcMeasurement.flushMeasurement();
425
+ return result;
426
+ })
427
+ .catch(function (error) {
428
+ _this.hybridAuthCodeResponses.delete(hybridAuthCode_1);
429
+ _this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_FAILURE, InteractionType.Silent, null, error);
430
+ atbcMeasurement.endMeasurement({
431
+ success: false
432
+ });
433
+ atbcMeasurement.flushMeasurement();
434
+ throw error;
320
435
  });
321
- atbcMeasurement.flushMeasurement();
322
- return result;
323
- })
324
- .catch(function (error) {
325
- _this.hybridAuthCodeResponses.delete(request.code);
326
- _this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_FAILURE, InteractionType.Silent, null, error);
436
+ this.hybridAuthCodeResponses.set(hybridAuthCode_1, response);
437
+ }
438
+ else {
439
+ this.logger.verbose("Existing acquireTokenByCode request found", request.correlationId);
327
440
  atbcMeasurement.endMeasurement({
328
- success: false
441
+ success: true
329
442
  });
330
- atbcMeasurement.flushMeasurement();
331
- throw error;
332
- });
333
- this.hybridAuthCodeResponses.set(request.code, response);
443
+ atbcMeasurement.discardMeasurement();
444
+ }
445
+ return [2 /*return*/, response];
446
+ }
447
+ else if (request.nativeAccountId) {
448
+ if (this.canUseNative(request, request.nativeAccountId)) {
449
+ return [2 /*return*/, this.acquireTokenNative(request, ApiId.acquireTokenByCode, request.nativeAccountId).catch(function (e) {
450
+ // If native token acquisition fails for availability reasons fallback to standard flow
451
+ if (e instanceof NativeAuthError && e.isFatal()) {
452
+ _this.nativeExtensionProvider = undefined; // If extension gets uninstalled during session prevent future requests from continuing to attempt
453
+ }
454
+ throw e;
455
+ })];
456
+ }
457
+ else {
458
+ throw BrowserAuthError.createUnableToAcquireTokenFromNativePlatformError();
459
+ }
334
460
  }
335
461
  else {
336
- this.logger.verbose("Existing acquireTokenByCode request found", request.correlationId);
337
- atbcMeasurement.endMeasurement({
338
- success: true
339
- });
340
- atbcMeasurement.discardMeasurement();
462
+ throw BrowserAuthError.createAuthCodeOrNativeAccountIdRequiredError();
341
463
  }
342
- return [2 /*return*/, response];
343
464
  }
344
465
  catch (e) {
345
466
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_BY_CODE_FAILURE, InteractionType.Silent, null, e);
@@ -364,7 +485,7 @@ var ClientApplication = /** @class */ (function () {
364
485
  switch (_a.label) {
365
486
  case 0:
366
487
  this.logger.trace("acquireTokenByCodeAsync called", request.correlationId);
367
- silentAuthCodeClient = new SilentAuthCodeClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, ApiId.acquireTokenByCode, this.performanceClient, request.correlationId);
488
+ silentAuthCodeClient = this.createSilentAuthCodeClient(request.correlationId);
368
489
  return [4 /*yield*/, silentAuthCodeClient.acquireToken(request)];
369
490
  case 1:
370
491
  silentTokenResult = _a.sent();
@@ -393,7 +514,7 @@ var ClientApplication = /** @class */ (function () {
393
514
  BrowserUtils.blockReloadInHiddenIframes();
394
515
  atbrtMeasurement = this.performanceClient.startMeasurement(PerformanceEvents.AcquireTokenByRefreshToken, request.correlationId);
395
516
  this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_NETWORK_START, InteractionType.Silent, request);
396
- silentRefreshClient = new SilentRefreshClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, this.performanceClient, request.correlationId);
517
+ silentRefreshClient = this.createSilentRefreshClient(request.correlationId);
397
518
  return [2 /*return*/, silentRefreshClient.acquireToken(request)
398
519
  .then(function (result) {
399
520
  atbrtMeasurement.endMeasurement({
@@ -408,7 +529,7 @@ var ClientApplication = /** @class */ (function () {
408
529
  var isInvalidGrantError = (e.errorCode === BrowserConstants.INVALID_GRANT_ERROR);
409
530
  if (isServerError && isInvalidGrantError && !isInteractionRequiredError) {
410
531
  _this.logger.verbose("Refresh token expired or invalid, attempting acquire token by iframe", request.correlationId);
411
- var silentIframeClient = new SilentIframeClient(_this.config, _this.browserStorage, _this.browserCrypto, _this.logger, _this.eventHandler, _this.navigationClient, ApiId.acquireTokenSilent_authCode, _this.performanceClient, request.correlationId);
532
+ var silentIframeClient = _this.createSilentIframeClient(request.correlationId);
412
533
  return silentIframeClient.acquireToken(request)
413
534
  .then(function (result) {
414
535
  atbrtMeasurement.endMeasurement({
@@ -460,8 +581,8 @@ var ClientApplication = /** @class */ (function () {
460
581
  return __generator(this, function (_a) {
461
582
  correlationId = this.getRequestCorrelationId(logoutRequest);
462
583
  this.preflightBrowserEnvironmentCheck(InteractionType.Redirect);
463
- redirectClient = new RedirectClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, this.performanceClient, correlationId);
464
- return [2 /*return*/, redirectClient.logout(__assign({ correlationId: correlationId }, logoutRequest))];
584
+ redirectClient = this.createRedirectClient(correlationId);
585
+ return [2 /*return*/, redirectClient.logout(logoutRequest)];
465
586
  });
466
587
  });
467
588
  };
@@ -473,8 +594,8 @@ var ClientApplication = /** @class */ (function () {
473
594
  try {
474
595
  var correlationId = this.getRequestCorrelationId(logoutRequest);
475
596
  this.preflightBrowserEnvironmentCheck(InteractionType.Popup);
476
- var popupClient = new PopupClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, this.performanceClient, correlationId);
477
- return popupClient.logout(__assign({ correlationId: correlationId }, logoutRequest));
597
+ var popupClient = this.createPopupClient(correlationId);
598
+ return popupClient.logout(logoutRequest);
478
599
  }
479
600
  catch (e) {
480
601
  // Since this function is syncronous we need to reject
@@ -580,6 +701,8 @@ var ClientApplication = /** @class */ (function () {
580
701
  BrowserUtils.blockReloadInHiddenIframes();
581
702
  // Block redirectUri opened in a popup from calling MSAL APIs
582
703
  BrowserUtils.blockAcquireTokenInPopups();
704
+ // Block token acquisition before initialize has been called if native brokering is enabled
705
+ BrowserUtils.blockNativeBrokerCalledBeforeInitialized(this.config.system.allowNativeBroker, this.initialized);
583
706
  // Block redirects if memory storage is enabled but storeAuthStateInCookie is not
584
707
  if (interactionType === InteractionType.Redirect &&
585
708
  this.config.cache.cacheLocation === BrowserCacheLocation.MemoryStorage &&
@@ -602,6 +725,98 @@ var ClientApplication = /** @class */ (function () {
602
725
  // Set interaction in progress temporary cache or throw if alread set.
603
726
  this.browserStorage.setInteractionInProgress(true);
604
727
  };
728
+ /**
729
+ * Acquire a token from native device (e.g. WAM)
730
+ * @param request
731
+ */
732
+ ClientApplication.prototype.acquireTokenNative = function (request, apiId, accountId) {
733
+ return __awaiter(this, void 0, void 0, function () {
734
+ var nativeClient;
735
+ return __generator(this, function (_a) {
736
+ this.logger.trace("acquireTokenNative called");
737
+ if (!this.nativeExtensionProvider) {
738
+ throw BrowserAuthError.createNativeConnectionNotEstablishedError();
739
+ }
740
+ nativeClient = new NativeInteractionClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, apiId, this.performanceClient, this.nativeExtensionProvider, accountId || this.getNativeAccountId(request), request.correlationId);
741
+ return [2 /*return*/, nativeClient.acquireToken(request)];
742
+ });
743
+ });
744
+ };
745
+ /**
746
+ * Returns boolean indicating if this request can use the native broker
747
+ * @param request
748
+ */
749
+ ClientApplication.prototype.canUseNative = function (request, accountId) {
750
+ this.logger.trace("canUseNative called");
751
+ if (!NativeMessageHandler.isNativeAvailable(this.config, this.logger, this.nativeExtensionProvider, request.authenticationScheme)) {
752
+ this.logger.trace("canUseNative: isNativeAvailable returned false, returning false");
753
+ return false;
754
+ }
755
+ if (request.prompt) {
756
+ switch (request.prompt) {
757
+ case PromptValue.NONE:
758
+ case PromptValue.CONSENT:
759
+ this.logger.trace("canUseNative: prompt is compatible with native flow");
760
+ break;
761
+ default:
762
+ this.logger.trace("canUseNative: prompt = " + request.prompt + " is not compatible with native flow, returning false");
763
+ return false;
764
+ }
765
+ }
766
+ if (!accountId && !this.getNativeAccountId(request)) {
767
+ this.logger.trace("canUseNative: nativeAccountId is not available, returning false");
768
+ return false;
769
+ }
770
+ return true;
771
+ };
772
+ /**
773
+ * Get the native accountId from the account
774
+ * @param request
775
+ * @returns
776
+ */
777
+ ClientApplication.prototype.getNativeAccountId = function (request) {
778
+ var account = request.account || this.browserStorage.getAccountInfoByHints(request.loginHint, request.sid) || this.getActiveAccount();
779
+ return account && account.nativeAccountId || "";
780
+ };
781
+ /**
782
+ * Returns new instance of the Popup Interaction Client
783
+ * @param correlationId
784
+ */
785
+ ClientApplication.prototype.createPopupClient = function (correlationId) {
786
+ return new PopupClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, this.performanceClient, this.nativeExtensionProvider, correlationId);
787
+ };
788
+ /**
789
+ * Returns new instance of the Popup Interaction Client
790
+ * @param correlationId
791
+ */
792
+ ClientApplication.prototype.createRedirectClient = function (correlationId) {
793
+ return new RedirectClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, this.performanceClient, this.nativeExtensionProvider, correlationId);
794
+ };
795
+ /**
796
+ * Returns new instance of the Silent Iframe Interaction Client
797
+ * @param correlationId
798
+ */
799
+ ClientApplication.prototype.createSilentIframeClient = function (correlationId) {
800
+ return new SilentIframeClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, ApiId.ssoSilent, this.performanceClient, this.nativeExtensionProvider, correlationId);
801
+ };
802
+ /**
803
+ * Returns new instance of the Silent Cache Interaction Client
804
+ */
805
+ ClientApplication.prototype.createSilentCacheClient = function (correlationId) {
806
+ return new SilentCacheClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, this.performanceClient, this.nativeExtensionProvider, correlationId);
807
+ };
808
+ /**
809
+ * Returns new instance of the Silent Refresh Interaction Client
810
+ */
811
+ ClientApplication.prototype.createSilentRefreshClient = function (correlationId) {
812
+ return new SilentRefreshClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, this.performanceClient, this.nativeExtensionProvider, correlationId);
813
+ };
814
+ /**
815
+ * Returns new instance of the Silent AuthCode Interaction Client
816
+ */
817
+ ClientApplication.prototype.createSilentAuthCodeClient = function (correlationId) {
818
+ return new SilentAuthCodeClient(this.config, this.browserStorage, this.browserCrypto, this.logger, this.eventHandler, this.navigationClient, ApiId.acquireTokenByCode, this.performanceClient, this.nativeExtensionProvider, correlationId);
819
+ };
605
820
  /**
606
821
  * Adds event callbacks to array
607
822
  * @param callback