@azure/msal-browser 3.0.2 → 3.1.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 (256) 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 +4 -1
  4. package/dist/app/IPublicClientApplication.mjs.map +1 -1
  5. package/dist/app/PublicClientApplication.d.ts +6 -0
  6. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  7. package/dist/app/PublicClientApplication.mjs +8 -1
  8. package/dist/app/PublicClientApplication.mjs.map +1 -1
  9. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
  10. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +5 -4
  11. package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +1 -1
  12. package/dist/cache/AsyncMemoryStorage.mjs +4 -3
  13. package/dist/cache/AsyncMemoryStorage.mjs.map +1 -1
  14. package/dist/cache/BrowserCacheManager.d.ts +9 -2
  15. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  16. package/dist/cache/BrowserCacheManager.mjs +54 -26
  17. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  18. package/dist/cache/BrowserStorage.mjs +1 -1
  19. package/dist/cache/BrowserStorage.mjs.map +1 -1
  20. package/dist/cache/CryptoKeyStore.mjs +1 -1
  21. package/dist/cache/CryptoKeyStore.mjs.map +1 -1
  22. package/dist/cache/DatabaseStorage.d.ts.map +1 -1
  23. package/dist/cache/DatabaseStorage.mjs +9 -8
  24. package/dist/cache/DatabaseStorage.mjs.map +1 -1
  25. package/dist/cache/MemoryStorage.mjs +1 -1
  26. package/dist/cache/MemoryStorage.mjs.map +1 -1
  27. package/dist/cache/TokenCache.d.ts.map +1 -1
  28. package/dist/cache/TokenCache.mjs +30 -30
  29. package/dist/cache/TokenCache.mjs.map +1 -1
  30. package/dist/config/Configuration.d.ts +1 -0
  31. package/dist/config/Configuration.d.ts.map +1 -1
  32. package/dist/config/Configuration.mjs +7 -11
  33. package/dist/config/Configuration.mjs.map +1 -1
  34. package/dist/controllers/ControllerFactory.mjs +1 -1
  35. package/dist/controllers/ControllerFactory.mjs.map +1 -1
  36. package/dist/controllers/IController.d.ts +3 -27
  37. package/dist/controllers/IController.d.ts.map +1 -1
  38. package/dist/controllers/StandardController.d.ts +6 -25
  39. package/dist/controllers/StandardController.d.ts.map +1 -1
  40. package/dist/controllers/StandardController.mjs +28 -52
  41. package/dist/controllers/StandardController.mjs.map +1 -1
  42. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  43. package/dist/crypto/BrowserCrypto.mjs +4 -3
  44. package/dist/crypto/BrowserCrypto.mjs.map +1 -1
  45. package/dist/crypto/CryptoOps.d.ts +0 -3
  46. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  47. package/dist/crypto/CryptoOps.mjs +14 -17
  48. package/dist/crypto/CryptoOps.mjs.map +1 -1
  49. package/dist/crypto/ModernBrowserCrypto.mjs +1 -1
  50. package/dist/crypto/ModernBrowserCrypto.mjs.map +1 -1
  51. package/dist/crypto/PkceGenerator.d.ts +0 -1
  52. package/dist/crypto/PkceGenerator.d.ts.map +1 -1
  53. package/dist/crypto/PkceGenerator.mjs +8 -8
  54. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  55. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  56. package/dist/crypto/SignedHttpRequest.mjs.map +1 -1
  57. package/dist/encode/Base64Decode.d.ts +6 -19
  58. package/dist/encode/Base64Decode.d.ts.map +1 -1
  59. package/dist/encode/Base64Decode.mjs +17 -70
  60. package/dist/encode/Base64Decode.mjs.map +1 -1
  61. package/dist/encode/Base64Encode.d.ts +15 -27
  62. package/dist/encode/Base64Encode.d.ts.map +1 -1
  63. package/dist/encode/Base64Encode.mjs +36 -75
  64. package/dist/encode/Base64Encode.mjs.map +1 -1
  65. package/dist/error/BrowserAuthError.d.ts +54 -195
  66. package/dist/error/BrowserAuthError.d.ts.map +1 -1
  67. package/dist/error/BrowserAuthError.mjs +150 -381
  68. package/dist/error/BrowserAuthError.mjs.map +1 -1
  69. package/dist/error/BrowserAuthErrorCodes.d.ts +45 -0
  70. package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -0
  71. package/dist/error/BrowserAuthErrorCodes.mjs +53 -0
  72. package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -0
  73. package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
  74. package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
  75. package/dist/error/NativeAuthError.d.ts.map +1 -1
  76. package/dist/error/NativeAuthError.mjs +5 -4
  77. package/dist/error/NativeAuthError.mjs.map +1 -1
  78. package/dist/event/EventHandler.mjs +1 -1
  79. package/dist/event/EventHandler.mjs.map +1 -1
  80. package/dist/event/EventMessage.mjs +1 -1
  81. package/dist/event/EventMessage.mjs.map +1 -1
  82. package/dist/event/EventType.mjs +1 -1
  83. package/dist/event/EventType.mjs.map +1 -1
  84. package/dist/index.d.ts +5 -5
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.mjs +5 -3
  87. package/dist/index.mjs.map +1 -1
  88. package/dist/interaction_client/BaseInteractionClient.d.ts +2 -1
  89. package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
  90. package/dist/interaction_client/BaseInteractionClient.mjs +1 -1
  91. package/dist/interaction_client/BaseInteractionClient.mjs.map +1 -1
  92. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  93. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs.map +1 -1
  94. package/dist/interaction_client/NativeInteractionClient.d.ts +4 -10
  95. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  96. package/dist/interaction_client/NativeInteractionClient.mjs +22 -30
  97. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  98. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  99. package/dist/interaction_client/PopupClient.mjs +16 -15
  100. package/dist/interaction_client/PopupClient.mjs.map +1 -1
  101. package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
  102. package/dist/interaction_client/RedirectClient.mjs +7 -6
  103. package/dist/interaction_client/RedirectClient.mjs.map +1 -1
  104. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  105. package/dist/interaction_client/SilentAuthCodeClient.mjs +5 -4
  106. package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
  107. package/dist/interaction_client/SilentCacheClient.d.ts +4 -2
  108. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  109. package/dist/interaction_client/SilentCacheClient.mjs +10 -8
  110. package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
  111. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  112. package/dist/interaction_client/SilentIframeClient.mjs +20 -47
  113. package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
  114. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
  115. package/dist/interaction_client/SilentRefreshClient.mjs +4 -3
  116. package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
  117. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  118. package/dist/interaction_client/StandardInteractionClient.mjs +8 -7
  119. package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
  120. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  121. package/dist/interaction_handler/InteractionHandler.mjs +9 -9
  122. package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
  123. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  124. package/dist/interaction_handler/RedirectHandler.mjs +11 -10
  125. package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
  126. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  127. package/dist/interaction_handler/SilentHandler.mjs +10 -9
  128. package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
  129. package/dist/navigation/NavigationClient.mjs +1 -1
  130. package/dist/navigation/NavigationClient.mjs.map +1 -1
  131. package/dist/network/FetchClient.d.ts.map +1 -1
  132. package/dist/network/FetchClient.mjs +9 -8
  133. package/dist/network/FetchClient.mjs.map +1 -1
  134. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  135. package/dist/operatingcontext/BaseOperatingContext.mjs.map +1 -1
  136. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  137. package/dist/operatingcontext/StandardOperatingContext.mjs.map +1 -1
  138. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +1 -1
  139. package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
  140. package/dist/packageMetadata.d.ts +1 -1
  141. package/dist/packageMetadata.mjs +2 -2
  142. package/dist/packageMetadata.mjs.map +1 -1
  143. package/dist/request/ClearCacheRequest.d.ts +11 -0
  144. package/dist/request/ClearCacheRequest.d.ts.map +1 -0
  145. package/dist/telemetry/BrowserPerformanceClient.d.ts +2 -4
  146. package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -1
  147. package/dist/telemetry/BrowserPerformanceClient.mjs +2 -6
  148. package/dist/telemetry/BrowserPerformanceClient.mjs.map +1 -1
  149. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  150. package/dist/telemetry/BrowserPerformanceMeasurement.mjs.map +1 -1
  151. package/dist/utils/BrowserConstants.mjs +1 -1
  152. package/dist/utils/BrowserConstants.mjs.map +1 -1
  153. package/dist/utils/BrowserProtocolUtils.d.ts.map +1 -1
  154. package/dist/utils/BrowserProtocolUtils.mjs +3 -3
  155. package/dist/utils/BrowserProtocolUtils.mjs.map +1 -1
  156. package/dist/utils/BrowserStringUtils.mjs +1 -1
  157. package/dist/utils/BrowserStringUtils.mjs.map +1 -1
  158. package/dist/utils/BrowserUtils.d.ts +0 -9
  159. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  160. package/dist/utils/BrowserUtils.mjs +8 -33
  161. package/dist/utils/BrowserUtils.mjs.map +1 -1
  162. package/lib/msal-browser.cjs +6579 -7102
  163. package/lib/msal-browser.cjs.map +1 -1
  164. package/lib/msal-browser.js +6579 -7102
  165. package/lib/msal-browser.js.map +1 -1
  166. package/lib/msal-browser.min.js +65 -62
  167. package/package.json +7 -5
  168. package/src/app/IPublicClientApplication.ts +199 -0
  169. package/src/app/PublicClientApplication.ts +405 -0
  170. package/src/broker/nativeBroker/NativeMessageHandler.ts +419 -0
  171. package/src/broker/nativeBroker/NativeRequest.ts +52 -0
  172. package/src/broker/nativeBroker/NativeResponse.ts +56 -0
  173. package/src/cache/AsyncMemoryStorage.ts +158 -0
  174. package/src/cache/BrowserCacheManager.ts +1994 -0
  175. package/src/cache/BrowserStorage.ts +54 -0
  176. package/src/cache/CryptoKeyStore.ts +63 -0
  177. package/src/cache/DatabaseStorage.ts +287 -0
  178. package/src/cache/IAsyncMemoryStorage.ts +36 -0
  179. package/src/cache/ITokenCache.ts +21 -0
  180. package/src/cache/IWindowStorage.ts +36 -0
  181. package/src/cache/MemoryStorage.ts +42 -0
  182. package/src/cache/TokenCache.ts +484 -0
  183. package/src/config/Configuration.ts +375 -0
  184. package/src/controllers/ControllerFactory.ts +55 -0
  185. package/src/controllers/IController.ts +131 -0
  186. package/src/controllers/StandardController.ts +2107 -0
  187. package/src/crypto/BrowserCrypto.ts +135 -0
  188. package/src/crypto/CryptoOps.ts +247 -0
  189. package/src/crypto/ISubtleCrypto.ts +30 -0
  190. package/src/crypto/ModernBrowserCrypto.ts +69 -0
  191. package/src/crypto/PkceGenerator.ts +76 -0
  192. package/src/crypto/SignedHttpRequest.ts +76 -0
  193. package/src/encode/Base64Decode.ts +26 -0
  194. package/src/encode/Base64Encode.ts +52 -0
  195. package/src/error/BrowserAuthError.ts +340 -0
  196. package/src/error/BrowserAuthErrorCodes.ts +56 -0
  197. package/src/error/BrowserConfigurationAuthError.ts +133 -0
  198. package/src/error/NativeAuthError.ts +141 -0
  199. package/src/event/EventHandler.ts +176 -0
  200. package/src/event/EventMessage.ts +125 -0
  201. package/src/event/EventType.ts +33 -0
  202. package/src/index.ts +152 -0
  203. package/src/interaction_client/BaseInteractionClient.ts +301 -0
  204. package/src/interaction_client/HybridSpaAuthorizationCodeClient.ts +16 -0
  205. package/src/interaction_client/NativeInteractionClient.ts +907 -0
  206. package/src/interaction_client/PopupClient.ts +926 -0
  207. package/src/interaction_client/RedirectClient.ts +616 -0
  208. package/src/interaction_client/SilentAuthCodeClient.ts +163 -0
  209. package/src/interaction_client/SilentCacheClient.ts +133 -0
  210. package/src/interaction_client/SilentIframeClient.ts +301 -0
  211. package/src/interaction_client/SilentRefreshClient.ts +120 -0
  212. package/src/interaction_client/StandardInteractionClient.ts +481 -0
  213. package/src/interaction_handler/InteractionHandler.ts +246 -0
  214. package/src/interaction_handler/RedirectHandler.ts +225 -0
  215. package/src/interaction_handler/SilentHandler.ts +266 -0
  216. package/src/navigation/INavigationClient.ts +23 -0
  217. package/src/navigation/NavigationClient.ts +55 -0
  218. package/src/navigation/NavigationOptions.ts +18 -0
  219. package/src/network/FetchClient.ts +130 -0
  220. package/src/operatingcontext/BaseOperatingContext.ts +82 -0
  221. package/src/operatingcontext/StandardOperatingContext.ts +49 -0
  222. package/src/operatingcontext/TeamsAppOperatingContext.ts +48 -0
  223. package/src/packageMetadata.ts +3 -0
  224. package/src/request/AuthorizationCodeRequest.ts +19 -0
  225. package/src/request/AuthorizationUrlRequest.ts +17 -0
  226. package/src/request/ClearCacheRequest.ts +16 -0
  227. package/src/request/EndSessionPopupRequest.ts +26 -0
  228. package/src/request/EndSessionRequest.ts +23 -0
  229. package/src/request/PopupRequest.ts +51 -0
  230. package/src/request/PopupWindowAttributes.ts +22 -0
  231. package/src/request/RedirectRequest.ts +51 -0
  232. package/src/request/SilentRequest.ts +49 -0
  233. package/src/request/SsoSilentRequest.ts +44 -0
  234. package/src/response/AuthenticationResult.ts +13 -0
  235. package/src/telemetry/BrowserPerformanceClient.ts +226 -0
  236. package/src/telemetry/BrowserPerformanceMeasurement.ts +144 -0
  237. package/src/utils/BrowserConstants.ts +241 -0
  238. package/src/utils/BrowserProtocolUtils.ts +57 -0
  239. package/src/utils/BrowserStringUtils.ts +143 -0
  240. package/src/utils/BrowserUtils.ts +156 -0
  241. package/dist/crypto/GuidGenerator.d.ts +0 -13
  242. package/dist/crypto/GuidGenerator.d.ts.map +0 -1
  243. package/dist/crypto/GuidGenerator.mjs +0 -104
  244. package/dist/crypto/GuidGenerator.mjs.map +0 -1
  245. package/dist/internals.d.ts +0 -23
  246. package/dist/internals.d.ts.map +0 -1
  247. package/dist/internals.mjs +0 -28
  248. package/dist/internals.mjs.map +0 -1
  249. package/dist/network/XhrClient.d.ts +0 -41
  250. package/dist/network/XhrClient.d.ts.map +0 -1
  251. package/dist/network/XhrClient.mjs +0 -125
  252. package/dist/network/XhrClient.mjs.map +0 -1
  253. package/dist/utils/MathUtils.d.ts +0 -12
  254. package/dist/utils/MathUtils.d.ts.map +0 -1
  255. package/dist/utils/MathUtils.mjs +0 -26
  256. package/dist/utils/MathUtils.mjs.map +0 -1
