@azure/msal-browser 3.2.0 → 3.3.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 (202) hide show
  1. package/dist/app/IPublicClientApplication.mjs +1 -1
  2. package/dist/app/PublicClientApplication.mjs +2 -2
  3. package/dist/app/PublicClientApplication.mjs.map +1 -1
  4. package/dist/app/PublicClientNext.d.ts +274 -0
  5. package/dist/app/PublicClientNext.d.ts.map +1 -0
  6. package/dist/app/PublicClientNext.mjs +362 -0
  7. package/dist/app/PublicClientNext.mjs.map +1 -0
  8. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +1 -1
  9. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +1 -1
  10. package/dist/cache/AsyncMemoryStorage.mjs +1 -1
  11. package/dist/cache/BrowserCacheManager.d.ts +2 -13
  12. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  13. package/dist/cache/BrowserCacheManager.mjs +7 -64
  14. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  15. package/dist/cache/BrowserStorage.mjs +1 -1
  16. package/dist/cache/CryptoKeyStore.mjs +1 -1
  17. package/dist/cache/DatabaseStorage.mjs +1 -1
  18. package/dist/cache/MemoryStorage.mjs +1 -1
  19. package/dist/cache/TokenCache.mjs +1 -1
  20. package/dist/config/Configuration.d.ts +4 -0
  21. package/dist/config/Configuration.d.ts.map +1 -1
  22. package/dist/config/Configuration.mjs +2 -1
  23. package/dist/config/Configuration.mjs.map +1 -1
  24. package/dist/controllers/ControllerFactory.d.ts +2 -1
  25. package/dist/controllers/ControllerFactory.d.ts.map +1 -1
  26. package/dist/controllers/ControllerFactory.mjs +26 -19
  27. package/dist/controllers/ControllerFactory.mjs.map +1 -1
  28. package/dist/controllers/NestedAppAuthController.d.ts +96 -0
  29. package/dist/controllers/NestedAppAuthController.d.ts.map +1 -0
  30. package/dist/controllers/NestedAppAuthController.mjs +345 -0
  31. package/dist/controllers/NestedAppAuthController.mjs.map +1 -0
  32. package/dist/controllers/StandardController.d.ts.map +1 -1
  33. package/dist/controllers/StandardController.mjs +16 -13
  34. package/dist/controllers/StandardController.mjs.map +1 -1
  35. package/dist/controllers/UnknownOperatingContextController.d.ts +88 -0
  36. package/dist/controllers/UnknownOperatingContextController.d.ts.map +1 -0
  37. package/dist/controllers/UnknownOperatingContextController.mjs +275 -0
  38. package/dist/controllers/UnknownOperatingContextController.mjs.map +1 -0
  39. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  40. package/dist/crypto/BrowserCrypto.mjs +3 -3
  41. package/dist/crypto/BrowserCrypto.mjs.map +1 -1
  42. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  43. package/dist/crypto/CryptoOps.mjs +8 -5
  44. package/dist/crypto/CryptoOps.mjs.map +1 -1
  45. package/dist/crypto/PkceGenerator.mjs +1 -1
  46. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  47. package/dist/encode/Base64Decode.mjs +1 -1
  48. package/dist/encode/Base64Encode.mjs +1 -1
  49. package/dist/error/BrowserAuthError.mjs +1 -1
  50. package/dist/error/BrowserAuthErrorCodes.mjs +1 -1
  51. package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
  52. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +1 -1
  53. package/dist/error/NativeAuthError.mjs +1 -1
  54. package/dist/error/NativeAuthErrorCodes.mjs +1 -1
  55. package/dist/error/NestedAppAuthError.d.ts +15 -0
  56. package/dist/error/NestedAppAuthError.d.ts.map +1 -0
  57. package/dist/error/NestedAppAuthError.mjs +30 -0
  58. package/dist/error/NestedAppAuthError.mjs.map +1 -0
  59. package/dist/event/EventHandler.mjs +1 -1
  60. package/dist/event/EventMessage.mjs +1 -1
  61. package/dist/event/EventType.mjs +1 -1
  62. package/dist/index.d.ts +3 -5
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.mjs +4 -2
  65. package/dist/index.mjs.map +1 -1
  66. package/dist/interaction_client/BaseInteractionClient.mjs +4 -4
  67. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  68. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  69. package/dist/interaction_client/NativeInteractionClient.mjs +15 -4
  70. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  71. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  72. package/dist/interaction_client/PopupClient.mjs +5 -4
  73. package/dist/interaction_client/PopupClient.mjs.map +1 -1
  74. package/dist/interaction_client/RedirectClient.mjs +7 -7
  75. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  76. package/dist/interaction_client/SilentAuthCodeClient.mjs +4 -4
  77. package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
  78. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  79. package/dist/interaction_client/SilentCacheClient.mjs +4 -3
  80. package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
  81. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  82. package/dist/interaction_client/SilentIframeClient.mjs +27 -13
  83. package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
  84. package/dist/interaction_client/SilentRefreshClient.mjs +1 -1
  85. package/dist/interaction_client/StandardInteractionClient.mjs +5 -5
  86. package/dist/interaction_handler/InteractionHandler.mjs +1 -1
  87. package/dist/interaction_handler/RedirectHandler.mjs +1 -1
  88. package/dist/interaction_handler/SilentHandler.d.ts +13 -47
  89. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  90. package/dist/interaction_handler/SilentHandler.mjs +120 -155
  91. package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
  92. package/dist/naa/AccountInfo.d.ts +13 -0
  93. package/dist/naa/AccountInfo.d.ts.map +1 -0
  94. package/dist/naa/AccountRequests.d.ts +10 -0
  95. package/dist/naa/AccountRequests.d.ts.map +1 -0
  96. package/dist/naa/AuthBridge.d.ts +6 -0
  97. package/dist/naa/AuthBridge.d.ts.map +1 -0
  98. package/dist/naa/BridgeCapabilities.d.ts +4 -0
  99. package/dist/naa/BridgeCapabilities.d.ts.map +1 -0
  100. package/dist/naa/BridgeError.d.ts +10 -0
  101. package/dist/naa/BridgeError.d.ts.map +1 -0
  102. package/dist/naa/BridgeError.mjs +12 -0
  103. package/dist/naa/BridgeError.mjs.map +1 -0
  104. package/dist/naa/BridgeProxy.d.ts +72 -0
  105. package/dist/naa/BridgeProxy.d.ts.map +1 -0
  106. package/dist/naa/BridgeProxy.mjs +154 -0
  107. package/dist/naa/BridgeProxy.mjs.map +1 -0
  108. package/dist/naa/BridgeRequest.d.ts +7 -0
  109. package/dist/naa/BridgeRequest.d.ts.map +1 -0
  110. package/dist/naa/BridgeRequestEnvelope.d.ts +14 -0
  111. package/dist/naa/BridgeRequestEnvelope.d.ts.map +1 -0
  112. package/dist/naa/BridgeResponseEnvelope.d.ts +11 -0
  113. package/dist/naa/BridgeResponseEnvelope.d.ts.map +1 -0
  114. package/dist/naa/BridgeStatusCode.d.ts +11 -0
  115. package/dist/naa/BridgeStatusCode.d.ts.map +1 -0
  116. package/dist/naa/BridgeStatusCode.mjs +20 -0
  117. package/dist/naa/BridgeStatusCode.mjs.map +1 -0
  118. package/dist/naa/IBridgeProxy.d.ts +11 -0
  119. package/dist/naa/IBridgeProxy.d.ts.map +1 -0
  120. package/dist/naa/InitializeBridgeResponse.d.ts +7 -0
  121. package/dist/naa/InitializeBridgeResponse.d.ts.map +1 -0
  122. package/dist/naa/TokenRequest.d.ts +22 -0
  123. package/dist/naa/TokenRequest.d.ts.map +1 -0
  124. package/dist/naa/TokenResponse.d.ts +17 -0
  125. package/dist/naa/TokenResponse.d.ts.map +1 -0
  126. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts +26 -0
  127. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts.map +1 -0
  128. package/dist/naa/mapping/NestedAppAuthAdapter.mjs +178 -0
  129. package/dist/naa/mapping/NestedAppAuthAdapter.mjs.map +1 -0
  130. package/dist/navigation/NavigationClient.mjs +1 -1
  131. package/dist/network/FetchClient.mjs +1 -1
  132. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  133. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  134. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts +7 -0
  135. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts.map +1 -1
  136. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +45 -4
  137. package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
  138. package/dist/operatingcontext/UnknownOperatingContext.d.ts +26 -0
  139. package/dist/operatingcontext/UnknownOperatingContext.d.ts.map +1 -0
  140. package/dist/operatingcontext/UnknownOperatingContext.mjs +49 -0
  141. package/dist/operatingcontext/UnknownOperatingContext.mjs.map +1 -0
  142. package/dist/packageMetadata.d.ts +1 -1
  143. package/dist/packageMetadata.mjs +2 -2
  144. package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
  145. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  146. package/dist/utils/BrowserConstants.mjs +1 -1
  147. package/dist/utils/BrowserProtocolUtils.mjs +1 -1
  148. package/dist/utils/BrowserUtils.d.ts +54 -53
  149. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  150. package/dist/utils/BrowserUtils.mjs +114 -102
  151. package/dist/utils/BrowserUtils.mjs.map +1 -1
  152. package/lib/msal-browser.cjs +61 -17728
  153. package/lib/msal-browser.cjs.map +1 -1
  154. package/lib/msal-browser.js +14625 -13223
  155. package/lib/msal-browser.js.map +1 -1
  156. package/lib/msal-browser.min.js +66 -68
  157. package/package.json +2 -2
  158. package/src/app/PublicClientApplication.ts +1 -1
  159. package/src/app/PublicClientNext.ts +442 -0
  160. package/src/cache/BrowserCacheManager.ts +11 -100
  161. package/src/config/Configuration.ts +5 -0
  162. package/src/controllers/ControllerFactory.ts +36 -25
  163. package/src/controllers/NestedAppAuthController.ts +525 -0
  164. package/src/controllers/StandardController.ts +8 -6
  165. package/src/controllers/UnknownOperatingContextController.ts +383 -0
  166. package/src/crypto/BrowserCrypto.ts +2 -2
  167. package/src/crypto/CryptoOps.ts +8 -5
  168. package/src/error/NestedAppAuthError.ts +32 -0
  169. package/src/index.ts +3 -10
  170. package/src/interaction_client/BaseInteractionClient.ts +1 -1
  171. package/src/interaction_client/NativeInteractionClient.ts +19 -3
  172. package/src/interaction_client/PopupClient.ts +2 -1
  173. package/src/interaction_client/RedirectClient.ts +1 -1
  174. package/src/interaction_client/SilentAuthCodeClient.ts +5 -4
  175. package/src/interaction_client/SilentCacheClient.ts +11 -3
  176. package/src/interaction_client/SilentIframeClient.ts +53 -17
  177. package/src/interaction_client/StandardInteractionClient.ts +1 -1
  178. package/src/interaction_handler/SilentHandler.ts +177 -233
  179. package/src/naa/AccountInfo.ts +17 -0
  180. package/src/naa/AccountRequests.ts +16 -0
  181. package/src/naa/AuthBridge.ts +16 -0
  182. package/src/naa/BridgeCapabilities.ts +8 -0
  183. package/src/naa/BridgeError.ts +18 -0
  184. package/src/naa/BridgeProxy.ts +230 -0
  185. package/src/naa/BridgeRequest.ts +12 -0
  186. package/src/naa/BridgeRequestEnvelope.ts +46 -0
  187. package/src/naa/BridgeResponseEnvelope.ts +21 -0
  188. package/src/naa/BridgeStatusCode.ts +15 -0
  189. package/src/naa/IBridgeProxy.ts +25 -0
  190. package/src/naa/InitializeBridgeResponse.ts +12 -0
  191. package/src/naa/TokenRequest.ts +26 -0
  192. package/src/naa/TokenResponse.ts +61 -0
  193. package/src/naa/mapping/NestedAppAuthAdapter.ts +252 -0
  194. package/src/operatingcontext/TeamsAppOperatingContext.ts +43 -3
  195. package/src/operatingcontext/UnknownOperatingContext.ts +48 -0
  196. package/src/packageMetadata.ts +1 -1
  197. package/src/utils/BrowserUtils.ts +133 -125
  198. package/dist/utils/BrowserStringUtils.d.ts +0 -22
  199. package/dist/utils/BrowserStringUtils.d.ts.map +0 -1
  200. package/dist/utils/BrowserStringUtils.mjs +0 -144
  201. package/dist/utils/BrowserStringUtils.mjs.map +0 -1
  202. package/src/utils/BrowserStringUtils.ts +0 -143
