@azure/msal-browser 3.0.2 → 3.2.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 (280) hide show
  1. package/dist/app/IPublicClientApplication.d.ts +2 -0
  2. package/dist/app/IPublicClientApplication.d.ts.map +1 -1
  3. package/dist/app/IPublicClientApplication.mjs +22 -18
  4. package/dist/app/IPublicClientApplication.mjs.map +1 -1
  5. package/dist/app/PublicClientApplication.d.ts +20 -6
  6. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  7. package/dist/app/PublicClientApplication.mjs +24 -7
  8. package/dist/app/PublicClientApplication.mjs.map +1 -1
  9. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +3 -4
  10. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
  11. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +17 -16
  12. package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +1 -1
  13. package/dist/broker/nativeBroker/NativeStatusCodes.d.ts +8 -0
  14. package/dist/broker/nativeBroker/NativeStatusCodes.d.ts.map +1 -0
  15. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +16 -0
  16. package/dist/broker/nativeBroker/NativeStatusCodes.mjs.map +1 -0
  17. package/dist/cache/AsyncMemoryStorage.mjs +4 -3
  18. package/dist/cache/AsyncMemoryStorage.mjs.map +1 -1
  19. package/dist/cache/BrowserCacheManager.d.ts +10 -3
  20. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  21. package/dist/cache/BrowserCacheManager.mjs +58 -29
  22. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  23. package/dist/cache/BrowserStorage.d.ts.map +1 -1
  24. package/dist/cache/BrowserStorage.mjs +7 -9
  25. package/dist/cache/BrowserStorage.mjs.map +1 -1
  26. package/dist/cache/CryptoKeyStore.mjs +1 -1
  27. package/dist/cache/CryptoKeyStore.mjs.map +1 -1
  28. package/dist/cache/DatabaseStorage.d.ts.map +1 -1
  29. package/dist/cache/DatabaseStorage.mjs +9 -8
  30. package/dist/cache/DatabaseStorage.mjs.map +1 -1
  31. package/dist/cache/MemoryStorage.mjs +1 -1
  32. package/dist/cache/MemoryStorage.mjs.map +1 -1
  33. package/dist/cache/TokenCache.d.ts.map +1 -1
  34. package/dist/cache/TokenCache.mjs +30 -30
  35. package/dist/cache/TokenCache.mjs.map +1 -1
  36. package/dist/config/Configuration.d.ts +1 -0
  37. package/dist/config/Configuration.d.ts.map +1 -1
  38. package/dist/config/Configuration.mjs +12 -16
  39. package/dist/config/Configuration.mjs.map +1 -1
  40. package/dist/controllers/ControllerFactory.mjs +1 -1
  41. package/dist/controllers/ControllerFactory.mjs.map +1 -1
  42. package/dist/controllers/IController.d.ts +5 -28
  43. package/dist/controllers/IController.d.ts.map +1 -1
  44. package/dist/controllers/StandardController.d.ts +17 -31
  45. package/dist/controllers/StandardController.d.ts.map +1 -1
  46. package/dist/controllers/StandardController.mjs +78 -83
  47. package/dist/controllers/StandardController.mjs.map +1 -1
  48. package/dist/crypto/BrowserCrypto.d.ts +44 -49
  49. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  50. package/dist/crypto/BrowserCrypto.mjs +78 -77
  51. package/dist/crypto/BrowserCrypto.mjs.map +1 -1
  52. package/dist/crypto/CryptoOps.d.ts +1 -10
  53. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  54. package/dist/crypto/CryptoOps.mjs +23 -34
  55. package/dist/crypto/CryptoOps.mjs.map +1 -1
  56. package/dist/crypto/PkceGenerator.d.ts +6 -22
  57. package/dist/crypto/PkceGenerator.d.ts.map +1 -1
  58. package/dist/crypto/PkceGenerator.mjs +48 -49
  59. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  60. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  61. package/dist/crypto/SignedHttpRequest.mjs.map +1 -1
  62. package/dist/encode/Base64Decode.d.ts +6 -19
  63. package/dist/encode/Base64Decode.d.ts.map +1 -1
  64. package/dist/encode/Base64Decode.mjs +31 -68
  65. package/dist/encode/Base64Decode.mjs.map +1 -1
  66. package/dist/encode/Base64Encode.d.ts +15 -27
  67. package/dist/encode/Base64Encode.d.ts.map +1 -1
  68. package/dist/encode/Base64Encode.mjs +36 -75
  69. package/dist/encode/Base64Encode.mjs.map +1 -1
  70. package/dist/error/BrowserAuthError.d.ts +63 -195
  71. package/dist/error/BrowserAuthError.d.ts.map +1 -1
  72. package/dist/error/BrowserAuthError.mjs +159 -381
  73. package/dist/error/BrowserAuthError.mjs.map +1 -1
  74. package/dist/error/BrowserAuthErrorCodes.d.ts +46 -0
  75. package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -0
  76. package/dist/error/BrowserAuthErrorCodes.mjs +54 -0
  77. package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -0
  78. package/dist/error/BrowserConfigurationAuthError.d.ts +9 -46
  79. package/dist/error/BrowserConfigurationAuthError.d.ts.map +1 -1
  80. package/dist/error/BrowserConfigurationAuthError.mjs +20 -73
  81. package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
  82. package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts +4 -0
  83. package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts.map +1 -0
  84. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +12 -0
  85. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs.map +1 -0
  86. package/dist/error/NativeAuthError.d.ts +17 -45
  87. package/dist/error/NativeAuthError.d.ts.map +1 -1
  88. package/dist/error/NativeAuthError.mjs +49 -79
  89. package/dist/error/NativeAuthError.mjs.map +1 -1
  90. package/dist/error/NativeAuthErrorCodes.d.ts +3 -0
  91. package/dist/error/NativeAuthErrorCodes.d.ts.map +1 -0
  92. package/dist/error/NativeAuthErrorCodes.mjs +11 -0
  93. package/dist/error/NativeAuthErrorCodes.mjs.map +1 -0
  94. package/dist/event/EventHandler.d.ts.map +1 -1
  95. package/dist/event/EventHandler.mjs +3 -2
  96. package/dist/event/EventHandler.mjs.map +1 -1
  97. package/dist/event/EventMessage.mjs +1 -1
  98. package/dist/event/EventMessage.mjs.map +1 -1
  99. package/dist/event/EventType.mjs +1 -1
  100. package/dist/event/EventType.mjs.map +1 -1
  101. package/dist/index.d.ts +6 -6
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.mjs +8 -4
  104. package/dist/index.mjs.map +1 -1
  105. package/dist/interaction_client/BaseInteractionClient.d.ts +2 -1
  106. package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
  107. package/dist/interaction_client/BaseInteractionClient.mjs +7 -8
  108. package/dist/interaction_client/BaseInteractionClient.mjs.map +1 -1
  109. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  110. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs.map +1 -1
  111. package/dist/interaction_client/NativeInteractionClient.d.ts +4 -10
  112. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  113. package/dist/interaction_client/NativeInteractionClient.mjs +32 -38
  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 +16 -15
  117. package/dist/interaction_client/PopupClient.mjs.map +1 -1
  118. package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
  119. package/dist/interaction_client/RedirectClient.mjs +7 -6
  120. package/dist/interaction_client/RedirectClient.mjs.map +1 -1
  121. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  122. package/dist/interaction_client/SilentAuthCodeClient.mjs +9 -11
  123. package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
  124. package/dist/interaction_client/SilentCacheClient.d.ts +4 -2
  125. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  126. package/dist/interaction_client/SilentCacheClient.mjs +19 -25
  127. package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
  128. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  129. package/dist/interaction_client/SilentIframeClient.mjs +20 -47
  130. package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
  131. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
  132. package/dist/interaction_client/SilentRefreshClient.mjs +11 -20
  133. package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
  134. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  135. package/dist/interaction_client/StandardInteractionClient.mjs +18 -38
  136. package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
  137. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  138. package/dist/interaction_handler/InteractionHandler.mjs +13 -16
  139. package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
  140. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  141. package/dist/interaction_handler/RedirectHandler.mjs +12 -11
  142. package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
  143. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  144. package/dist/interaction_handler/SilentHandler.mjs +11 -11
  145. package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
  146. package/dist/navigation/NavigationClient.mjs +1 -1
  147. package/dist/navigation/NavigationClient.mjs.map +1 -1
  148. package/dist/network/FetchClient.d.ts.map +1 -1
  149. package/dist/network/FetchClient.mjs +9 -8
  150. package/dist/network/FetchClient.mjs.map +1 -1
  151. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  152. package/dist/operatingcontext/BaseOperatingContext.mjs.map +1 -1
  153. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  154. package/dist/operatingcontext/StandardOperatingContext.mjs.map +1 -1
  155. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +1 -1
  156. package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
  157. package/dist/packageMetadata.d.ts +1 -1
  158. package/dist/packageMetadata.mjs +2 -2
  159. package/dist/packageMetadata.mjs.map +1 -1
  160. package/dist/request/ClearCacheRequest.d.ts +11 -0
  161. package/dist/request/ClearCacheRequest.d.ts.map +1 -0
  162. package/dist/telemetry/BrowserPerformanceClient.d.ts +2 -4
  163. package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -1
  164. package/dist/telemetry/BrowserPerformanceClient.mjs +2 -6
  165. package/dist/telemetry/BrowserPerformanceClient.mjs.map +1 -1
  166. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  167. package/dist/telemetry/BrowserPerformanceMeasurement.mjs.map +1 -1
  168. package/dist/utils/BrowserConstants.mjs +1 -1
  169. package/dist/utils/BrowserConstants.mjs.map +1 -1
  170. package/dist/utils/BrowserProtocolUtils.d.ts.map +1 -1
  171. package/dist/utils/BrowserProtocolUtils.mjs +4 -4
  172. package/dist/utils/BrowserProtocolUtils.mjs.map +1 -1
  173. package/dist/utils/BrowserStringUtils.mjs +1 -1
  174. package/dist/utils/BrowserStringUtils.mjs.map +1 -1
  175. package/dist/utils/BrowserUtils.d.ts +0 -9
  176. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  177. package/dist/utils/BrowserUtils.mjs +8 -33
  178. package/dist/utils/BrowserUtils.mjs.map +1 -1
  179. package/lib/msal-browser.cjs +8729 -9566
  180. package/lib/msal-browser.cjs.map +1 -1
  181. package/lib/msal-browser.js +8729 -9566
  182. package/lib/msal-browser.js.map +1 -1
  183. package/lib/msal-browser.min.js +68 -62
  184. package/package.json +7 -5
  185. package/src/app/IPublicClientApplication.ts +236 -0
  186. package/src/app/PublicClientApplication.ts +417 -0
  187. package/src/broker/nativeBroker/NativeMessageHandler.ts +416 -0
  188. package/src/broker/nativeBroker/NativeRequest.ts +52 -0
  189. package/src/broker/nativeBroker/NativeResponse.ts +56 -0
  190. package/src/broker/nativeBroker/NativeStatusCodes.ts +13 -0
  191. package/src/cache/AsyncMemoryStorage.ts +158 -0
  192. package/src/cache/BrowserCacheManager.ts +2009 -0
  193. package/src/cache/BrowserStorage.ts +52 -0
  194. package/src/cache/CryptoKeyStore.ts +63 -0
  195. package/src/cache/DatabaseStorage.ts +287 -0
  196. package/src/cache/IAsyncMemoryStorage.ts +36 -0
  197. package/src/cache/ITokenCache.ts +21 -0
  198. package/src/cache/IWindowStorage.ts +36 -0
  199. package/src/cache/MemoryStorage.ts +42 -0
  200. package/src/cache/TokenCache.ts +484 -0
  201. package/src/config/Configuration.ts +383 -0
  202. package/src/controllers/ControllerFactory.ts +55 -0
  203. package/src/controllers/IController.ts +134 -0
  204. package/src/controllers/StandardController.ts +2170 -0
  205. package/src/crypto/BrowserCrypto.ts +151 -0
  206. package/src/crypto/CryptoOps.ts +235 -0
  207. package/src/crypto/PkceGenerator.ts +115 -0
  208. package/src/crypto/SignedHttpRequest.ts +76 -0
  209. package/src/encode/Base64Decode.ts +46 -0
  210. package/src/encode/Base64Encode.ts +52 -0
  211. package/src/error/BrowserAuthError.ts +352 -0
  212. package/src/error/BrowserAuthErrorCodes.ts +57 -0
  213. package/src/error/BrowserConfigurationAuthError.ts +64 -0
  214. package/src/error/BrowserConfigurationAuthErrorCodes.ts +9 -0
  215. package/src/error/NativeAuthError.ts +113 -0
  216. package/src/error/NativeAuthErrorCodes.ts +7 -0
  217. package/src/event/EventHandler.ts +177 -0
  218. package/src/event/EventMessage.ts +125 -0
  219. package/src/event/EventType.ts +33 -0
  220. package/src/index.ts +157 -0
  221. package/src/interaction_client/BaseInteractionClient.ts +307 -0
  222. package/src/interaction_client/HybridSpaAuthorizationCodeClient.ts +16 -0
  223. package/src/interaction_client/NativeInteractionClient.ts +925 -0
  224. package/src/interaction_client/PopupClient.ts +926 -0
  225. package/src/interaction_client/RedirectClient.ts +616 -0
  226. package/src/interaction_client/SilentAuthCodeClient.ts +165 -0
  227. package/src/interaction_client/SilentCacheClient.ts +125 -0
  228. package/src/interaction_client/SilentIframeClient.ts +301 -0
  229. package/src/interaction_client/SilentRefreshClient.ts +118 -0
  230. package/src/interaction_client/StandardInteractionClient.ts +450 -0
  231. package/src/interaction_handler/InteractionHandler.ts +251 -0
  232. package/src/interaction_handler/RedirectHandler.ts +229 -0
  233. package/src/interaction_handler/SilentHandler.ts +269 -0
  234. package/src/navigation/INavigationClient.ts +23 -0
  235. package/src/navigation/NavigationClient.ts +55 -0
  236. package/src/navigation/NavigationOptions.ts +18 -0
  237. package/src/network/FetchClient.ts +130 -0
  238. package/src/operatingcontext/BaseOperatingContext.ts +82 -0
  239. package/src/operatingcontext/StandardOperatingContext.ts +49 -0
  240. package/src/operatingcontext/TeamsAppOperatingContext.ts +48 -0
  241. package/src/packageMetadata.ts +3 -0
  242. package/src/request/AuthorizationCodeRequest.ts +19 -0
  243. package/src/request/AuthorizationUrlRequest.ts +17 -0
  244. package/src/request/ClearCacheRequest.ts +16 -0
  245. package/src/request/EndSessionPopupRequest.ts +26 -0
  246. package/src/request/EndSessionRequest.ts +23 -0
  247. package/src/request/PopupRequest.ts +51 -0
  248. package/src/request/PopupWindowAttributes.ts +22 -0
  249. package/src/request/RedirectRequest.ts +51 -0
  250. package/src/request/SilentRequest.ts +49 -0
  251. package/src/request/SsoSilentRequest.ts +44 -0
  252. package/src/response/AuthenticationResult.ts +13 -0
  253. package/src/telemetry/BrowserPerformanceClient.ts +226 -0
  254. package/src/telemetry/BrowserPerformanceMeasurement.ts +144 -0
  255. package/src/utils/BrowserConstants.ts +241 -0
  256. package/src/utils/BrowserProtocolUtils.ts +58 -0
  257. package/src/utils/BrowserStringUtils.ts +143 -0
  258. package/src/utils/BrowserUtils.ts +156 -0
  259. package/dist/crypto/GuidGenerator.d.ts +0 -13
  260. package/dist/crypto/GuidGenerator.d.ts.map +0 -1
  261. package/dist/crypto/GuidGenerator.mjs +0 -104
  262. package/dist/crypto/GuidGenerator.mjs.map +0 -1
  263. package/dist/crypto/ISubtleCrypto.d.ts +0 -10
  264. package/dist/crypto/ISubtleCrypto.d.ts.map +0 -1
  265. package/dist/crypto/ModernBrowserCrypto.d.ts +0 -10
  266. package/dist/crypto/ModernBrowserCrypto.d.ts.map +0 -1
  267. package/dist/crypto/ModernBrowserCrypto.mjs +0 -31
  268. package/dist/crypto/ModernBrowserCrypto.mjs.map +0 -1
  269. package/dist/internals.d.ts +0 -23
  270. package/dist/internals.d.ts.map +0 -1
  271. package/dist/internals.mjs +0 -28
  272. package/dist/internals.mjs.map +0 -1
  273. package/dist/network/XhrClient.d.ts +0 -41
  274. package/dist/network/XhrClient.d.ts.map +0 -1
  275. package/dist/network/XhrClient.mjs +0 -125
  276. package/dist/network/XhrClient.mjs.map +0 -1
  277. package/dist/utils/MathUtils.d.ts +0 -12
  278. package/dist/utils/MathUtils.d.ts.map +0 -1
  279. package/dist/utils/MathUtils.mjs +0 -26
  280. package/dist/utils/MathUtils.mjs.map +0 -1