@@ -0,0 +1,907 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ Logger,
8
+ ICrypto,
9
+ PromptValue,
10
+ AuthToken,
11
+ Constants,
12
+ AccountEntity,
13
+ AuthorityType,
14
+ ScopeSet,
15
+ TimeUtils,
16
+ AuthenticationScheme,
17
+ UrlString,
18
+ OIDC_DEFAULT_SCOPES,
19
+ PopTokenGenerator,
20
+ SignedHttpRequestParameters,
21
+ IPerformanceClient,
22
+ PerformanceEvents,
23
+ IdTokenEntity,
24
+ AccessTokenEntity,
25
+ ClientAuthError,
26
+ AuthError,
27
+ CommonSilentFlowRequest,
28
+ AccountInfo,
29
+ CacheRecord,
30
+ AADServerParamKeys,
31
+ TokenClaims,
32
+ } from "@azure/msal-common";
33
+ import { BaseInteractionClient } from "./BaseInteractionClient";
34
+ import { BrowserConfiguration } from "../config/Configuration";
35
+ import { BrowserCacheManager } from "../cache/BrowserCacheManager";
36
+ import { EventHandler } from "../event/EventHandler";
37
+ import { PopupRequest } from "../request/PopupRequest";
38
+ import { SilentRequest } from "../request/SilentRequest";
39
+ import { SsoSilentRequest } from "../request/SsoSilentRequest";
40
+ import { NativeMessageHandler } from "../broker/nativeBroker/NativeMessageHandler";
41
+ import {
42
+ NativeExtensionMethod,
43
+ ApiId,
44
+ TemporaryCacheKeys,
45
+ NativeConstants,
46
+ } from "../utils/BrowserConstants";
47
+ import {
48
+ NativeExtensionRequestBody,
49
+ NativeTokenRequest,
50
+ } from "../broker/nativeBroker/NativeRequest";
51
+ import { MATS, NativeResponse } from "../broker/nativeBroker/NativeResponse";
52
+ import { NativeAuthError } from "../error/NativeAuthError";
53
+ import { RedirectRequest } from "../request/RedirectRequest";
54
+ import { NavigationOptions } from "../navigation/NavigationOptions";
55
+ import { INavigationClient } from "../navigation/INavigationClient";
56
+ import {
57
+ createBrowserAuthError,
58
+ BrowserAuthErrorCodes,
59
+ } from "../error/BrowserAuthError";
60
+ import { SilentCacheClient } from "./SilentCacheClient";
61
+ import { AuthenticationResult } from "../response/AuthenticationResult";
62
+ import { base64Decode } from "../encode/Base64Decode";
63
+
64
+ const BrokerServerParamKeys = {
65
+ BROKER_CLIENT_ID: "brk_client_id",
66
+ BROKER_REDIRECT_URI: "brk_redirect_uri",
67
+ };
68
+
69
+ export class NativeInteractionClient extends BaseInteractionClient {
70
+ protected apiId: ApiId;
71
+ protected accountId: string;
72
+ protected nativeMessageHandler: NativeMessageHandler;
73
+ protected silentCacheClient: SilentCacheClient;
74
+ protected nativeStorageManager: BrowserCacheManager;
75
+
76
+ constructor(
77
+ config: BrowserConfiguration,
78
+ browserStorage: BrowserCacheManager,
79
+ browserCrypto: ICrypto,
80
+ logger: Logger,
81
+ eventHandler: EventHandler,
82
+ navigationClient: INavigationClient,
83
+ apiId: ApiId,
84
+ performanceClient: IPerformanceClient,
85
+ provider: NativeMessageHandler,
86
+ accountId: string,
87
+ nativeStorageImpl: BrowserCacheManager,
88
+ correlationId?: string
89
+ ) {
90
+ super(
91
+ config,
92
+ browserStorage,
93
+ browserCrypto,
94
+ logger,
95
+ eventHandler,
96
+ navigationClient,
97
+ performanceClient,
98
+ provider,
99
+ correlationId
100
+ );
101
+ this.apiId = apiId;
102
+ this.accountId = accountId;
103
+ this.nativeMessageHandler = provider;
104
+ this.nativeStorageManager = nativeStorageImpl;
105
+ this.silentCacheClient = new SilentCacheClient(
106
+ config,
107
+ this.nativeStorageManager,
108
+ browserCrypto,
109
+ logger,
110
+ eventHandler,
111
+ navigationClient,
112
+ performanceClient,
113
+ provider,
114
+ correlationId
115
+ );
116
+ }
117
+
118
+ /**
119
+ * Acquire token from native platform via browser extension
120
+ * @param request
121
+ */
122
+ async acquireToken(
123
+ request: PopupRequest | SilentRequest | SsoSilentRequest
124
+ ): Promise<AuthenticationResult> {
125
+ this.logger.trace("NativeInteractionClient - acquireToken called.");
126
+
127
+ // start the perf measurement
128
+ const nativeATMeasurement = this.performanceClient.startMeasurement(
129
+ PerformanceEvents.NativeInteractionClientAcquireToken,
130
+ request.correlationId
131
+ );
132
+ const reqTimestamp = TimeUtils.nowSeconds();
133
+
134
+ // initialize native request
135
+ const nativeRequest = await this.initializeNativeRequest(request);
136
+
137
+ // check if the tokens can be retrieved from internal cache
138
+ try {
139
+ const result = await this.acquireTokensFromCache(
140
+ this.accountId,
141
+ nativeRequest
142
+ );
143
+ nativeATMeasurement.end({
144
+ success: true,
145
+ isNativeBroker: false, // Should be true only when the result is coming directly from the broker
146
+ fromCache: true,
147
+ });
148
+ return result;
149
+ } catch (e) {
150
+ // continue with a native call for any and all errors
151
+ this.logger.info(
152
+ "MSAL internal Cache does not contain tokens, proceed to make a native call"
153
+ );
154
+ }
155
+
156
+ // fall back to native calls
157
+ const messageBody: NativeExtensionRequestBody = {
158
+ method: NativeExtensionMethod.GetToken,
159
+ request: nativeRequest,
160
+ };
161
+
162
+ const response: object = await this.nativeMessageHandler.sendMessage(
163
+ messageBody
164
+ );
165
+ const validatedResponse: NativeResponse =
166
+ this.validateNativeResponse(response);
167
+
168
+ return this.handleNativeResponse(
169
+ validatedResponse,
170
+ nativeRequest,
171
+ reqTimestamp
172
+ )
173
+ .then((result: AuthenticationResult) => {
174
+ nativeATMeasurement.end({
175
+ success: true,
176
+ isNativeBroker: true,
177
+ requestId: result.requestId,
178
+ });
179
+ return result;
180
+ })
181
+ .catch((error: AuthError) => {
182
+ nativeATMeasurement.end({
183
+ success: false,
184
+ errorCode: error.errorCode,
185
+ subErrorCode: error.subError,
186
+ isNativeBroker: true,
187
+ });
188
+ throw error;
189
+ });
190
+ }
191
+
192
+ /**
193
+ * Creates silent flow request
194
+ * @param request
195
+ * @param cachedAccount
196
+ * @returns CommonSilentFlowRequest
197
+ */
198
+ private createSilentCacheRequest(
199
+ request: NativeTokenRequest,
200
+ cachedAccount: AccountInfo
201
+ ): CommonSilentFlowRequest {
202
+ return {
203
+ authority: request.authority,
204
+ correlationId: this.correlationId,
205
+ scopes: ScopeSet.fromString(request.scope).asArray(),
206
+ account: cachedAccount,
207
+ forceRefresh: false,
208
+ };
209
+ }
210
+
211
+ /**
212
+ * Fetches the tokens from the cache if un-expired
213
+ * @param nativeAccountId
214
+ * @param request
215
+ * @returns authenticationResult
216
+ */
217
+ protected async acquireTokensFromCache(
218
+ nativeAccountId: string,
219
+ request: NativeTokenRequest
220
+ ): Promise<AuthenticationResult> {
221
+ if (!nativeAccountId) {
222
+ this.logger.warning(
223
+ "NativeInteractionClient:acquireTokensFromCache - No nativeAccountId provided"
224
+ );
225
+ throw ClientAuthError.createNoAccountFoundError();
226
+ }
227
+ // fetch the account from browser cache
228
+ const account = this.browserStorage.getAccountInfoFilteredBy({
229
+ nativeAccountId,
230
+ });
231
+ if (!account) {
232
+ throw ClientAuthError.createNoAccountFoundError();
233
+ }
234
+
235
+ // leverage silent flow for cached tokens retrieval
236
+ try {
237
+ const silentRequest = this.createSilentCacheRequest(
238
+ request,
239
+ account
240
+ );
241
+ const result = await this.silentCacheClient.acquireToken(
242
+ silentRequest
243
+ );
244
+ return {
245
+ ...result,
246
+ account,
247
+ };
248
+ } catch (e) {
249
+ throw e;
250
+ }
251
+ }
252
+
253
+ /**
254
+ * Acquires a token from native platform then redirects to the redirectUri instead of returning the response
255
+ * @param request
256
+ */
257
+ async acquireTokenRedirect(request: RedirectRequest): Promise<void> {
258
+ this.logger.trace(
259
+ "NativeInteractionClient - acquireTokenRedirect called."
260
+ );
261
+ const nativeRequest = await this.initializeNativeRequest(request);
262
+
263
+ const messageBody: NativeExtensionRequestBody = {
264
+ method: NativeExtensionMethod.GetToken,
265
+ request: nativeRequest,
266
+ };
267
+
268
+ try {
269
+ const response: object =
270
+ await this.nativeMessageHandler.sendMessage(messageBody);
271
+ this.validateNativeResponse(response);
272
+ } catch (e) {
273
+ // Only throw fatal errors here to allow application to fallback to regular redirect. Otherwise proceed and the error will be thrown in handleRedirectPromise
274
+ if (e instanceof NativeAuthError && e.isFatal()) {
275
+ throw e;
276
+ }
277
+ }
278
+ this.browserStorage.setTemporaryCache(
279
+ TemporaryCacheKeys.NATIVE_REQUEST,
280
+ JSON.stringify(nativeRequest),
281
+ true
282
+ );
283
+
284
+ const navigationOptions: NavigationOptions = {
285
+ apiId: ApiId.acquireTokenRedirect,
286
+ timeout: this.config.system.redirectNavigationTimeout,
287
+ noHistory: false,
288
+ };
289
+ const redirectUri = this.config.auth.navigateToLoginRequestUrl
290
+ ? window.location.href
291
+ : this.getRedirectUri(request.redirectUri);
292
+ await this.navigationClient.navigateExternal(
293
+ redirectUri,
294
+ navigationOptions
295
+ ); // Need to treat this as external to ensure handleRedirectPromise is run again
296
+ }
297
+
298
+ /**
299
+ * If the previous page called native platform for a token using redirect APIs, send the same request again and return the response
300
+ */
301
+ async handleRedirectPromise(): Promise<AuthenticationResult | null> {
302
+ this.logger.trace(
303
+ "NativeInteractionClient - handleRedirectPromise called."
304
+ );
305
+ if (!this.browserStorage.isInteractionInProgress(true)) {
306
+ this.logger.info(
307
+ "handleRedirectPromise called but there is no interaction in progress, returning null."
308
+ );
309
+ return null;
310
+ }
311
+
312
+ // remove prompt from the request to prevent WAM from prompting twice
313
+ const cachedRequest = this.browserStorage.getCachedNativeRequest();
314
+ if (!cachedRequest) {
315
+ this.logger.verbose(
316
+ "NativeInteractionClient - handleRedirectPromise called but there is no cached request, returning null."
317
+ );
318
+ return null;
319
+ }
320
+
321
+ const { prompt, ...request } = cachedRequest;
322
+ if (prompt) {
323
+ this.logger.verbose(
324
+ "NativeInteractionClient - handleRedirectPromise called and prompt was included in the original request, removing prompt from cached request to prevent second interaction with native broker window."
325
+ );
326
+ }
327
+
328
+ this.browserStorage.removeItem(
329
+ this.browserStorage.generateCacheKey(
330
+ TemporaryCacheKeys.NATIVE_REQUEST
331
+ )
332
+ );
333
+
334
+ const messageBody: NativeExtensionRequestBody = {
335
+ method: NativeExtensionMethod.GetToken,
336
+ request: request,
337
+ };
338
+
339
+ const reqTimestamp = TimeUtils.nowSeconds();
340
+
341
+ try {
342
+ this.logger.verbose(
343
+ "NativeInteractionClient - handleRedirectPromise sending message to native broker."
344
+ );
345
+ const response: object =
346
+ await this.nativeMessageHandler.sendMessage(messageBody);
347
+ this.validateNativeResponse(response);
348
+ const result = this.handleNativeResponse(
349
+ response as NativeResponse,
350
+ request,
351
+ reqTimestamp
352
+ );
353
+ this.browserStorage.setInteractionInProgress(false);
354
+ return result;
355
+ } catch (e) {
356
+ this.browserStorage.setInteractionInProgress(false);
357
+ throw e;
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Logout from native platform via browser extension
363
+ * @param request
364
+ */
365
+ logout(): Promise<void> {
366
+ this.logger.trace("NativeInteractionClient - logout called.");
367
+ return Promise.reject("Logout not implemented yet");
368
+ }
369
+
370
+ /**
371
+ * Transform response from native platform into AuthenticationResult object which will be returned to the end user
372
+ * @param response
373
+ * @param request
374
+ * @param reqTimestamp
375
+ */
376
+ protected async handleNativeResponse(
377
+ response: NativeResponse,
378
+ request: NativeTokenRequest,
379
+ reqTimestamp: number
380
+ ): Promise<AuthenticationResult> {
381
+ this.logger.trace(
382
+ "NativeInteractionClient - handleNativeResponse called."
383
+ );
384
+
385
+ if (response.account.id !== request.accountId) {
386
+ // User switch in native broker prompt is not supported. All users must first sign in through web flow to ensure server state is in sync
387
+ throw NativeAuthError.createUserSwitchError();
388
+ }
389
+
390
+ // Get the preferred_cache domain for the given authority
391
+ const authority = await this.getDiscoveredAuthority(request.authority);
392
+
393
+ // generate identifiers
394
+ const idTokenClaims = AuthToken.extractTokenClaims(
395
+ response.id_token,
396
+ base64Decode
397
+ );
398
+ const homeAccountIdentifier = this.createHomeAccountIdentifier(
399
+ response,
400
+ idTokenClaims
401
+ );
402
+ const accountEntity = AccountEntity.createAccount(
403
+ {
404
+ homeAccountId: homeAccountIdentifier,
405
+ idTokenClaims: idTokenClaims,
406
+ clientInfo: response.client_info,
407
+ nativeAccountId: response.account.id,
408
+ },
409
+ authority
410
+ );
411
+
412
+ // generate authenticationResult
413
+ const result = await this.generateAuthenticationResult(
414
+ response,
415
+ request,
416
+ idTokenClaims,
417
+ accountEntity,
418
+ authority.canonicalAuthority,
419
+ reqTimestamp
420
+ );
421
+
422
+ // cache accounts and tokens in the appropriate storage
423
+ this.cacheAccount(accountEntity);
424
+ this.cacheNativeTokens(
425
+ response,
426
+ request,
427
+ homeAccountIdentifier,
428
+ idTokenClaims,
429
+ result.accessToken,
430
+ result.tenantId,
431
+ reqTimestamp
432
+ );
433
+
434
+ return result;
435
+ }
436
+
437
+ /**
438
+ * creates an homeAccountIdentifier for the account
439
+ * @param response
440
+ * @param idTokenObj
441
+ * @returns
442
+ */
443
+ protected createHomeAccountIdentifier(
444
+ response: NativeResponse,
445
+ idTokenClaims: TokenClaims
446
+ ): string {
447
+ // Save account in browser storage
448
+ const homeAccountIdentifier = AccountEntity.generateHomeAccountId(
449
+ response.client_info || Constants.EMPTY_STRING,
450
+ AuthorityType.Default,
451
+ this.logger,
452
+ this.browserCrypto,
453
+ idTokenClaims
454
+ );
455
+
456
+ return homeAccountIdentifier;
457
+ }
458
+
459
+ /**
460
+ * Helper to generate scopes
461
+ * @param response
462
+ * @param request
463
+ * @returns
464
+ */
465
+ generateScopes(
466
+ response: NativeResponse,
467
+ request: NativeTokenRequest
468
+ ): ScopeSet {
469
+ return response.scope
470
+ ? ScopeSet.fromString(response.scope)
471
+ : ScopeSet.fromString(request.scope);
472
+ }
473
+
474
+ /**
475
+ * If PoP token is requesred, records the PoP token if returned from the WAM, else generates one in the browser
476
+ * @param request
477
+ * @param response
478
+ */
479
+ async generatePopAccessToken(
480
+ response: NativeResponse,
481
+ request: NativeTokenRequest
482
+ ): Promise<string> {
483
+ if (request.tokenType === AuthenticationScheme.POP) {
484
+ /**
485
+ * This code prioritizes SHR returned from the native layer. In case of error/SHR not calculated from WAM and the AT
486
+ * is still received, SHR is calculated locally
487
+ */
488
+
489
+ // Check if native layer returned an SHR token
490
+ if (response.shr) {
491
+ this.logger.trace(
492
+ "handleNativeServerResponse: SHR is enabled in native layer"
493
+ );
494
+ return response.shr;
495
+ }
496
+
497
+ // Generate SHR in msal js if WAM does not compute it when POP is enabled
498
+ const popTokenGenerator: PopTokenGenerator = new PopTokenGenerator(
499
+ this.browserCrypto
500
+ );
501
+ const shrParameters: SignedHttpRequestParameters = {
502
+ resourceRequestMethod: request.resourceRequestMethod,
503
+ resourceRequestUri: request.resourceRequestUri,
504
+ shrClaims: request.shrClaims,
505
+ shrNonce: request.shrNonce,
506
+ };
507
+
508
+ /**
509
+ * KeyID must be present in the native request from when the PoP key was generated in order for
510
+ * PopTokenGenerator to query the full key for signing
511
+ */
512
+ if (!request.keyId) {
513
+ throw ClientAuthError.createKeyIdMissingError();
514
+ }
515
+ return await popTokenGenerator.signPopToken(
516
+ response.access_token,
517
+ request.keyId,
518
+ shrParameters
519
+ );
520
+ } else {
521
+ return response.access_token;
522
+ }
523
+ }
524
+
525
+ /**
526
+ * Generates authentication result
527
+ * @param response
528
+ * @param request
529
+ * @param idTokenObj
530
+ * @param accountEntity
531
+ * @param authority
532
+ * @param reqTimestamp
533
+ * @returns
534
+ */
535
+ protected async generateAuthenticationResult(
536
+ response: NativeResponse,
537
+ request: NativeTokenRequest,
538
+ idTokenClaims: TokenClaims,
539
+ accountEntity: AccountEntity,
540
+ authority: string,
541
+ reqTimestamp: number
542
+ ): Promise<AuthenticationResult> {
543
+ // Add Native Broker fields to Telemetry
544
+ const mats = this.addTelemetryFromNativeResponse(response);
545
+
546
+ // If scopes not returned in server response, use request scopes
547
+ const responseScopes = response.scope
548
+ ? ScopeSet.fromString(response.scope)
549
+ : ScopeSet.fromString(request.scope);
550
+
551
+ const accountProperties = response.account.properties || {};
552
+ const uid =
553
+ accountProperties["UID"] ||
554
+ idTokenClaims.oid ||
555
+ idTokenClaims.sub ||
556
+ Constants.EMPTY_STRING;
557
+ const tid =
558
+ accountProperties["TenantId"] ||
559
+ idTokenClaims.tid ||
560
+ Constants.EMPTY_STRING;
561
+
562
+ // generate PoP token as needed
563
+ const responseAccessToken = await this.generatePopAccessToken(
564
+ response,
565
+ request
566
+ );
567
+ const tokenType =
568
+ request.tokenType === AuthenticationScheme.POP
569
+ ? AuthenticationScheme.POP
570
+ : AuthenticationScheme.BEARER;
571
+
572
+ const result: AuthenticationResult = {
573
+ authority: authority,
574
+ uniqueId: uid,
575
+ tenantId: tid,
576
+ scopes: responseScopes.asArray(),
577
+ account: accountEntity.getAccountInfo(),
578
+ idToken: response.id_token,
579
+ idTokenClaims: idTokenClaims,
580
+ accessToken: responseAccessToken,
581
+ fromCache: mats ? this.isResponseFromCache(mats) : false,
582
+ expiresOn: new Date(
583
+ Number(reqTimestamp + response.expires_in) * 1000
584
+ ),
585
+ tokenType: tokenType,
586
+ correlationId: this.correlationId,
587
+ state: response.state,
588
+ fromNativeBroker: true,
589
+ };
590
+
591
+ return result;
592
+ }
593
+
594
+ /**
595
+ * cache the account entity in browser storage
596
+ * @param accountEntity
597
+ */
598
+ cacheAccount(accountEntity: AccountEntity): void {
599
+ // Store the account info and hence `nativeAccountId` in browser cache
600
+ this.browserStorage.setAccount(accountEntity);
601
+
602
+ // Remove any existing cached tokens for this account in browser storage
603
+ this.browserStorage.removeAccountContext(accountEntity).catch((e) => {
604
+ this.logger.error(
605
+ `Error occurred while removing account context from browser storage. ${e}`
606
+ );
607
+ });
608
+ }
609
+
610
+ /**
611
+ * Stores the access_token and id_token in inmemory storage
612
+ * @param response
613
+ * @param request
614
+ * @param homeAccountIdentifier
615
+ * @param idTokenObj
616
+ * @param responseAccessToken
617
+ * @param tenantId
618
+ * @param reqTimestamp
619
+ */
620
+ cacheNativeTokens(
621
+ response: NativeResponse,
622
+ request: NativeTokenRequest,
623
+ homeAccountIdentifier: string,
624
+ idTokenClaims: TokenClaims,
625
+ responseAccessToken: string,
626
+ tenantId: string,
627
+ reqTimestamp: number
628
+ ): void {
629
+ const cachedIdToken: IdTokenEntity | null =
630
+ IdTokenEntity.createIdTokenEntity(
631
+ homeAccountIdentifier,
632
+ request.authority,
633
+ response.id_token || "",
634
+ request.clientId,
635
+ idTokenClaims.tid || ""
636
+ );
637
+
638
+ // cache accessToken in inmemory storage
639
+ const expiresIn: number =
640
+ request.tokenType === AuthenticationScheme.POP
641
+ ? Constants.SHR_NONCE_VALIDITY
642
+ : (typeof response.expires_in === "string"
643
+ ? parseInt(response.expires_in, 10)
644
+ : response.expires_in) || 0;
645
+ const tokenExpirationSeconds = reqTimestamp + expiresIn;
646
+ const responseScopes = this.generateScopes(response, request);
647
+
648
+ const cachedAccessToken: AccessTokenEntity | null =
649
+ AccessTokenEntity.createAccessTokenEntity(
650
+ homeAccountIdentifier,
651
+ request.authority,
652
+ responseAccessToken,
653
+ request.clientId,
654
+ idTokenClaims.tid || tenantId,
655
+ responseScopes.printScopes(),
656
+ tokenExpirationSeconds,
657
+ 0,
658
+ this.browserCrypto
659
+ );
660
+
661
+ const nativeCacheRecord = new CacheRecord(
662
+ undefined,
663
+ cachedIdToken,
664
+ cachedAccessToken
665
+ );
666
+
667
+ void this.nativeStorageManager.saveCacheRecord(
668
+ nativeCacheRecord,
669
+ request.storeInCache
670
+ );
671
+ }
672
+
673
+ protected addTelemetryFromNativeResponse(
674
+ response: NativeResponse
675
+ ): MATS | null {
676
+ const mats = this.getMATSFromResponse(response);
677
+
678
+ if (!mats) {
679
+ return null;
680
+ }
681
+
682
+ this.performanceClient.addFields(
683
+ {
684
+ extensionId: this.nativeMessageHandler.getExtensionId(),
685
+ extensionVersion:
686
+ this.nativeMessageHandler.getExtensionVersion(),
687
+ matsBrokerVersion: mats.broker_version,
688
+ matsAccountJoinOnStart: mats.account_join_on_start,
689
+ matsAccountJoinOnEnd: mats.account_join_on_end,
690
+ matsDeviceJoin: mats.device_join,
691
+ matsPromptBehavior: mats.prompt_behavior,
692
+ matsApiErrorCode: mats.api_error_code,
693
+ matsUiVisible: mats.ui_visible,
694
+ matsSilentCode: mats.silent_code,
695
+ matsSilentBiSubCode: mats.silent_bi_sub_code,
696
+ matsSilentMessage: mats.silent_message,
697
+ matsSilentStatus: mats.silent_status,
698
+ matsHttpStatus: mats.http_status,
699
+ matsHttpEventCount: mats.http_event_count,
700
+ },
701
+ this.correlationId
702
+ );
703
+
704
+ return mats;
705
+ }
706
+
707
+ /**
708
+ * Validates native platform response before processing
709
+ * @param response
710
+ */
711
+ private validateNativeResponse(response: object): NativeResponse {
712
+ if (
713
+ response.hasOwnProperty("access_token") &&
714
+ response.hasOwnProperty("id_token") &&
715
+ response.hasOwnProperty("client_info") &&
716
+ response.hasOwnProperty("account") &&
717
+ response.hasOwnProperty("scope") &&
718
+ response.hasOwnProperty("expires_in")
719
+ ) {
720
+ return response as NativeResponse;
721
+ } else {
722
+ throw NativeAuthError.createUnexpectedError(
723
+ "Response missing expected properties."
724
+ );
725
+ }
726
+ }
727
+
728
+ /**
729
+ * Gets MATS telemetry from native response
730
+ * @param response
731
+ * @returns
732
+ */
733
+ private getMATSFromResponse(response: NativeResponse): MATS | null {
734
+ if (response.properties.MATS) {
735
+ try {
736
+ return JSON.parse(response.properties.MATS);
737
+ } catch (e) {
738
+ this.logger.error(
739
+ "NativeInteractionClient - Error parsing MATS telemetry, returning null instead"
740
+ );
741
+ }
742
+ }
743
+
744
+ return null;
745
+ }
746
+
747
+ /**
748
+ * Returns whether or not response came from native cache
749
+ * @param response
750
+ * @returns
751
+ */
752
+ protected isResponseFromCache(mats: MATS): boolean {
753
+ if (typeof mats.is_cached === "undefined") {
754
+ this.logger.verbose(
755
+ "NativeInteractionClient - MATS telemetry does not contain field indicating if response was served from cache. Returning false."
756
+ );
757
+ return false;
758
+ }
759
+
760
+ return !!mats.is_cached;
761
+ }
762
+
763
+ /**
764
+ * Translates developer provided request object into NativeRequest object
765
+ * @param request
766
+ */
767
+ protected async initializeNativeRequest(
768
+ request: PopupRequest | SsoSilentRequest
769
+ ): Promise<NativeTokenRequest> {
770
+ this.logger.trace(
771
+ "NativeInteractionClient - initializeNativeRequest called"
772
+ );
773
+
774
+ const authority = request.authority || this.config.auth.authority;
775
+
776
+ if (request.account) {
777
+ await this.validateRequestAuthority(authority, request.account);
778
+ }
779
+
780
+ const canonicalAuthority = new UrlString(authority);
781
+ canonicalAuthority.validateAsUri();
782
+
783
+ // scopes are expected to be received by the native broker as "scope" and will be added to the request below. Other properties that should be dropped from the request to the native broker can be included in the object destructuring here.
784
+ const { scopes, ...remainingProperties } = request;
785
+ const scopeSet = new ScopeSet(scopes || []);
786
+ scopeSet.appendScopes(OIDC_DEFAULT_SCOPES);
787
+
788
+ const getPrompt = () => {
789
+ // If request is silent, prompt is always none
790
+ switch (this.apiId) {
791
+ case ApiId.ssoSilent:
792
+ case ApiId.acquireTokenSilent_silentFlow:
793
+ this.logger.trace(
794
+ "initializeNativeRequest: silent request sets prompt to none"
795
+ );
796
+ return PromptValue.NONE;
797
+ default:
798
+ break;
799
+ }
800
+
801
+ // Prompt not provided, request may proceed and native broker decides if it needs to prompt
802
+ if (!request.prompt) {
803
+ this.logger.trace(
804
+ "initializeNativeRequest: prompt was not provided"
805
+ );
806
+ return undefined;
807
+ }
808
+
809
+ // If request is interactive, check if prompt provided is allowed to go directly to native broker
810
+ switch (request.prompt) {
811
+ case PromptValue.NONE:
812
+ case PromptValue.CONSENT:
813
+ case PromptValue.LOGIN:
814
+ this.logger.trace(
815
+ "initializeNativeRequest: prompt is compatible with native flow"
816
+ );
817
+ return request.prompt;
818
+ default:
819
+ this.logger.trace(
820
+ `initializeNativeRequest: prompt = ${request.prompt} is not compatible with native flow`
821
+ );
822
+ throw createBrowserAuthError(
823
+ BrowserAuthErrorCodes.nativePromptNotSupported
824
+ );
825
+ }
826
+ };
827
+
828
+ const validatedRequest: NativeTokenRequest = {
829
+ ...remainingProperties,
830
+ accountId: this.accountId,
831
+ clientId: this.config.auth.clientId,
832
+ authority: canonicalAuthority.urlString,
833
+ scope: scopeSet.printScopes(),
834
+ redirectUri: this.getRedirectUri(request.redirectUri),
835
+ prompt: getPrompt(),
836
+ correlationId: this.correlationId,
837
+ tokenType: request.authenticationScheme,
838
+ windowTitleSubstring: document.title,
839
+ extraParameters: {
840
+ ...request.extraQueryParameters,
841
+ ...request.tokenQueryParameters,
842
+ },
843
+ extendedExpiryToken: false, // Make this configurable?
844
+ };
845
+
846
+ this.handleExtraBrokerParams(validatedRequest);
847
+ validatedRequest.extraParameters =
848
+ validatedRequest.extraParameters || {};
849
+ validatedRequest.extraParameters.telemetry =
850
+ NativeConstants.MATS_TELEMETRY;
851
+
852
+ if (request.authenticationScheme === AuthenticationScheme.POP) {
853
+ // add POP request type
854
+ const shrParameters: SignedHttpRequestParameters = {
855
+ resourceRequestUri: request.resourceRequestUri,
856
+ resourceRequestMethod: request.resourceRequestMethod,
857
+ shrClaims: request.shrClaims,
858
+ shrNonce: request.shrNonce,
859
+ };
860
+
861
+ const popTokenGenerator = new PopTokenGenerator(this.browserCrypto);
862
+ const reqCnfData = await popTokenGenerator.generateCnf(
863
+ shrParameters
864
+ );
865
+
866
+ // to reduce the URL length, it is recommended to send the hash of the req_cnf instead of the whole string
867
+ validatedRequest.reqCnf = reqCnfData.reqCnfHash;
868
+ validatedRequest.keyId = reqCnfData.kid;
869
+ }
870
+
871
+ return validatedRequest;
872
+ }
873
+
874
+ /**
875
+ * Handles extra broker request parameters
876
+ * @param request {NativeTokenRequest}
877
+ * @private
878
+ */
879
+ private handleExtraBrokerParams(request: NativeTokenRequest): void {
880
+ if (!request.extraParameters) {
881
+ return;
882
+ }
883
+
884
+ if (
885
+ request.extraParameters.hasOwnProperty(
886
+ BrokerServerParamKeys.BROKER_CLIENT_ID
887
+ ) &&
888
+ request.extraParameters.hasOwnProperty(
889
+ BrokerServerParamKeys.BROKER_REDIRECT_URI
890
+ ) &&
891
+ request.extraParameters.hasOwnProperty(AADServerParamKeys.CLIENT_ID)
892
+ ) {
893
+ const child_client_id =
894
+ request.extraParameters[AADServerParamKeys.CLIENT_ID];
895
+ const child_redirect_uri = request.redirectUri;
896
+ const brk_redirect_uri =
897
+ request.extraParameters[
898
+ BrokerServerParamKeys.BROKER_REDIRECT_URI
899
+ ];
900
+ request.extraParameters = {
901
+ child_client_id,
902
+ child_redirect_uri,
903
+ };
904
+ request.redirectUri = brk_redirect_uri;
905
+ }
906
+ }
907
+ }