@@ -25,31 +25,42 @@ export class ControllerFactory {
25
25
  this.logger = new Logger(loggerOptions, name, version);
26
26
  }
27
27
 
28
- async createController(): Promise<IController> {
28
+ async createV3Controller(): Promise<IController> {
29
29
  const standard = new StandardOperatingContext(this.config);
30
- const metaOS = new TeamsAppOperatingContext(this.config);
31
-
32
- const operatingContexts = [standard.initialize(), metaOS.initialize()];
33
-
34
- return Promise.all(operatingContexts).then(async () => {
35
- if (metaOS.isAvailable()) {
36
- /*
37
- * pull down metaos module
38
- * create associated controller
39
- */
40
- // return await StandardController.createController(standard);
41
- const controller = await import("./StandardController");
42
- return await controller.StandardController.createController(
43
- standard
44
- );
45
- } else if (standard.isAvailable()) {
46
- const controller = await import("./StandardController");
47
- return await controller.StandardController.createController(
48
- standard
49
- );
50
- }
51
-
52
- throw new Error("No controller found.");
53
- });
30
+
31
+ await standard.initialize();
32
+
33
+ const controller = await import("./StandardController");
34
+ return await controller.StandardController.createController(standard);
35
+ }
36
+
37
+ async createController(): Promise<IController | null> {
38
+ const standard = new StandardOperatingContext(this.config);
39
+ const teamsApp = new TeamsAppOperatingContext(this.config);
40
+
41
+ const operatingContexts = [
42
+ standard.initialize(),
43
+ teamsApp.initialize(),
44
+ ];
45
+
46
+ await Promise.all(operatingContexts);
47
+
48
+ if (
49
+ teamsApp.isAvailable() &&
50
+ teamsApp.getConfig().auth.supportsNestedAppAuth
51
+ ) {
52
+ const controller = await import("./NestedAppAuthController");
53
+ return await controller.NestedAppAuthController.createController(
54
+ teamsApp
55
+ );
56
+ } else if (standard.isAvailable()) {
57
+ const controller = await import("./StandardController");
58
+ return await controller.StandardController.createController(
59
+ standard
60
+ );
61
+ } else {
62
+ // Since neither of the actual operating contexts are available keep the UnknownOperatingContextController
63
+ return null;
64
+ }
54
65
  }
55
66
  }