@@ -0,0 +1,165 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ ICrypto,
8
+ Logger,
9
+ CommonAuthorizationCodeRequest,
10
+ AuthError,
11
+ Constants,
12
+ IPerformanceClient,
13
+ PerformanceEvents,
14
+ invokeAsync,
15
+ } from "@azure/msal-common";
16
+ import { StandardInteractionClient } from "./StandardInteractionClient";
17
+ import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest";
18
+ import { BrowserConfiguration } from "../config/Configuration";
19
+ import { BrowserCacheManager } from "../cache/BrowserCacheManager";
20
+ import { EventHandler } from "../event/EventHandler";
21
+ import { INavigationClient } from "../navigation/INavigationClient";
22
+ import {
23
+ createBrowserAuthError,
24
+ BrowserAuthErrorCodes,
25
+ } from "../error/BrowserAuthError";
26
+ import { InteractionType, ApiId } from "../utils/BrowserConstants";
27
+ import { SilentHandler } from "../interaction_handler/SilentHandler";
28
+ import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest";
29
+ import { HybridSpaAuthorizationCodeClient } from "./HybridSpaAuthorizationCodeClient";
30
+ import { NativeMessageHandler } from "../broker/nativeBroker/NativeMessageHandler";
31
+ import { AuthenticationResult } from "../response/AuthenticationResult";
32
+
33
+ export class SilentAuthCodeClient extends StandardInteractionClient {
34
+ private apiId: ApiId;
35
+
36
+ constructor(
37
+ config: BrowserConfiguration,
38
+ storageImpl: BrowserCacheManager,
39
+ browserCrypto: ICrypto,
40
+ logger: Logger,
41
+ eventHandler: EventHandler,
42
+ navigationClient: INavigationClient,
43
+ apiId: ApiId,
44
+ performanceClient: IPerformanceClient,
45
+ nativeMessageHandler?: NativeMessageHandler,
46
+ correlationId?: string
47
+ ) {
48
+ super(
49
+ config,
50
+ storageImpl,
51
+ browserCrypto,
52
+ logger,
53
+ eventHandler,
54
+ navigationClient,
55
+ performanceClient,
56
+ nativeMessageHandler,
57
+ correlationId
58
+ );
59
+ this.apiId = apiId;
60
+ }
61
+
62
+ /**
63
+ * Acquires a token silently by redeeming an authorization code against the /token endpoint
64
+ * @param request
65
+ */
66
+ async acquireToken(
67
+ request: AuthorizationCodeRequest
68
+ ): Promise<AuthenticationResult> {
69
+ // Auth code payload is required
70
+ if (!request.code) {
71
+ throw createBrowserAuthError(
72
+ BrowserAuthErrorCodes.authCodeRequired
73
+ );
74
+ }
75
+
76
+ // Create silent request
77
+ const silentRequest: AuthorizationUrlRequest = await invokeAsync(
78
+ this.initializeAuthorizationRequest.bind(this),
79
+ PerformanceEvents.StandardInteractionClientInitializeAuthorizationRequest,
80
+ this.logger,
81
+ this.performanceClient,
82
+ request.correlationId
83
+ )(request, InteractionType.Silent);
84
+ this.browserStorage.updateCacheEntries(
85
+ silentRequest.state,
86
+ silentRequest.nonce,
87
+ silentRequest.authority,
88
+ silentRequest.loginHint || Constants.EMPTY_STRING,
89
+ silentRequest.account || null
90
+ );
91
+
92
+ const serverTelemetryManager = this.initializeServerTelemetryManager(
93
+ this.apiId
94
+ );
95
+
96
+ try {
97
+ // Create auth code request (PKCE not needed)
98
+ const authCodeRequest: CommonAuthorizationCodeRequest = {
99
+ ...silentRequest,
100
+ code: request.code,
101
+ };
102
+
103
+ // Initialize the client
104
+ const clientConfig = await invokeAsync(
105
+ this.getClientConfiguration.bind(this),
106
+ PerformanceEvents.StandardInteractionClientGetClientConfiguration,
107
+ this.logger,
108
+ this.performanceClient,
109
+ request.correlationId
110
+ )(serverTelemetryManager, silentRequest.authority);
111
+ const authClient: HybridSpaAuthorizationCodeClient =
112
+ new HybridSpaAuthorizationCodeClient(clientConfig);
113
+ this.logger.verbose("Auth code client created");
114
+
115
+ // Create silent handler
116
+ const silentHandler = new SilentHandler(
117
+ authClient,
118
+ this.browserStorage,
119
+ authCodeRequest,
120
+ this.logger,
121
+ this.config.system,
122
+ this.performanceClient
123
+ );
124
+
125
+ // Handle auth code parameters from request
126
+ return invokeAsync(
127
+ silentHandler.handleCodeResponseFromServer.bind(silentHandler),
128
+ PerformanceEvents.HandleCodeResponseFromServer,
129
+ this.logger,
130
+ this.performanceClient,
131
+ request.correlationId
132
+ )(
133
+ {
134
+ code: request.code,
135
+ msgraph_host: request.msGraphHost,
136
+ cloud_graph_host_name: request.cloudGraphHostName,
137
+ cloud_instance_host_name: request.cloudInstanceHostName,
138
+ },
139
+ silentRequest.state,
140
+ authClient.authority,
141
+ this.networkClient,
142
+ false
143
+ );
144
+ } catch (e) {
145
+ if (e instanceof AuthError) {
146
+ (e as AuthError).setCorrelationId(this.correlationId);
147
+ serverTelemetryManager.cacheFailedRequest(e);
148
+ }
149
+ this.browserStorage.cleanRequestByState(silentRequest.state);
150
+ throw e;
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Currently Unsupported
156
+ */
157
+ logout(): Promise<void> {
158
+ // Synchronous so we must reject
159
+ return Promise.reject(
160
+ createBrowserAuthError(
161
+ BrowserAuthErrorCodes.silentLogoutUnsupported
162
+ )
163
+ );
164
+ }
165
+ }
@@ -0,0 +1,125 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { StandardInteractionClient } from "./StandardInteractionClient";
7
+ import {
8
+ CommonSilentFlowRequest,
9
+ SilentFlowClient,
10
+ ServerTelemetryManager,
11
+ AccountInfo,
12
+ AzureCloudOptions,
13
+ PerformanceEvents,
14
+ invokeAsync,
15
+ } from "@azure/msal-common";
16
+ import { SilentRequest } from "../request/SilentRequest";
17
+ import { ApiId } from "../utils/BrowserConstants";
18
+ import {
19
+ BrowserAuthError,
20
+ BrowserAuthErrorCodes,
21
+ } from "../error/BrowserAuthError";
22
+ import { AuthenticationResult } from "../response/AuthenticationResult";
23
+ import { ClearCacheRequest } from "../request/ClearCacheRequest";
24
+
25
+ export class SilentCacheClient extends StandardInteractionClient {
26
+ /**
27
+ * Returns unexpired tokens from the cache, if available
28
+ * @param silentRequest
29
+ */
30
+ async acquireToken(
31
+ silentRequest: CommonSilentFlowRequest
32
+ ): Promise<AuthenticationResult> {
33
+ // Telemetry manager only used to increment cacheHits here
34
+ const serverTelemetryManager = this.initializeServerTelemetryManager(
35
+ ApiId.acquireTokenSilent_silentFlow
36
+ );
37
+
38
+ const silentAuthClient = await this.createSilentFlowClient(
39
+ serverTelemetryManager,
40
+ silentRequest.authority,
41
+ silentRequest.azureCloudOptions
42
+ );
43
+ this.logger.verbose("Silent auth client created");
44
+
45
+ try {
46
+ const response = await silentAuthClient.acquireCachedToken(
47
+ silentRequest
48
+ );
49
+ const authResponse = response[0] as AuthenticationResult;
50
+
51
+ this.performanceClient.addFields(
52
+ {
53
+ fromCache: true,
54
+ },
55
+ silentRequest.correlationId
56
+ );
57
+ return authResponse;
58
+ } catch (error) {
59
+ if (
60
+ error instanceof BrowserAuthError &&
61
+ error.errorCode === BrowserAuthErrorCodes.cryptoKeyNotFound
62
+ ) {
63
+ this.logger.verbose(
64
+ "Signing keypair for bound access token not found. Refreshing bound access token and generating a new crypto keypair."
65
+ );
66
+ }
67
+ throw error;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * API to silenty clear the browser cache.
73
+ * @param logoutRequest
74
+ */
75
+ logout(logoutRequest?: ClearCacheRequest): Promise<void> {
76
+ this.logger.verbose("logoutRedirect called");
77
+ const validLogoutRequest = this.initializeLogoutRequest(logoutRequest);
78
+ return this.clearCacheOnLogout(validLogoutRequest?.account);
79
+ }
80
+
81
+ /**
82
+ * Creates an Silent Flow Client with the given authority, or the default authority.
83
+ * @param serverTelemetryManager
84
+ * @param authorityUrl
85
+ */
86
+ protected async createSilentFlowClient(
87
+ serverTelemetryManager: ServerTelemetryManager,
88
+ authorityUrl?: string,
89
+ azureCloudOptions?: AzureCloudOptions
90
+ ): Promise<SilentFlowClient> {
91
+ // Create auth module.
92
+ const clientConfig = await invokeAsync(
93
+ this.getClientConfiguration.bind(this),
94
+ PerformanceEvents.StandardInteractionClientGetClientConfiguration,
95
+ this.logger,
96
+ this.performanceClient,
97
+ this.correlationId
98
+ )(serverTelemetryManager, authorityUrl, azureCloudOptions);
99
+ return new SilentFlowClient(clientConfig, this.performanceClient);
100
+ }
101
+
102
+ async initializeSilentRequest(
103
+ request: SilentRequest,
104
+ account: AccountInfo
105
+ ): Promise<CommonSilentFlowRequest> {
106
+ this.performanceClient.addQueueMeasurement(
107
+ PerformanceEvents.InitializeSilentRequest,
108
+ this.correlationId
109
+ );
110
+
111
+ const baseRequest = await invokeAsync(
112
+ this.initializeBaseRequest.bind(this),
113
+ PerformanceEvents.InitializeBaseRequest,
114
+ this.logger,
115
+ this.performanceClient,
116
+ this.correlationId
117
+ )(request, account);
118
+ return {
119
+ ...request,
120
+ ...baseRequest,
121
+ account: account,
122
+ forceRefresh: request.forceRefresh || false,
123
+ };
124
+ }
125
+ }
@@ -0,0 +1,301 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ ICrypto,
8
+ Logger,
9
+ PromptValue,
10
+ CommonAuthorizationCodeRequest,
11
+ AuthorizationCodeClient,
12
+ AuthError,
13
+ Constants,
14
+ UrlString,
15
+ ServerAuthorizationCodeResponse,
16
+ ProtocolUtils,
17
+ IPerformanceClient,
18
+ PerformanceEvents,
19
+ invokeAsync,
20
+ } from "@azure/msal-common";
21
+ import { StandardInteractionClient } from "./StandardInteractionClient";
22
+ import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest";
23
+ import { BrowserConfiguration } from "../config/Configuration";
24
+ import { BrowserCacheManager } from "../cache/BrowserCacheManager";
25
+ import { EventHandler } from "../event/EventHandler";
26
+ import { INavigationClient } from "../navigation/INavigationClient";
27
+ import {
28
+ createBrowserAuthError,
29
+ BrowserAuthErrorCodes,
30
+ } from "../error/BrowserAuthError";
31
+ import { InteractionType, ApiId } from "../utils/BrowserConstants";
32
+ import { SilentHandler } from "../interaction_handler/SilentHandler";
33
+ import { SsoSilentRequest } from "../request/SsoSilentRequest";
34
+ import { NativeMessageHandler } from "../broker/nativeBroker/NativeMessageHandler";
35
+ import { NativeInteractionClient } from "./NativeInteractionClient";
36
+ import { AuthenticationResult } from "../response/AuthenticationResult";
37
+
38
+ export class SilentIframeClient extends StandardInteractionClient {
39
+ protected apiId: ApiId;
40
+ protected nativeStorage: BrowserCacheManager;
41
+
42
+ constructor(
43
+ config: BrowserConfiguration,
44
+ storageImpl: BrowserCacheManager,
45
+ browserCrypto: ICrypto,
46
+ logger: Logger,
47
+ eventHandler: EventHandler,
48
+ navigationClient: INavigationClient,
49
+ apiId: ApiId,
50
+ performanceClient: IPerformanceClient,
51
+ nativeStorageImpl: BrowserCacheManager,
52
+ nativeMessageHandler?: NativeMessageHandler,
53
+ correlationId?: string
54
+ ) {
55
+ super(
56
+ config,
57
+ storageImpl,
58
+ browserCrypto,
59
+ logger,
60
+ eventHandler,
61
+ navigationClient,
62
+ performanceClient,
63
+ nativeMessageHandler,
64
+ correlationId
65
+ );
66
+ this.apiId = apiId;
67
+ this.nativeStorage = nativeStorageImpl;
68
+ }
69
+
70
+ /**
71
+ * Acquires a token silently by opening a hidden iframe to the /authorize endpoint with prompt=none or prompt=no_session
72
+ * @param request
73
+ */
74
+ async acquireToken(
75
+ request: SsoSilentRequest
76
+ ): Promise<AuthenticationResult> {
77
+ this.performanceClient.addQueueMeasurement(
78
+ PerformanceEvents.SilentIframeClientAcquireToken,
79
+ request.correlationId
80
+ );
81
+ // Check that we have some SSO data
82
+ if (
83
+ !request.loginHint &&
84
+ !request.sid &&
85
+ (!request.account || !request.account.username)
86
+ ) {
87
+ this.logger.warning(
88
+ "No user hint provided. The authorization server may need more information to complete this request."
89
+ );
90
+ }
91
+
92
+ // Check that prompt is set to none or no_session, throw error if it is set to anything else.
93
+ if (
94
+ request.prompt &&
95
+ request.prompt !== PromptValue.NONE &&
96
+ request.prompt !== PromptValue.NO_SESSION
97
+ ) {
98
+ throw createBrowserAuthError(
99
+ BrowserAuthErrorCodes.silentPromptValueError
100
+ );
101
+ }
102
+
103
+ // Create silent request
104
+ const silentRequest: AuthorizationUrlRequest = await invokeAsync(
105
+ this.initializeAuthorizationRequest.bind(this),
106
+ PerformanceEvents.StandardInteractionClientInitializeAuthorizationRequest,
107
+ this.logger,
108
+ this.performanceClient,
109
+ request.correlationId
110
+ )(
111
+ {
112
+ ...request,
113
+ prompt: request.prompt || PromptValue.NONE,
114
+ },
115
+ InteractionType.Silent
116
+ );
117
+ this.browserStorage.updateCacheEntries(
118
+ silentRequest.state,
119
+ silentRequest.nonce,
120
+ silentRequest.authority,
121
+ silentRequest.loginHint || Constants.EMPTY_STRING,
122
+ silentRequest.account || null
123
+ );
124
+
125
+ const serverTelemetryManager = this.initializeServerTelemetryManager(
126
+ this.apiId
127
+ );
128
+
129
+ try {
130
+ // Initialize the client
131
+ const authClient: AuthorizationCodeClient = await invokeAsync(
132
+ this.createAuthCodeClient.bind(this),
133
+ PerformanceEvents.StandardInteractionClientCreateAuthCodeClient,
134
+ this.logger,
135
+ this.performanceClient,
136
+ request.correlationId
137
+ )(
138
+ serverTelemetryManager,
139
+ silentRequest.authority,
140
+ silentRequest.azureCloudOptions
141
+ );
142
+
143
+ return await invokeAsync(
144
+ this.silentTokenHelper.bind(this),
145
+ PerformanceEvents.SilentIframeClientTokenHelper,
146
+ this.logger,
147
+ this.performanceClient,
148
+ request.correlationId
149
+ )(authClient, silentRequest);
150
+ } catch (e) {
151
+ if (e instanceof AuthError) {
152
+ (e as AuthError).setCorrelationId(this.correlationId);
153
+ serverTelemetryManager.cacheFailedRequest(e);
154
+ }
155
+ this.browserStorage.cleanRequestByState(silentRequest.state);
156
+ throw e;
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Currently Unsupported
162
+ */
163
+ logout(): Promise<void> {
164
+ // Synchronous so we must reject
165
+ return Promise.reject(
166
+ createBrowserAuthError(
167
+ BrowserAuthErrorCodes.silentLogoutUnsupported
168
+ )
169
+ );
170
+ }
171
+
172
+ /**
173
+ * Helper which acquires an authorization code silently using a hidden iframe from given url
174
+ * using the scopes requested as part of the id, and exchanges the code for a set of OAuth tokens.
175
+ * @param navigateUrl
176
+ * @param userRequestScopes
177
+ */
178
+ protected async silentTokenHelper(
179
+ authClient: AuthorizationCodeClient,
180
+ silentRequest: AuthorizationUrlRequest
181
+ ): Promise<AuthenticationResult> {
182
+ this.performanceClient.addQueueMeasurement(
183
+ PerformanceEvents.SilentIframeClientTokenHelper,
184
+ silentRequest.correlationId
185
+ );
186
+
187
+ // Create auth code request and generate PKCE params
188
+ const authCodeRequest: CommonAuthorizationCodeRequest =
189
+ await invokeAsync(
190
+ this.initializeAuthorizationCodeRequest.bind(this),
191
+ PerformanceEvents.StandardInteractionClientInitializeAuthorizationCodeRequest,
192
+ this.logger,
193
+ this.performanceClient,
194
+ silentRequest.correlationId
195
+ )(silentRequest);
196
+
197
+ // Create authorize request url
198
+ const navigateUrl = await invokeAsync(
199
+ authClient.getAuthCodeUrl.bind(authClient),
200
+ PerformanceEvents.GetAuthCodeUrl,
201
+ this.logger,
202
+ this.performanceClient,
203
+ silentRequest.correlationId
204
+ )({
205
+ ...silentRequest,
206
+ nativeBroker: NativeMessageHandler.isNativeAvailable(
207
+ this.config,
208
+ this.logger,
209
+ this.nativeMessageHandler,
210
+ silentRequest.authenticationScheme
211
+ ),
212
+ });
213
+
214
+ // Create silent handler
215
+ const silentHandler = new SilentHandler(
216
+ authClient,
217
+ this.browserStorage,
218
+ authCodeRequest,
219
+ this.logger,
220
+ this.config.system,
221
+ this.performanceClient
222
+ );
223
+ // Get the frame handle for the silent request
224
+ const msalFrame = await invokeAsync(
225
+ silentHandler.initiateAuthRequest.bind(silentHandler),
226
+ PerformanceEvents.SilentHandlerInitiateAuthRequest,
227
+ this.logger,
228
+ this.performanceClient,
229
+ silentRequest.correlationId
230
+ )(navigateUrl);
231
+ // Monitor the window for the hash. Return the string value and close the popup when the hash is received. Default timeout is 60 seconds.
232
+ const hash = await invokeAsync(
233
+ silentHandler.monitorIframeForHash.bind(silentHandler),
234
+ PerformanceEvents.SilentHandlerMonitorIframeForHash,
235
+ this.logger,
236
+ this.performanceClient,
237
+ silentRequest.correlationId
238
+ )(msalFrame, this.config.system.iframeHashTimeout);
239
+ // Deserialize hash fragment response parameters.
240
+ const serverParams: ServerAuthorizationCodeResponse =
241
+ UrlString.getDeserializedHash(hash);
242
+ const state = this.validateAndExtractStateFromHash(
243
+ serverParams,
244
+ InteractionType.Silent,
245
+ authCodeRequest.correlationId
246
+ );
247
+
248
+ if (serverParams.accountId) {
249
+ this.logger.verbose(
250
+ "Account id found in hash, calling WAM for token"
251
+ );
252
+ if (!this.nativeMessageHandler) {
253
+ throw createBrowserAuthError(
254
+ BrowserAuthErrorCodes.nativeConnectionNotEstablished
255
+ );
256
+ }
257
+ const nativeInteractionClient = new NativeInteractionClient(
258
+ this.config,
259
+ this.browserStorage,
260
+ this.browserCrypto,
261
+ this.logger,
262
+ this.eventHandler,
263
+ this.navigationClient,
264
+ this.apiId,
265
+ this.performanceClient,
266
+ this.nativeMessageHandler,
267
+ serverParams.accountId,
268
+ this.browserStorage,
269
+ this.correlationId
270
+ );
271
+ const { userRequestState } = ProtocolUtils.parseRequestState(
272
+ this.browserCrypto,
273
+ state
274
+ );
275
+ return invokeAsync(
276
+ nativeInteractionClient.acquireToken.bind(
277
+ nativeInteractionClient
278
+ ),
279
+ PerformanceEvents.NativeInteractionClientAcquireToken,
280
+ this.logger,
281
+ this.performanceClient,
282
+ silentRequest.correlationId
283
+ )({
284
+ ...silentRequest,
285
+ state: userRequestState,
286
+ prompt: silentRequest.prompt || PromptValue.NONE,
287
+ }).finally(() => {
288
+ this.browserStorage.cleanRequestByState(state);
289
+ });
290
+ }
291
+
292
+ // Handle response from hash string
293
+ return invokeAsync(
294
+ silentHandler.handleCodeResponseFromHash.bind(silentHandler),
295
+ PerformanceEvents.HandleCodeResponseFromHash,
296
+ this.logger,
297
+ this.performanceClient,
298
+ silentRequest.correlationId
299
+ )(hash, state, authClient.authority, this.networkClient);
300
+ }
301
+ }