@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,383 @@
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
+ AccountFilter,
16
+ } from "@azure/msal-common";
17
+ import { ITokenCache } from "../cache/ITokenCache";
18
+ import { BrowserConfiguration } from "../config/Configuration";
19
+ import {
20
+ BrowserCacheManager,
21
+ DEFAULT_BROWSER_CACHE_MANAGER,
22
+ } from "../cache/BrowserCacheManager";
23
+ import { INavigationClient } from "../navigation/INavigationClient";
24
+ import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest";
25
+ import { EndSessionPopupRequest } from "../request/EndSessionPopupRequest";
26
+ import { EndSessionRequest } from "../request/EndSessionRequest";
27
+ import { PopupRequest } from "../request/PopupRequest";
28
+ import { RedirectRequest } from "../request/RedirectRequest";
29
+ import { SilentRequest } from "../request/SilentRequest";
30
+ import { SsoSilentRequest } from "../request/SsoSilentRequest";
31
+ import { AuthenticationResult } from "../response/AuthenticationResult";
32
+ import { ApiId, WrapperSKU, InteractionType } from "../utils/BrowserConstants";
33
+ import { IController } from "./IController";
34
+ import { UnknownOperatingContext } from "../operatingcontext/UnknownOperatingContext";
35
+ import { CryptoOps } from "../crypto/CryptoOps";
36
+ import {
37
+ blockAPICallsBeforeInitialize,
38
+ blockNonBrowserEnvironment,
39
+ } from "../utils/BrowserUtils";
40
+ import { EventHandler } from "../event/EventHandler";
41
+ import { EventCallbackFunction } from "../event/EventMessage";
42
+ import { ClearCacheRequest } from "../request/ClearCacheRequest";
43
+
44
+ /**
45
+ * UnknownOperatingContextController class
46
+ *
47
+ * - Until initialize method is called, this controller is the default
48
+ * - AFter initialize method is called, this controller will be swapped out for the appropriate controller
49
+ * if the operating context can be determined; otherwise this controller will continued be used
50
+ *
51
+ * - Why do we have this? We don't want to dynamically import (download) all of the code in StandardController if we don't need to.
52
+ *
53
+ * - Only includes implementation for getAccounts and handleRedirectPromise
54
+ * - All other methods are will throw initialization error (because either initialize method or the factory method were not used)
55
+ * - This controller is necessary for React Native wrapper, server side rendering and any other scenario where we don't have a DOM
56
+ *
57
+ */
58
+ export class UnknownOperatingContextController implements IController {
59
+ // OperatingContext
60
+ protected readonly operatingContext: UnknownOperatingContext;
61
+
62
+ // Logger
63
+ protected logger: Logger;
64
+
65
+ // Storage interface implementation
66
+ protected readonly browserStorage: BrowserCacheManager;
67
+
68
+ // Input configuration by developer/user
69
+ protected readonly config: BrowserConfiguration;
70
+
71
+ // Performance telemetry client
72
+ protected readonly performanceClient: IPerformanceClient;
73
+
74
+ // Crypto interface implementation
75
+ protected readonly browserCrypto: ICrypto;
76
+
77
+ // Flag to indicate if in browser environment
78
+ protected isBrowserEnvironment: boolean;
79
+
80
+ // Flag representing whether or not the initialize API has been called and completed
81
+ protected initialized: boolean = false;
82
+
83
+ protected readonly eventHandler: EventHandler;
84
+
85
+ constructor(operatingContext: UnknownOperatingContext) {
86
+ this.operatingContext = operatingContext;
87
+
88
+ this.isBrowserEnvironment =
89
+ this.operatingContext.isBrowserEnvironment();
90
+
91
+ this.config = operatingContext.getConfig();
92
+
93
+ this.logger = operatingContext.getLogger();
94
+
95
+ // Initialize performance client
96
+ this.performanceClient = this.config.telemetry.client;
97
+
98
+ // Initialize the crypto class.
99
+ this.browserCrypto = this.isBrowserEnvironment
100
+ ? new CryptoOps(this.logger, this.performanceClient)
101
+ : DEFAULT_CRYPTO_IMPLEMENTATION;
102
+
103
+ // Initialize the browser storage class.
104
+ this.browserStorage = this.isBrowserEnvironment
105
+ ? new BrowserCacheManager(
106
+ this.config.auth.clientId,
107
+ this.config.cache,
108
+ this.browserCrypto,
109
+ this.logger
110
+ )
111
+ : DEFAULT_BROWSER_CACHE_MANAGER(
112
+ this.config.auth.clientId,
113
+ this.logger
114
+ );
115
+
116
+ this.eventHandler = new EventHandler(this.logger, this.browserCrypto);
117
+ }
118
+ getBrowserStorage(): BrowserCacheManager {
119
+ return this.browserStorage;
120
+ }
121
+
122
+ getEventHandler(): EventHandler {
123
+ return this.eventHandler;
124
+ }
125
+
126
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
127
+ getAccount(accountFilter: AccountFilter): AccountInfo | null {
128
+ return null;
129
+ }
130
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
131
+ getAccountByHomeId(homeAccountId: string): AccountInfo | null {
132
+ return null;
133
+ }
134
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
135
+ getAccountByLocalId(localAccountId: string): AccountInfo | null {
136
+ return null;
137
+ }
138
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
139
+ getAccountByUsername(username: string): AccountInfo | null {
140
+ return null;
141
+ }
142
+ getAllAccounts(): AccountInfo[] {
143
+ return [];
144
+ }
145
+ initialize(): Promise<void> {
146
+ this.initialized = true;
147
+ return Promise.resolve();
148
+ }
149
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
150
+ acquireTokenPopup(request: PopupRequest): Promise<AuthenticationResult> {
151
+ blockAPICallsBeforeInitialize(this.initialized);
152
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
153
+ return {} as Promise<AuthenticationResult>;
154
+ }
155
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
156
+ acquireTokenRedirect(request: RedirectRequest): Promise<void> {
157
+ blockAPICallsBeforeInitialize(this.initialized);
158
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
159
+ return Promise.resolve();
160
+ }
161
+ acquireTokenSilent(
162
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
163
+ silentRequest: SilentRequest
164
+ ): Promise<AuthenticationResult> {
165
+ blockAPICallsBeforeInitialize(this.initialized);
166
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
167
+ return {} as Promise<AuthenticationResult>;
168
+ }
169
+ acquireTokenByCode(
170
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
171
+ request: AuthorizationCodeRequest
172
+ ): Promise<AuthenticationResult> {
173
+ blockAPICallsBeforeInitialize(this.initialized);
174
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
175
+ return {} as Promise<AuthenticationResult>;
176
+ }
177
+ acquireTokenNative(
178
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
179
+ request:
180
+ | PopupRequest
181
+ | SilentRequest
182
+ | Partial<
183
+ Omit<
184
+ CommonAuthorizationUrlRequest,
185
+ | "responseMode"
186
+ | "codeChallenge"
187
+ | "codeChallengeMethod"
188
+ | "requestedClaimsHash"
189
+ | "nativeBroker"
190
+ >
191
+ >,
192
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
193
+ apiId: ApiId,
194
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
195
+ accountId?: string | undefined
196
+ ): Promise<AuthenticationResult> {
197
+ blockAPICallsBeforeInitialize(this.initialized);
198
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
199
+ return {} as Promise<AuthenticationResult>;
200
+ }
201
+ acquireTokenByRefreshToken(
202
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
203
+ commonRequest: CommonSilentFlowRequest,
204
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
205
+ silentRequest: SilentRequest
206
+ ): Promise<AuthenticationResult> {
207
+ blockAPICallsBeforeInitialize(this.initialized);
208
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
209
+ return {} as Promise<AuthenticationResult>;
210
+ }
211
+ addEventCallback(callback: EventCallbackFunction): string | null {
212
+ return this.eventHandler.addEventCallback(callback);
213
+ }
214
+ removeEventCallback(callbackId: string): void {
215
+ this.eventHandler.removeEventCallback(callbackId);
216
+ }
217
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
218
+ addPerformanceCallback(callback: PerformanceCallbackFunction): string {
219
+ blockAPICallsBeforeInitialize(this.initialized);
220
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
221
+ return "";
222
+ }
223
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
224
+ removePerformanceCallback(callbackId: string): boolean {
225
+ blockAPICallsBeforeInitialize(this.initialized);
226
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
227
+ return true;
228
+ }
229
+ enableAccountStorageEvents(): void {
230
+ blockAPICallsBeforeInitialize(this.initialized);
231
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
232
+ }
233
+ disableAccountStorageEvents(): void {
234
+ blockAPICallsBeforeInitialize(this.initialized);
235
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
236
+ }
237
+
238
+ handleRedirectPromise(
239
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
240
+ hash?: string | undefined
241
+ ): Promise<AuthenticationResult | null> {
242
+ blockAPICallsBeforeInitialize(this.initialized);
243
+ return Promise.resolve(null);
244
+ }
245
+ loginPopup(
246
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
247
+ request?: PopupRequest | undefined
248
+ ): Promise<AuthenticationResult> {
249
+ blockAPICallsBeforeInitialize(this.initialized);
250
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
251
+ return {} as Promise<AuthenticationResult>;
252
+ }
253
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
254
+ loginRedirect(request?: RedirectRequest | undefined): Promise<void> {
255
+ blockAPICallsBeforeInitialize(this.initialized);
256
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
257
+ return {} as Promise<void>;
258
+ }
259
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
260
+ logout(logoutRequest?: EndSessionRequest | undefined): Promise<void> {
261
+ blockAPICallsBeforeInitialize(this.initialized);
262
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
263
+ return {} as Promise<void>;
264
+ }
265
+ logoutRedirect(
266
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
267
+ logoutRequest?: EndSessionRequest | undefined
268
+ ): Promise<void> {
269
+ blockAPICallsBeforeInitialize(this.initialized);
270
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
271
+ return {} as Promise<void>;
272
+ }
273
+ logoutPopup(
274
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
275
+ logoutRequest?: EndSessionPopupRequest | undefined
276
+ ): Promise<void> {
277
+ blockAPICallsBeforeInitialize(this.initialized);
278
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
279
+ return {} as Promise<void>;
280
+ }
281
+ ssoSilent(
282
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
283
+ request: Partial<
284
+ Omit<
285
+ CommonAuthorizationUrlRequest,
286
+ | "responseMode"
287
+ | "codeChallenge"
288
+ | "codeChallengeMethod"
289
+ | "requestedClaimsHash"
290
+ | "nativeBroker"
291
+ >
292
+ >
293
+ ): Promise<AuthenticationResult> {
294
+ blockAPICallsBeforeInitialize(this.initialized);
295
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
296
+ return {} as Promise<AuthenticationResult>;
297
+ }
298
+ getTokenCache(): ITokenCache {
299
+ blockAPICallsBeforeInitialize(this.initialized);
300
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
301
+ return {} as ITokenCache;
302
+ }
303
+ getLogger(): Logger {
304
+ return this.logger;
305
+ }
306
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
307
+ setLogger(logger: Logger): void {
308
+ blockAPICallsBeforeInitialize(this.initialized);
309
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
310
+ }
311
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
312
+ setActiveAccount(account: AccountInfo | null): void {
313
+ blockAPICallsBeforeInitialize(this.initialized);
314
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
315
+ }
316
+ getActiveAccount(): AccountInfo | null {
317
+ blockAPICallsBeforeInitialize(this.initialized);
318
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
319
+ return null;
320
+ }
321
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
322
+ initializeWrapperLibrary(sku: WrapperSKU, version: string): void {
323
+ this.browserStorage.setWrapperMetadata(sku, version);
324
+ }
325
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
326
+ setNavigationClient(navigationClient: INavigationClient): void {
327
+ blockAPICallsBeforeInitialize(this.initialized);
328
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
329
+ }
330
+ getConfiguration(): BrowserConfiguration {
331
+ return this.config;
332
+ }
333
+ isBrowserEnv(): boolean {
334
+ blockAPICallsBeforeInitialize(this.initialized);
335
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
336
+ return true;
337
+ }
338
+ getBrowserCrypto(): ICrypto {
339
+ blockAPICallsBeforeInitialize(this.initialized);
340
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
341
+ return {} as ICrypto;
342
+ }
343
+ getPerformanceClient(): IPerformanceClient {
344
+ blockAPICallsBeforeInitialize(this.initialized);
345
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
346
+ return {} as IPerformanceClient;
347
+ }
348
+ getRedirectResponse(): Map<string, Promise<AuthenticationResult | null>> {
349
+ blockAPICallsBeforeInitialize(this.initialized);
350
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
351
+ return {} as Map<string, Promise<AuthenticationResult | null>>;
352
+ }
353
+ preflightBrowserEnvironmentCheck(
354
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
355
+ interactionType: InteractionType,
356
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
357
+ isAppEmbedded?: boolean | undefined
358
+ ): void {
359
+ blockAPICallsBeforeInitialize(this.initialized);
360
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
361
+ }
362
+
363
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
364
+ async clearCache(logoutRequest?: ClearCacheRequest): Promise<void> {
365
+ blockAPICallsBeforeInitialize(this.initialized);
366
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
367
+ }
368
+
369
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
370
+ async hydrateCache(
371
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
372
+ result: AuthenticationResult,
373
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
374
+ request:
375
+ | SilentRequest
376
+ | SsoSilentRequest
377
+ | RedirectRequest
378
+ | PopupRequest
379
+ ): Promise<void> {
380
+ blockAPICallsBeforeInitialize(this.initialized);
381
+ blockNonBrowserEnvironment(this.isBrowserEnvironment);
382
+ }
383
+ }
@@ -3,14 +3,22 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { BrowserStringUtils } from "../utils/BrowserStringUtils";
7
6
  import {
8
7
  createBrowserAuthError,
9
8
  BrowserAuthErrorCodes,
10
9
  } from "../error/BrowserAuthError";