@@ -0,0 +1,525 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ CommonAuthorizationUrlRequest,
8
+ CommonSilentFlowRequest,
9
+ PerformanceCallbackFunction,
10
+ AccountInfo,
11
+ Logger,
12
+ ICrypto,
13
+ IPerformanceClient,
14
+ DEFAULT_CRYPTO_IMPLEMENTATION,
15
+ PerformanceEvents,
16
+ AccountFilter,
17
+ } from "@azure/msal-common";
18
+ import { ITokenCache } from "../cache/ITokenCache";
19
+ import { BrowserConfiguration } from "../config/Configuration";
20
+ import { INavigationClient } from "../navigation/INavigationClient";
21
+ import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest";
22
+ import { EndSessionPopupRequest } from "../request/EndSessionPopupRequest";
23
+ import { EndSessionRequest } from "../request/EndSessionRequest";
24
+ import { PopupRequest } from "../request/PopupRequest";
25
+ import { RedirectRequest } from "../request/RedirectRequest";
26
+ import { SilentRequest } from "../request/SilentRequest";
27
+ import { SsoSilentRequest } from "../request/SsoSilentRequest";
28
+ import { ApiId, WrapperSKU, InteractionType } from "../utils/BrowserConstants";
29
+ import { IController } from "./IController";
30
+ import { TeamsAppOperatingContext } from "../operatingcontext/TeamsAppOperatingContext";
31
+ import { IBridgeProxy } from "../naa/IBridgeProxy";
32
+ import { CryptoOps } from "../crypto/CryptoOps";
33
+ import { NestedAppAuthAdapter } from "../naa/mapping/NestedAppAuthAdapter";
34
+ import { NestedAppAuthError } from "../error/NestedAppAuthError";
35
+ import { EventHandler } from "../event/EventHandler";
36
+ import { EventType } from "../event/EventType";
37
+ import { EventCallbackFunction, EventError } from "../event/EventMessage";
38
+ import { AuthenticationResult } from "../response/AuthenticationResult";
39
+ import { BrowserCacheManager } from "../cache/BrowserCacheManager";
40
+ import { ClearCacheRequest } from "../request/ClearCacheRequest";
41
+
42
+ export class NestedAppAuthController implements IController {
43
+ // OperatingContext
44
+ protected readonly operatingContext: TeamsAppOperatingContext;
45
+
46
+ // BridgeProxy
47
+ protected readonly bridgeProxy: IBridgeProxy;
48
+
49
+ // Crypto interface implementation
50
+ protected readonly browserCrypto: ICrypto;
51
+
52
+ // Input configuration by developer/user
53
+ protected readonly config: BrowserConfiguration;
54
+
55
+ // Logger
56
+ protected logger: Logger;
57
+
58
+ // Performance telemetry client
59
+ protected readonly performanceClient: IPerformanceClient;
60
+
61
+ // EventHandler
62
+ protected readonly eventHandler: EventHandler;
63
+
64
+ // NestedAppAuthAdapter
65
+ protected readonly nestedAppAuthAdapter: NestedAppAuthAdapter;
66
+
67
+ constructor(operatingContext: TeamsAppOperatingContext) {
68
+ this.operatingContext = operatingContext;
69
+ const proxy = this.operatingContext.getBridgeProxy();
70
+ if (proxy !== undefined) {
71
+ this.bridgeProxy = proxy;
72
+ } else {
73
+ throw new Error("unexpected: bridgeProxy is undefined");
74
+ }
75
+
76
+ // Set the configuration.
77
+ this.config = operatingContext.getConfig();
78
+
79
+ // Initialize logger
80
+ this.logger = this.operatingContext.getLogger();
81
+ // Initialize performance client
82
+ this.performanceClient = this.config.telemetry.client;
83
+
84
+ // Initialize the crypto class.
85
+ this.browserCrypto = operatingContext.isBrowserEnvironment()
86
+ ? new CryptoOps(this.logger, this.performanceClient)
87
+ : DEFAULT_CRYPTO_IMPLEMENTATION;
88
+
89
+ this.eventHandler = new EventHandler(this.logger, this.browserCrypto);
90
+
91
+ this.nestedAppAuthAdapter = new NestedAppAuthAdapter(
92
+ this.config.auth.clientId,
93
+ this.config.auth.clientCapabilities,
94
+ this.browserCrypto,
95
+ this.logger
96
+ );
97
+ }
98
+ getBrowserStorage(): BrowserCacheManager {
99
+ throw NestedAppAuthError.createUnsupportedError();
100
+ }
101
+
102
+ getEventHandler(): EventHandler {
103
+ return this.eventHandler;
104
+ }
105
+
106
+ static async createController(
107
+ operatingContext: TeamsAppOperatingContext
108
+ ): Promise<IController> {
109
+ const controller = new NestedAppAuthController(operatingContext);
110
+ return Promise.resolve(controller);
111
+ }
112
+
113
+ initialize(): Promise<void> {
114
+ // do nothing not required by this controller
115
+ return Promise.resolve();
116
+ }
117
+
118
+ private async acquireTokenInteractive(
119
+ request: PopupRequest | RedirectRequest
120
+ ): Promise<AuthenticationResult> {
121
+ this.eventHandler.emitEvent(
122
+ EventType.ACQUIRE_TOKEN_START,
123
+ InteractionType.Popup,
124
+ request
125
+ );
126
+
127
+ const atPopupMeasurement = this.performanceClient.startMeasurement(
128
+ PerformanceEvents.AcquireTokenPopup,
129
+ request.correlationId
130
+ );
131
+
132
+ atPopupMeasurement?.add({ nestedAppAuthRequest: true });
133
+
134
+ try {
135
+ const naaRequest =
136
+ this.nestedAppAuthAdapter.toNaaTokenRequest(request);
137
+ const response = await this.bridgeProxy.getTokenInteractive(
138
+ naaRequest
139
+ );
140
+ const result: AuthenticationResult =
141
+ this.nestedAppAuthAdapter.fromNaaTokenResponse(
142
+ naaRequest,
143
+ response
144
+ );
145
+
146
+ this.operatingContext.setActiveAccount(result.account);
147
+ this.eventHandler.emitEvent(
148
+ EventType.ACQUIRE_TOKEN_SUCCESS,
149
+ InteractionType.Popup,
150
+ result
151
+ );
152
+
153
+ atPopupMeasurement.add({
154
+ accessTokenSize: result.accessToken.length,
155
+ idTokenSize: result.idToken.length,
156
+ });
157
+
158
+ atPopupMeasurement.end({
159
+ success: true,
160
+ requestId: result.requestId,
161
+ });
162
+
163
+ return result;
164
+ } catch (e) {
165
+ const error = this.nestedAppAuthAdapter.fromBridgeError(e);
166
+ this.eventHandler.emitEvent(
167
+ EventType.ACQUIRE_TOKEN_FAILURE,
168
+ InteractionType.Popup,
169
+ null,
170
+ e as EventError
171
+ );
172
+
173
+ atPopupMeasurement.end({
174
+ errorCode: error.errorCode,
175
+ subErrorCode: error.subError,
176
+ success: false,
177
+ });
178
+
179
+ throw error;
180
+ }
181
+ }
182
+
183
+ private async acquireTokenSilentInternal(
184
+ request: SilentRequest
185
+ ): Promise<AuthenticationResult> {
186
+ this.eventHandler.emitEvent(
187
+ EventType.ACQUIRE_TOKEN_START,
188
+ InteractionType.Silent,
189
+ request
190
+ );
191
+
192
+ const ssoSilentMeasurement = this.performanceClient.startMeasurement(
193
+ PerformanceEvents.SsoSilent,
194
+ request.correlationId
195
+ );
196
+
197
+ ssoSilentMeasurement?.increment({
198
+ visibilityChangeCount: 0,
199
+ });
200
+
201
+ ssoSilentMeasurement?.add({
202
+ nestedAppAuthRequest: true,
203
+ });
204
+
205
+ try {
206
+ const naaRequest =
207
+ this.nestedAppAuthAdapter.toNaaSilentTokenRequest(request);
208
+ const response = await this.bridgeProxy.getTokenSilent(naaRequest);
209
+
210
+ const result: AuthenticationResult =
211
+ this.nestedAppAuthAdapter.fromNaaTokenResponse(
212
+ naaRequest,
213
+ response
214
+ );
215
+
216
+ this.operatingContext.setActiveAccount(result.account);
217
+ this.eventHandler.emitEvent(
218
+ EventType.ACQUIRE_TOKEN_SUCCESS,
219
+ InteractionType.Silent,
220
+ result
221
+ );
222
+ ssoSilentMeasurement?.add({
223
+ accessTokenSize: result.accessToken.length,
224
+ idTokenSize: result.idToken.length,
225
+ });
226
+ ssoSilentMeasurement?.end({
227
+ success: true,
228
+ requestId: result.requestId,
229
+ });
230
+ return result;
231
+ } catch (e) {
232
+ const error = this.nestedAppAuthAdapter.fromBridgeError(e);
233
+ this.eventHandler.emitEvent(
234
+ EventType.ACQUIRE_TOKEN_FAILURE,
235
+ InteractionType.Silent,
236
+ null,
237
+ e as EventError
238
+ );
239
+ ssoSilentMeasurement?.end({
240
+ errorCode: error.errorCode,
241
+ subErrorCode: error.subError,
242
+ success: false,
243
+ });
244
+ throw error;
245
+ }
246
+ }
247
+
248
+ async acquireTokenPopup(
249
+ request: PopupRequest
250
+ ): Promise<AuthenticationResult> {
251
+ return this.acquireTokenInteractive(request);
252
+ }
253
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
254
+ acquireTokenRedirect(request: RedirectRequest): Promise<void> {
255
+ throw NestedAppAuthError.createUnsupportedError();
256
+ }
257
+
258
+ async acquireTokenSilent(
259
+ silentRequest: SilentRequest
260
+ ): Promise<AuthenticationResult> {
261
+ return this.acquireTokenSilentInternal(silentRequest);
262
+ }
263
+
264
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
265
+ acquireTokenByCode(
266
+ request: AuthorizationCodeRequest // eslint-disable-line @typescript-eslint/no-unused-vars
267
+ ): Promise<AuthenticationResult> {
268
+ throw NestedAppAuthError.createUnsupportedError();
269
+ }
270
+ acquireTokenNative(
271
+ request: // eslint-disable-line @typescript-eslint/no-unused-vars
272
+ | SilentRequest
273
+ | Partial<
274
+ Omit<
275
+ CommonAuthorizationUrlRequest,
276
+ | "requestedClaimsHash"
277
+ | "responseMode"
278
+ | "codeChallenge"
279
+ | "codeChallengeMethod"
280
+ | "nativeBroker"
281
+ >
282
+ >
283
+ | PopupRequest,
284
+ apiId: ApiId, // eslint-disable-line @typescript-eslint/no-unused-vars
285
+ accountId?: string | undefined // eslint-disable-line @typescript-eslint/no-unused-vars
286
+ ): Promise<AuthenticationResult> {
287
+ throw NestedAppAuthError.createUnsupportedError();
288
+ }
289
+ acquireTokenByRefreshToken(
290
+ commonRequest: CommonSilentFlowRequest, // eslint-disable-line @typescript-eslint/no-unused-vars
291
+ silentRequest: SilentRequest // eslint-disable-line @typescript-eslint/no-unused-vars
292
+ ): Promise<AuthenticationResult> {
293
+ throw NestedAppAuthError.createUnsupportedError();
294
+ }
295
+
296
+ /**
297
+ * Adds event callbacks to array
298
+ * @param callback
299
+ */
300
+ addEventCallback(callback: EventCallbackFunction): string | null {
301
+ return this.eventHandler.addEventCallback(callback);
302
+ }
303
+
304
+ /**
305
+ * Removes callback with provided id from callback array
306
+ * @param callbackId
307
+ */
308
+ removeEventCallback(callbackId: string): void {
309
+ this.eventHandler.removeEventCallback(callbackId);
310
+ }
311
+
312
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
313
+ addPerformanceCallback(callback: PerformanceCallbackFunction): string {
314
+ throw NestedAppAuthError.createUnsupportedError();
315
+ }
316
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
317
+ removePerformanceCallback(callbackId: string): boolean {
318
+ throw NestedAppAuthError.createUnsupportedError();
319
+ }
320
+ enableAccountStorageEvents(): void {
321
+ throw NestedAppAuthError.createUnsupportedError();
322
+ }
323
+ disableAccountStorageEvents(): void {
324
+ throw NestedAppAuthError.createUnsupportedError();
325
+ }
326
+
327
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
328
+ getAccount(accountFilter: AccountFilter): AccountInfo | null {
329
+ throw NestedAppAuthError.createUnsupportedError();
330
+ // TODO: Look at standard implementation
331
+ }
332
+
333
+ getAccountByHomeId(homeAccountId: string): AccountInfo | null {
334
+ const currentAccount = this.operatingContext.getActiveAccount();
335
+ if (currentAccount !== undefined) {
336
+ if (currentAccount.homeAccountId === homeAccountId) {
337
+ return this.nestedAppAuthAdapter.fromNaaAccountInfo(
338
+ currentAccount
339
+ );
340
+ } else {
341
+ return null;
342
+ }
343
+ } else {
344
+ return null;
345
+ }
346
+ }
347
+
348
+ getAccountByLocalId(localId: string): AccountInfo | null {
349
+ const currentAccount = this.operatingContext.getActiveAccount();
350
+ if (currentAccount !== undefined) {
351
+ if (currentAccount.localAccountId === localId) {
352
+ return this.nestedAppAuthAdapter.fromNaaAccountInfo(
353
+ currentAccount
354
+ );
355
+ } else {
356
+ return null;
357
+ }
358
+ } else {
359
+ return null;
360
+ }
361
+ }
362
+
363
+ getAccountByUsername(userName: string): AccountInfo | null {
364
+ const currentAccount = this.operatingContext.getActiveAccount();
365
+ if (currentAccount !== undefined) {
366
+ if (currentAccount.username === userName) {
367
+ return this.nestedAppAuthAdapter.fromNaaAccountInfo(
368
+ currentAccount
369
+ );
370
+ } else {
371
+ return null;
372
+ }
373
+ } else {
374
+ return null;
375
+ }
376
+ }
377
+ getAllAccounts(): AccountInfo[] {
378
+ const currentAccount = this.operatingContext.getActiveAccount();
379
+ if (currentAccount !== undefined) {
380
+ return [
381
+ this.nestedAppAuthAdapter.fromNaaAccountInfo(currentAccount),
382
+ ];
383
+ } else {
384
+ return [];
385
+ }
386
+ }
387
+ handleRedirectPromise(
388
+ hash?: string | undefined // eslint-disable-line @typescript-eslint/no-unused-vars
389
+ ): Promise<AuthenticationResult | null> {
390
+ throw NestedAppAuthError.createUnsupportedError();
391
+ }
392
+ loginPopup(
393
+ request?: PopupRequest | undefined // eslint-disable-line @typescript-eslint/no-unused-vars
394
+ ): Promise<AuthenticationResult> {
395
+ if (request !== undefined) {
396
+ return this.acquireTokenInteractive(request);
397
+ } else {
398
+ throw NestedAppAuthError.createUnsupportedError();
399
+ }
400
+ }
401
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
402
+ loginRedirect(request?: RedirectRequest | undefined): Promise<void> {
403
+ throw NestedAppAuthError.createUnsupportedError();
404
+ }
405
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
406
+ logout(logoutRequest?: EndSessionRequest | undefined): Promise<void> {
407
+ throw NestedAppAuthError.createUnsupportedError();
408
+ }
409
+ logoutRedirect(
410
+ logoutRequest?: EndSessionRequest | undefined // eslint-disable-line @typescript-eslint/no-unused-vars
411
+ ): Promise<void> {
412
+ throw NestedAppAuthError.createUnsupportedError();
413
+ }
414
+ logoutPopup(
415
+ logoutRequest?: EndSessionPopupRequest | undefined // eslint-disable-line @typescript-eslint/no-unused-vars
416
+ ): Promise<void> {
417
+ throw NestedAppAuthError.createUnsupportedError();
418
+ }
419
+ ssoSilent(
420
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
421
+ request: Partial<
422
+ Omit<
423
+ CommonAuthorizationUrlRequest,
424
+ | "requestedClaimsHash"
425
+ | "responseMode"
426
+ | "codeChallenge"
427
+ | "codeChallengeMethod"
428
+ | "nativeBroker"
429
+ >
430
+ >
431
+ ): Promise<AuthenticationResult> {
432
+ return this.acquireTokenSilentInternal(request as SilentRequest);
433
+ }
434
+ getTokenCache(): ITokenCache {
435
+ throw NestedAppAuthError.createUnsupportedError();
436
+ }
437
+
438
+ /**
439
+ * Returns the logger instance
440
+ */
441
+ public getLogger(): Logger {
442
+ return this.logger;
443
+ }
444
+
445
+ /**
446
+ * Replaces the default logger set in configurations with new Logger with new configurations
447
+ * @param logger Logger instance
448
+ */
449
+ setLogger(logger: Logger): void {
450
+ this.logger = logger;
451
+ }
452
+
453
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
454
+ setActiveAccount(account: AccountInfo | null): void {
455
+ /*
456
+ * StandardController uses this to allow the developer to set the active account
457
+ * in the nested app auth scenario the active account is controlled by the app hosting the nested app
458
+ */
459
+ this.logger.warning("nestedAppAuth does not support setActiveAccount");
460
+ return;
461
+ }
462
+ getActiveAccount(): AccountInfo | null {
463
+ const currentAccount = this.operatingContext.getActiveAccount();
464
+ if (currentAccount !== undefined) {
465
+ return this.nestedAppAuthAdapter.fromNaaAccountInfo(currentAccount);
466
+ } else {
467
+ return null;
468
+ }
469
+ }
470
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
471
+ initializeWrapperLibrary(sku: WrapperSKU, version: string): void {
472
+ /*
473
+ * Standard controller uses this to set the sku and version of the wrapper library in the storage
474
+ * we do nothing here
475
+ */
476
+ return;
477
+ }
478
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
479
+ setNavigationClient(navigationClient: INavigationClient): void {
480
+ this.logger.warning(
481
+ "setNavigationClient is not supported in nested app auth"
482
+ );
483
+ }
484
+ getConfiguration(): BrowserConfiguration {
485
+ return this.config;
486
+ }
487
+ isBrowserEnv(): boolean {
488
+ return this.operatingContext.isBrowserEnvironment();
489
+ }
490
+ getBrowserCrypto(): ICrypto {
491
+ return this.browserCrypto;
492
+ }
493
+ getPerformanceClient(): IPerformanceClient {
494
+ throw NestedAppAuthError.createUnsupportedError();
495
+ }
496
+
497
+ getRedirectResponse(): Map<string, Promise<AuthenticationResult | null>> {
498
+ throw NestedAppAuthError.createUnsupportedError();
499
+ }
500
+ preflightBrowserEnvironmentCheck(
501
+ interactionType: InteractionType, // eslint-disable-line @typescript-eslint/no-unused-vars
502
+ setInteractionInProgress?: boolean | undefined // eslint-disable-line @typescript-eslint/no-unused-vars
503
+ ): void {
504
+ throw NestedAppAuthError.createUnsupportedError();
505
+ }
506
+
507
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
508
+ async clearCache(logoutRequest?: ClearCacheRequest): Promise<void> {
509
+ throw NestedAppAuthError.createUnsupportedError();
510
+ }
511
+
512
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
513
+ async hydrateCache(
514
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
515
+ result: AuthenticationResult,
516
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
517
+ request:
518
+ | SilentRequest
519
+ | SsoSilentRequest
520
+ | RedirectRequest
521
+ | PopupRequest
522
+ ): Promise<void> {
523
+ throw NestedAppAuthError.createUnsupportedError();
524
+ }
525
+ }
@@ -29,6 +29,7 @@ import {
29
29
  createClientAuthError,
30
30
  ClientAuthErrorCodes,
31
31
  AccountFilter,
32
+ buildStaticAuthorityOptions,
32
33
  } from "@azure/msal-common";
