@azure/msal-browser 3.1.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 (282) hide show
  1. package/dist/app/IPublicClientApplication.d.ts.map +1 -1
  2. package/dist/app/IPublicClientApplication.mjs +20 -19
  3. package/dist/app/IPublicClientApplication.mjs.map +1 -1
  4. package/dist/app/PublicClientApplication.d.ts +14 -6
  5. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  6. package/dist/app/PublicClientApplication.mjs +18 -8
  7. package/dist/app/PublicClientApplication.mjs.map +1 -1
  8. package/dist/app/PublicClientNext.d.ts +274 -0
  9. package/dist/app/PublicClientNext.d.ts.map +1 -0
  10. package/dist/app/PublicClientNext.mjs +362 -0
  11. package/dist/app/PublicClientNext.mjs.map +1 -0
  12. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +3 -4
  13. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
  14. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +13 -13
  15. package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +1 -1
  16. package/dist/broker/nativeBroker/NativeStatusCodes.d.ts +8 -0
  17. package/dist/broker/nativeBroker/NativeStatusCodes.d.ts.map +1 -0
  18. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +16 -0
  19. package/dist/broker/nativeBroker/NativeStatusCodes.mjs.map +1 -0
  20. package/dist/cache/AsyncMemoryStorage.mjs +1 -1
  21. package/dist/cache/BrowserCacheManager.d.ts +4 -15
  22. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  23. package/dist/cache/BrowserCacheManager.mjs +13 -69
  24. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  25. package/dist/cache/BrowserStorage.d.ts.map +1 -1
  26. package/dist/cache/BrowserStorage.mjs +7 -9
  27. package/dist/cache/BrowserStorage.mjs.map +1 -1
  28. package/dist/cache/CryptoKeyStore.mjs +1 -1
  29. package/dist/cache/DatabaseStorage.mjs +1 -1
  30. package/dist/cache/MemoryStorage.mjs +1 -1
  31. package/dist/cache/TokenCache.mjs +1 -1
  32. package/dist/config/Configuration.d.ts +4 -0
  33. package/dist/config/Configuration.d.ts.map +1 -1
  34. package/dist/config/Configuration.mjs +8 -7
  35. package/dist/config/Configuration.mjs.map +1 -1
  36. package/dist/controllers/ControllerFactory.d.ts +2 -1
  37. package/dist/controllers/ControllerFactory.d.ts.map +1 -1
  38. package/dist/controllers/ControllerFactory.mjs +26 -19
  39. package/dist/controllers/ControllerFactory.mjs.map +1 -1
  40. package/dist/controllers/IController.d.ts +3 -2
  41. package/dist/controllers/IController.d.ts.map +1 -1
  42. package/dist/controllers/NestedAppAuthController.d.ts +96 -0
  43. package/dist/controllers/NestedAppAuthController.d.ts.map +1 -0
  44. package/dist/controllers/NestedAppAuthController.mjs +345 -0
  45. package/dist/controllers/NestedAppAuthController.mjs.map +1 -0
  46. package/dist/controllers/StandardController.d.ts +11 -6
  47. package/dist/controllers/StandardController.d.ts.map +1 -1
  48. package/dist/controllers/StandardController.mjs +67 -45
  49. package/dist/controllers/StandardController.mjs.map +1 -1
  50. package/dist/controllers/UnknownOperatingContextController.d.ts +88 -0
  51. package/dist/controllers/UnknownOperatingContextController.d.ts.map +1 -0
  52. package/dist/controllers/UnknownOperatingContextController.mjs +275 -0
  53. package/dist/controllers/UnknownOperatingContextController.mjs.map +1 -0
  54. package/dist/crypto/BrowserCrypto.d.ts +44 -49
  55. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  56. package/dist/crypto/BrowserCrypto.mjs +77 -77
  57. package/dist/crypto/BrowserCrypto.mjs.map +1 -1
  58. package/dist/crypto/CryptoOps.d.ts +1 -7
  59. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  60. package/dist/crypto/CryptoOps.mjs +18 -23
  61. package/dist/crypto/CryptoOps.mjs.map +1 -1
  62. package/dist/crypto/PkceGenerator.d.ts +6 -21
  63. package/dist/crypto/PkceGenerator.d.ts.map +1 -1
  64. package/dist/crypto/PkceGenerator.mjs +45 -46
  65. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  66. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  67. package/dist/encode/Base64Decode.d.ts.map +1 -1
  68. package/dist/encode/Base64Decode.mjs +18 -2
  69. package/dist/encode/Base64Decode.mjs.map +1 -1
  70. package/dist/encode/Base64Encode.mjs +1 -1
  71. package/dist/error/BrowserAuthError.d.ts +10 -1
  72. package/dist/error/BrowserAuthError.d.ts.map +1 -1
  73. package/dist/error/BrowserAuthError.mjs +12 -3
  74. package/dist/error/BrowserAuthError.mjs.map +1 -1
  75. package/dist/error/BrowserAuthErrorCodes.d.ts +1 -0
  76. package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -1
  77. package/dist/error/BrowserAuthErrorCodes.mjs +3 -2
  78. package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -1
  79. package/dist/error/BrowserConfigurationAuthError.d.ts +9 -46
  80. package/dist/error/BrowserConfigurationAuthError.d.ts.map +1 -1
  81. package/dist/error/BrowserConfigurationAuthError.mjs +20 -73
  82. package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
  83. package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts +4 -0
  84. package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts.map +1 -0
  85. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +12 -0
  86. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs.map +1 -0
  87. package/dist/error/NativeAuthError.d.ts +17 -45
  88. package/dist/error/NativeAuthError.d.ts.map +1 -1
  89. package/dist/error/NativeAuthError.mjs +47 -78
  90. package/dist/error/NativeAuthError.mjs.map +1 -1
  91. package/dist/error/NativeAuthErrorCodes.d.ts +3 -0
  92. package/dist/error/NativeAuthErrorCodes.d.ts.map +1 -0
  93. package/dist/error/NativeAuthErrorCodes.mjs +11 -0
  94. package/dist/error/NativeAuthErrorCodes.mjs.map +1 -0
  95. package/dist/error/NestedAppAuthError.d.ts +15 -0
  96. package/dist/error/NestedAppAuthError.d.ts.map +1 -0
  97. package/dist/error/NestedAppAuthError.mjs +30 -0
  98. package/dist/error/NestedAppAuthError.mjs.map +1 -0
  99. package/dist/event/EventHandler.d.ts.map +1 -1
  100. package/dist/event/EventHandler.mjs +3 -2
  101. package/dist/event/EventHandler.mjs.map +1 -1
  102. package/dist/event/EventMessage.mjs +1 -1
  103. package/dist/event/EventType.mjs +1 -1
  104. package/dist/index.d.ts +5 -7
  105. package/dist/index.d.ts.map +1 -1
  106. package/dist/index.mjs +7 -3
  107. package/dist/index.mjs.map +1 -1
  108. package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
  109. package/dist/interaction_client/BaseInteractionClient.mjs +10 -11
  110. package/dist/interaction_client/BaseInteractionClient.mjs.map +1 -1
  111. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  112. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  113. package/dist/interaction_client/NativeInteractionClient.mjs +26 -13
  114. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  115. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  116. package/dist/interaction_client/PopupClient.mjs +5 -4
  117. package/dist/interaction_client/PopupClient.mjs.map +1 -1
  118. package/dist/interaction_client/RedirectClient.mjs +7 -7
  119. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  120. package/dist/interaction_client/SilentAuthCodeClient.mjs +7 -10
  121. package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
  122. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  123. package/dist/interaction_client/SilentCacheClient.mjs +11 -18
  124. package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
  125. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  126. package/dist/interaction_client/SilentIframeClient.mjs +27 -13
  127. package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
  128. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
  129. package/dist/interaction_client/SilentRefreshClient.mjs +8 -18
  130. package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
  131. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  132. package/dist/interaction_client/StandardInteractionClient.mjs +16 -37
  133. package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
  134. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  135. package/dist/interaction_handler/InteractionHandler.mjs +6 -9
  136. package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
  137. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  138. package/dist/interaction_handler/RedirectHandler.mjs +3 -3
  139. package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
  140. package/dist/interaction_handler/SilentHandler.d.ts +13 -47
  141. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  142. package/dist/interaction_handler/SilentHandler.mjs +120 -156
  143. package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
  144. package/dist/naa/AccountInfo.d.ts +13 -0
  145. package/dist/naa/AccountInfo.d.ts.map +1 -0
  146. package/dist/naa/AccountRequests.d.ts +10 -0
  147. package/dist/naa/AccountRequests.d.ts.map +1 -0
  148. package/dist/naa/AuthBridge.d.ts +6 -0
  149. package/dist/naa/AuthBridge.d.ts.map +1 -0
  150. package/dist/naa/BridgeCapabilities.d.ts +4 -0
  151. package/dist/naa/BridgeCapabilities.d.ts.map +1 -0
  152. package/dist/naa/BridgeError.d.ts +10 -0
  153. package/dist/naa/BridgeError.d.ts.map +1 -0
  154. package/dist/naa/BridgeError.mjs +12 -0
  155. package/dist/naa/BridgeError.mjs.map +1 -0
  156. package/dist/naa/BridgeProxy.d.ts +72 -0
  157. package/dist/naa/BridgeProxy.d.ts.map +1 -0
  158. package/dist/naa/BridgeProxy.mjs +154 -0
  159. package/dist/naa/BridgeProxy.mjs.map +1 -0
  160. package/dist/naa/BridgeRequest.d.ts +7 -0
  161. package/dist/naa/BridgeRequest.d.ts.map +1 -0
  162. package/dist/naa/BridgeRequestEnvelope.d.ts +14 -0
  163. package/dist/naa/BridgeRequestEnvelope.d.ts.map +1 -0
  164. package/dist/naa/BridgeResponseEnvelope.d.ts +11 -0
  165. package/dist/naa/BridgeResponseEnvelope.d.ts.map +1 -0
  166. package/dist/naa/BridgeStatusCode.d.ts +11 -0
  167. package/dist/naa/BridgeStatusCode.d.ts.map +1 -0
  168. package/dist/naa/BridgeStatusCode.mjs +20 -0
  169. package/dist/naa/BridgeStatusCode.mjs.map +1 -0
  170. package/dist/naa/IBridgeProxy.d.ts +11 -0
  171. package/dist/naa/IBridgeProxy.d.ts.map +1 -0
  172. package/dist/naa/InitializeBridgeResponse.d.ts +7 -0
  173. package/dist/naa/InitializeBridgeResponse.d.ts.map +1 -0
  174. package/dist/naa/TokenRequest.d.ts +22 -0
  175. package/dist/naa/TokenRequest.d.ts.map +1 -0
  176. package/dist/naa/TokenResponse.d.ts +17 -0
  177. package/dist/naa/TokenResponse.d.ts.map +1 -0
  178. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts +26 -0
  179. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts.map +1 -0
  180. package/dist/naa/mapping/NestedAppAuthAdapter.mjs +178 -0
  181. package/dist/naa/mapping/NestedAppAuthAdapter.mjs.map +1 -0
  182. package/dist/navigation/NavigationClient.mjs +1 -1
  183. package/dist/network/FetchClient.mjs +1 -1
  184. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  185. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  186. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts +7 -0
  187. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts.map +1 -1
  188. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +45 -4
  189. package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
  190. package/dist/operatingcontext/UnknownOperatingContext.d.ts +26 -0
  191. package/dist/operatingcontext/UnknownOperatingContext.d.ts.map +1 -0
  192. package/dist/operatingcontext/UnknownOperatingContext.mjs +49 -0
  193. package/dist/operatingcontext/UnknownOperatingContext.mjs.map +1 -0
  194. package/dist/packageMetadata.d.ts +1 -1
  195. package/dist/packageMetadata.mjs +2 -2
  196. package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
  197. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  198. package/dist/utils/BrowserConstants.mjs +1 -1
  199. package/dist/utils/BrowserProtocolUtils.d.ts.map +1 -1
  200. package/dist/utils/BrowserProtocolUtils.mjs +3 -3
  201. package/dist/utils/BrowserProtocolUtils.mjs.map +1 -1
  202. package/dist/utils/BrowserUtils.d.ts +54 -53
  203. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  204. package/dist/utils/BrowserUtils.mjs +114 -102
  205. package/dist/utils/BrowserUtils.mjs.map +1 -1
  206. package/lib/msal-browser.cjs +61 -18042
  207. package/lib/msal-browser.cjs.map +1 -1
  208. package/lib/msal-browser.js +13593 -12505
  209. package/lib/msal-browser.js.map +1 -1
  210. package/lib/msal-browser.min.js +66 -65
  211. package/package.json +2 -2
  212. package/src/app/IPublicClientApplication.ts +55 -18
  213. package/src/app/PublicClientApplication.ts +19 -7
  214. package/src/app/PublicClientNext.ts +442 -0
  215. package/src/broker/nativeBroker/NativeMessageHandler.ts +12 -15
  216. package/src/broker/nativeBroker/NativeStatusCodes.ts +13 -0
  217. package/src/cache/BrowserCacheManager.ts +29 -103
  218. package/src/cache/BrowserStorage.ts +9 -11
  219. package/src/config/Configuration.ts +21 -8
  220. package/src/controllers/ControllerFactory.ts +36 -25
  221. package/src/controllers/IController.ts +4 -1
  222. package/src/controllers/NestedAppAuthController.ts +525 -0
  223. package/src/controllers/StandardController.ts +163 -98
  224. package/src/controllers/UnknownOperatingContextController.ts +383 -0
  225. package/src/crypto/BrowserCrypto.ts +119 -103
  226. package/src/crypto/CryptoOps.ts +18 -27
  227. package/src/crypto/PkceGenerator.ts +93 -54
  228. package/src/encode/Base64Decode.ts +21 -1
  229. package/src/error/BrowserAuthError.ts +13 -1
  230. package/src/error/BrowserAuthErrorCodes.ts +1 -0
  231. package/src/error/BrowserConfigurationAuthError.ts +33 -102
  232. package/src/error/BrowserConfigurationAuthErrorCodes.ts +9 -0
  233. package/src/error/NativeAuthError.ts +73 -101
  234. package/src/error/NativeAuthErrorCodes.ts +7 -0
  235. package/src/error/NestedAppAuthError.ts +32 -0
  236. package/src/event/EventHandler.ts +2 -1
  237. package/src/index.ts +8 -10
  238. package/src/interaction_client/BaseInteractionClient.ts +14 -8
  239. package/src/interaction_client/NativeInteractionClient.ts +48 -14
  240. package/src/interaction_client/PopupClient.ts +2 -1
  241. package/src/interaction_client/RedirectClient.ts +1 -1
  242. package/src/interaction_client/SilentAuthCodeClient.ts +22 -19
  243. package/src/interaction_client/SilentCacheClient.ts +28 -28
  244. package/src/interaction_client/SilentIframeClient.ts +54 -18
  245. package/src/interaction_client/SilentRefreshClient.ts +26 -28
  246. package/src/interaction_client/StandardInteractionClient.ts +37 -68
  247. package/src/interaction_handler/InteractionHandler.ts +20 -15
  248. package/src/interaction_handler/RedirectHandler.ts +6 -2
  249. package/src/interaction_handler/SilentHandler.ts +177 -230
  250. package/src/naa/AccountInfo.ts +17 -0
  251. package/src/naa/AccountRequests.ts +16 -0
  252. package/src/naa/AuthBridge.ts +16 -0
  253. package/src/naa/BridgeCapabilities.ts +8 -0
  254. package/src/naa/BridgeError.ts +18 -0
  255. package/src/naa/BridgeProxy.ts +230 -0
  256. package/src/naa/BridgeRequest.ts +12 -0
  257. package/src/naa/BridgeRequestEnvelope.ts +46 -0
  258. package/src/naa/BridgeResponseEnvelope.ts +21 -0
  259. package/src/naa/BridgeStatusCode.ts +15 -0
  260. package/src/naa/IBridgeProxy.ts +25 -0
  261. package/src/naa/InitializeBridgeResponse.ts +12 -0
  262. package/src/naa/TokenRequest.ts +26 -0
  263. package/src/naa/TokenResponse.ts +61 -0
  264. package/src/naa/mapping/NestedAppAuthAdapter.ts +252 -0
  265. package/src/operatingcontext/TeamsAppOperatingContext.ts +43 -3
  266. package/src/operatingcontext/UnknownOperatingContext.ts +48 -0
  267. package/src/packageMetadata.ts +1 -1
  268. package/src/utils/BrowserProtocolUtils.ts +3 -2
  269. package/src/utils/BrowserUtils.ts +133 -125
  270. package/dist/crypto/ISubtleCrypto.d.ts +0 -10
  271. package/dist/crypto/ISubtleCrypto.d.ts.map +0 -1
  272. package/dist/crypto/ModernBrowserCrypto.d.ts +0 -10
  273. package/dist/crypto/ModernBrowserCrypto.d.ts.map +0 -1
  274. package/dist/crypto/ModernBrowserCrypto.mjs +0 -31
  275. package/dist/crypto/ModernBrowserCrypto.mjs.map +0 -1
  276. package/dist/utils/BrowserStringUtils.d.ts +0 -22
  277. package/dist/utils/BrowserStringUtils.d.ts.map +0 -1
  278. package/dist/utils/BrowserStringUtils.mjs +0 -144
  279. package/dist/utils/BrowserStringUtils.mjs.map +0 -1
  280. package/src/crypto/ISubtleCrypto.ts +0 -30
  281. package/src/crypto/ModernBrowserCrypto.ts +0 -69
  282. package/src/utils/BrowserStringUtils.ts +0 -143
@@ -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
+ }