11
- import { ISubtleCrypto } from "./ISubtleCrypto";
12
- import { ModernBrowserCrypto } from "./ModernBrowserCrypto";
13
- import { Logger } from "@azure/msal-common";
10
+ import {
11
+ IPerformanceClient,
12
+ Logger,
13
+ PerformanceEvents,
14
+ } from "@azure/msal-common";
15
+ import { KEY_FORMAT_JWK } from "../utils/BrowserConstants";
16
+
17
+ /**
18
+ * This file defines functions used by the browser library to perform cryptography operations such as
19
+ * hashing and encoding. It also has helper functions to validate the availability of specific APIs.
20
+ */
21
+
14
22
  /**
15
23
  * See here for more info on RsaHashedKeyGenParams: https://developer.mozilla.org/en-US/docs/Web/API/RsaHashedKeyGenParams
16
24
  */
@@ -23,113 +31,121 @@ const MODULUS_LENGTH = 2048;
23
31
  // Public Exponent
24
32
  const PUBLIC_EXPONENT: Uint8Array = new Uint8Array([0x01, 0x00, 0x01]);
25
33
 
34
+ const keygenAlgorithmOptions: RsaHashedKeyGenParams = {
35
+ name: PKCS1_V15_KEYGEN_ALG,
36
+ hash: S256_HASH_ALG,
37
+ modulusLength: MODULUS_LENGTH,
38
+ publicExponent: PUBLIC_EXPONENT,
39
+ };
40
+
26
41
  /**
27
- * This class implements functions used by the browser library to perform cryptography operations such as
28
- * hashing and encoding. It also has helper functions to validate the availability of specific APIs.
42
+ * Check whether browser crypto is available.
29
43
  */