33
34
  import {
34
35
  BrowserCacheManager,
@@ -45,7 +46,7 @@ import {
45
46
  DEFAULT_REQUEST,
46
47
  BrowserConstants,
47
48
  } from "../utils/BrowserConstants";
48
- import { BrowserUtils } from "../utils/BrowserUtils";
49
+ import * as BrowserUtils from "../utils/BrowserUtils";
49
50
  import { RedirectRequest } from "../request/RedirectRequest";
50
51
  import { PopupRequest } from "../request/PopupRequest";
51
52
  import { SsoSilentRequest } from "../request/SsoSilentRequest";
@@ -207,7 +208,8 @@ export class StandardController implements IController {
207
208
  this.config.auth.clientId,
208
209
  this.config.cache,
209
210
  this.browserCrypto,
210
- this.logger
211
+ this.logger,
212
+ buildStaticAuthorityOptions(this.config.auth)
211
213
  )
212
214
  : DEFAULT_BROWSER_CACHE_MANAGER(
213
215
  this.config.auth.clientId,
@@ -1559,10 +1561,10 @@ export class StandardController implements IController {
1559
1561
  ): string {
1560
1562
  const account =
1561
1563
  request.account ||
1562
- this.browserStorage.getAccountInfoByHints(
1563
- request.loginHint,
1564
- request.sid
1565
- ) ||
1564
+ this.browserStorage.getAccountInfoFilteredBy({
1565
+ loginHint: request.loginHint,
1566
+ sid: request.sid,
1567
+ }) ||
1566
1568
  this.getActiveAccount();
1567
1569
 
1568
1570
  return (account && account.nativeAccountId) || "";