30
- export class BrowserCrypto {
31
- private keygenAlgorithmOptions: RsaHashedKeyGenParams;
32
- private subtleCrypto: ISubtleCrypto;
33
- private logger: Logger;
34
-
35
- constructor(logger: Logger) {
36
- this.logger = logger;
37
-
38
- if (this.hasBrowserCrypto()) {
39
- // Use standard modern web crypto if available
40
- this.logger.verbose(
41
- "BrowserCrypto: modern crypto interface available"
42
- );
43
- this.subtleCrypto = new ModernBrowserCrypto();
44
- } else {
45
- this.logger.error("BrowserCrypto: crypto interface is unavailable");
46
- throw createBrowserAuthError(
47
- BrowserAuthErrorCodes.cryptoNonExistent
48
- );
49
- }
50
-
51
- this.keygenAlgorithmOptions = {
52
- name: PKCS1_V15_KEYGEN_ALG,
53
- hash: S256_HASH_ALG,
54
- modulusLength: MODULUS_LENGTH,
55
- publicExponent: PUBLIC_EXPONENT,
56
- };
44
+ export function validateCryptoAvailable(logger: Logger): void {
45
+ if ("crypto" in window) {
46
+ logger.verbose("BrowserCrypto: modern crypto interface available");
47
+ } else {
48
+ logger.error("BrowserCrypto: crypto interface is unavailable");
49
+ throw createBrowserAuthError(BrowserAuthErrorCodes.cryptoNonExistent);
57
50
  }
51
+ }
58
52
 
59
- /**
60
- * Check whether browser crypto is available.
61
- */
62
- private hasBrowserCrypto(): boolean {
63
- return "crypto" in window;
64
- }
53
+ /**
54
+ * Returns a sha-256 hash of the given dataString as an ArrayBuffer.
55
+ * @param dataString
56
+ */
57
+ export async function sha256Digest(
58
+ dataString: string,
59
+ performanceClient?: IPerformanceClient,
60
+ correlationId?: string
61
+ ): Promise<ArrayBuffer> {
62
+ performanceClient?.addQueueMeasurement(
63
+ PerformanceEvents.Sha256Digest,
64
+ correlationId
65
+ );
66
+ const encoder = new TextEncoder();
67
+ const data = encoder.encode(dataString);
68
+ return window.crypto.subtle.digest(
69
+ S256_HASH_ALG,
70
+ data
71
+ ) as Promise<ArrayBuffer>;
72
+ }
65
73
 
66
- /**
67
- * Returns a sha-256 hash of the given dataString as an ArrayBuffer.
68
- * @param dataString
69
- */
70
- async sha256Digest(dataString: string): Promise<ArrayBuffer> {
71
- const data = BrowserStringUtils.stringToUtf8Arr(dataString);
72
- // MSR Crypto wants object with name property, instead of string
73
- return this.subtleCrypto.digest({ name: S256_HASH_ALG }, data);
74
- }
74
+ /**
75
+ * Populates buffer with cryptographically random values.
76
+ * @param dataBuffer
77
+ */
78
+ export function getRandomValues(dataBuffer: Uint8Array): Uint8Array {
79
+ return window.crypto.getRandomValues(dataBuffer);
80
+ }
75
81
 
76
- /**
77
- * Populates buffer with cryptographically random values.
78
- * @param dataBuffer
79
- */
80
- getRandomValues(dataBuffer: Uint8Array): Uint8Array {
81
- return this.subtleCrypto.getRandomValues(dataBuffer);
82
- }
82
+ /**
83
+ * Creates a new random GUID
84
+ * @returns
85
+ */
86
+ export function createNewGuid(): string {
87
+ return window.crypto.randomUUID();
88
+ }
83
89
 
84
- /**
85
- * Generates a keypair based on current keygen algorithm config.
86
- * @param extractable
87
- * @param usages
88
- */
89
- async generateKeyPair(
90
- extractable: boolean,
91
- usages: Array<KeyUsage>
92
- ): Promise<CryptoKeyPair> {
93
- return this.subtleCrypto.generateKey(
94
- this.keygenAlgorithmOptions,
95
- extractable,
96
- usages
97
- );
98
- }
90
+ /**
91
+ * Generates a keypair based on current keygen algorithm config.
92
+ * @param extractable
93
+ * @param usages
94
+ */
95
+ export async function generateKeyPair(
96
+ extractable: boolean,
97
+ usages: Array<KeyUsage>
98
+ ): Promise<CryptoKeyPair> {
99
+ return window.crypto.subtle.generateKey(
100
+ keygenAlgorithmOptions,
101
+ extractable,
102
+ usages
103
+ ) as Promise<CryptoKeyPair>;
104
+ }
99
105
 
100
- /**
101
- * Export key as Json Web Key (JWK)
102
- * @param key
103
- */
104
- async exportJwk(key: CryptoKey): Promise<JsonWebKey> {
105
- return this.subtleCrypto.exportKey(key);
106
- }
106
+ /**
107
+ * Export key as Json Web Key (JWK)
108
+ * @param key
109
+ */
110
+ export async function exportJwk(key: CryptoKey): Promise<JsonWebKey> {
111
+ return window.crypto.subtle.exportKey(
112
+ KEY_FORMAT_JWK,
113
+ key
114
+ ) as Promise<JsonWebKey>;
115
+ }
107
116
 
108
- /**
109
- * Imports key as Json Web Key (JWK), can set extractable and usages.
110
- * @param key
111
- * @param extractable
112
- * @param usages
113
- */
114
- async importJwk(
115
- key: JsonWebKey,
116
- extractable: boolean,
117
- usages: Array<KeyUsage>
118
- ): Promise<CryptoKey> {
119
- return this.subtleCrypto.importKey(
120
- key,
121
- this.keygenAlgorithmOptions,
122
- extractable,
123
- usages
124
- );
125
- }
117
+ /**
118
+ * Imports key as Json Web Key (JWK), can set extractable and usages.
119
+ * @param key
120
+ * @param extractable
121
+ * @param usages
122
+ */
123
+ export async function importJwk(
124
+ key: JsonWebKey,
125
+ extractable: boolean,
126
+ usages: Array<KeyUsage>
127
+ ): Promise<CryptoKey> {
128
+ return window.crypto.subtle.importKey(
129
+ KEY_FORMAT_JWK,
130
+ key,
131
+ keygenAlgorithmOptions,
132
+ extractable,
133
+ usages
134
+ ) as Promise<CryptoKey>;
135
+ }
126
136
 
127
- /**
128
- * Signs given data with given key
129
- * @param key
130
- * @param data
131
- */
132
- async sign(key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
133
- return this.subtleCrypto.sign(this.keygenAlgorithmOptions, key, data);
134
- }
137
+ /**
138
+ * Signs given data with given key
139
+ * @param key
140
+ * @param data
141
+ */
142
+ export async function sign(
143
+ key: CryptoKey,
144
+ data: ArrayBuffer
145
+ ): Promise<ArrayBuffer> {
146
+ return window.crypto.subtle.sign(
147
+ keygenAlgorithmOptions,
148
+ key,
149
+ data
150
+ ) as Promise<ArrayBuffer>;
135
151
  }