@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,252 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { TokenRequest } from "../TokenRequest";
7
+ import { AccountInfo as NaaAccountInfo } from "../AccountInfo";
8
+ import { RedirectRequest } from "../../request/RedirectRequest";
9
+ import { PopupRequest } from "../../request/PopupRequest";
10
+ import { TokenResponse } from "../TokenResponse";
11
+ import {
12
+ AccountInfo as MsalAccountInfo,
13
+ AuthError,
14
+ ClientAuthError,
15
+ ClientConfigurationError,
16
+ InteractionRequiredAuthError,
17
+ ServerError,
18
+ TimeUtils,
19
+ ICrypto,
20
+ Logger,
21
+ AuthToken,
22
+ TokenClaims,
23
+ ClientAuthErrorCodes,
24
+ } from "@azure/msal-common";
25
+ import { isBridgeError } from "../BridgeError";
26
+ import { BridgeStatusCode } from "../BridgeStatusCode";
27
+ import { SilentRequest } from "../../request/SilentRequest";
28
+ import { AuthenticationResult } from "../../response/AuthenticationResult";
29
+ import {} from "../../error/BrowserAuthErrorCodes";
30
+
31
+ export class NestedAppAuthAdapter {
32
+ protected crypto: ICrypto;
33
+ protected logger: Logger;
34
+ protected clientId: string;
35
+ protected clientCapabilities: string[];
36
+
37
+ constructor(
38
+ clientId: string,
39
+ clientCapabilities: string[],
40
+ crypto: ICrypto,
41
+ logger: Logger
42
+ ) {
43
+ this.clientId = clientId;
44
+ this.clientCapabilities = clientCapabilities;
45
+ this.crypto = crypto;
46
+ this.logger = logger;
47
+ }
48
+
49
+ public toNaaSilentTokenRequest(request: SilentRequest): TokenRequest {
50
+ let extraParams: Map<string, string>;
51
+ if (request.extraQueryParameters === undefined) {
52
+ extraParams = new Map<string, string>();
53
+ } else {
54
+ extraParams = new Map<string, string>(
55
+ Object.entries(request.extraQueryParameters)
56
+ );
57
+ }
58
+ /**
59
+ * Need to get information about the client to populate request correctly
60
+ * For example: client id, client capabilities
61
+ */
62
+ const tokenRequest: TokenRequest = {
63
+ userObjectId: request.account?.homeAccountId,
64
+ clientId: this.clientId,
65
+ authority: request.authority,
66
+ scope: request.scopes.join(" "),
67
+ correlationId:
68
+ request.correlationId !== undefined
69
+ ? request.correlationId
70
+ : this.crypto.createNewGuid(),
71
+ prompt: request.prompt !== undefined ? request.prompt : "",
72
+ claims: request.claims !== undefined ? request.claims : "",
73
+ authenticationScheme:
74
+ request.authenticationScheme !== undefined
75
+ ? request.authenticationScheme
76
+ : "",
77
+ clientCapabilities: this.clientCapabilities,
78
+ extraParameters: extraParams,
79
+ };
80
+
81
+ return tokenRequest;
82
+ }
83
+
84
+ public toNaaTokenRequest(
85
+ request: PopupRequest | RedirectRequest
86
+ ): TokenRequest {
87
+ let extraParams: Map<string, string>;
88
+ if (request.extraQueryParameters === undefined) {
89
+ extraParams = new Map<string, string>();
90
+ } else {
91
+ extraParams = new Map<string, string>(
92
+ Object.entries(request.extraQueryParameters)
93
+ );
94
+ }
95
+
96
+ const tokenRequest: TokenRequest = {
97
+ userObjectId: request.account?.homeAccountId,
98
+ clientId: this.clientId,
99
+ authority: request.authority,
100
+ scope: request.scopes.join(" "),
101
+ correlationId:
102
+ request.correlationId !== undefined
103
+ ? request.correlationId
104
+ : "",
105
+ prompt: request.prompt !== undefined ? request.prompt : "",
106
+ nonce: request.nonce !== undefined ? request.nonce : "",
107
+ claims: request.claims !== undefined ? request.claims : "",
108
+ state: request.state !== undefined ? request.state : "",
109
+ authenticationScheme:
110
+ request.authenticationScheme !== undefined
111
+ ? request.authenticationScheme
112
+ : "",
113
+ clientCapabilities: undefined,
114
+ extraParameters: extraParams,
115
+ };
116
+
117
+ return tokenRequest;
118
+ }
119
+
120
+ public fromNaaTokenResponse(
121
+ request: TokenRequest,
122
+ response: TokenResponse
123
+ ): AuthenticationResult {
124
+ const expiresOn = new Date(
125
+ TimeUtils.nowSeconds() + (response.expires_in || 0) * 1000
126
+ );
127
+
128
+ const account = this.fromNaaAccountInfo(response.account);
129
+
130
+ const authenticationResult: AuthenticationResult = {
131
+ authority: response.account.environment,
132
+ uniqueId: response.account.homeAccountId,
133
+ tenantId: response.account.tenantId,
134
+ scopes: response.scope.split(" "),
135
+ account: this.fromNaaAccountInfo(response.account),
136
+ idToken: response.id_token !== undefined ? response.id_token : "",
137
+ idTokenClaims:
138
+ account.idTokenClaims !== undefined
139
+ ? account.idTokenClaims
140
+ : {},
141
+ accessToken: response.access_token,
142
+ fromCache: true,
143
+ expiresOn: expiresOn,
144
+ tokenType:
145
+ request.authenticationScheme !== undefined
146
+ ? request.authenticationScheme
147
+ : "Bearer",
148
+ correlationId: request.correlationId,
149
+ requestId: "",
150
+ extExpiresOn: expiresOn,
151
+ state: response.state,
152
+ };
153
+
154
+ return authenticationResult;
155
+ }
156
+
157
+ /*
158
+ * export type AccountInfo = {
159
+ * homeAccountId: string;
160
+ * environment: string;
161
+ * tenantId: string;
162
+ * username: string;
163
+ * localAccountId: string;
164
+ * name?: string;
165
+ * idToken?: string;
166
+ * idTokenClaims?: TokenClaims & {
167
+ * [key: string]:
168
+ * | string
169
+ * | number
170
+ * | string[]
171
+ * | object
172
+ * | undefined
173
+ * | unknown;
174
+ * };
175
+ * nativeAccountId?: string;
176
+ * authorityType?: string;
177
+ * };
178
+ */
179
+ public fromNaaAccountInfo(fromAccount: NaaAccountInfo): MsalAccountInfo {
180
+ let tokenClaims: TokenClaims | undefined;
181
+ if (fromAccount.idToken !== undefined) {
182
+ tokenClaims = AuthToken.extractTokenClaims(
183
+ fromAccount.idToken,
184
+ this.crypto.base64Decode
185
+ );
186
+ } else {
187
+ tokenClaims = undefined;
188
+ }
189
+
190
+ const account: MsalAccountInfo = {
191
+ homeAccountId: fromAccount.homeAccountId,
192
+ environment: fromAccount.environment,
193
+ tenantId: fromAccount.tenantId,
194
+ username: fromAccount.username,
195
+ localAccountId: fromAccount.localAccountId,
196
+ name: fromAccount.name,
197
+ idToken: fromAccount.idToken,
198
+ idTokenClaims: tokenClaims,
199
+ };
200
+
201
+ return account;
202
+ }
203
+
204
+ /**
205
+ *
206
+ * @param error BridgeError
207
+ * @returns AuthError, ClientAuthError, ClientConfigurationError, ServerError, InteractionRequiredError
208
+ */
209
+ public fromBridgeError(
210
+ error: unknown
211
+ ):
212
+ | AuthError
213
+ | ClientAuthError
214
+ | ClientConfigurationError
215
+ | ServerError
216
+ | InteractionRequiredAuthError {
217
+ if (isBridgeError(error)) {
218
+ switch (error.status) {
219
+ case BridgeStatusCode.USER_CANCEL:
220
+ return new ClientAuthError(
221
+ ClientAuthErrorCodes.userCanceled
222
+ );
223
+ case BridgeStatusCode.NO_NETWORK:
224
+ return new ClientAuthError(
225
+ ClientAuthErrorCodes.noNetworkConnectivity
226
+ );
227
+ case BridgeStatusCode.ACCOUNT_UNAVAILABLE:
228
+ return new ClientAuthError(
229
+ ClientAuthErrorCodes.noAccountFound
230
+ );
231
+ case BridgeStatusCode.DISABLED:
232
+ return new ClientAuthError(
233
+ ClientAuthErrorCodes.nestedAppAuthBridgeDisabled
234
+ );
235
+ case BridgeStatusCode.NESTED_APP_AUTH_UNAVAILABLE:
236
+ return new ClientAuthError(error.code, error.description);
237
+ case BridgeStatusCode.TRANSIENT_ERROR:
238
+ case BridgeStatusCode.PERSISTENT_ERROR:
239
+ return new ServerError(error.code, error.description);
240
+ case BridgeStatusCode.USER_INTERACTION_REQUIRED:
241
+ return new InteractionRequiredAuthError(
242
+ error.code,
243
+ error.description
244
+ );
245
+ default:
246
+ return new AuthError(error.code, error.description);
247
+ }
248
+ } else {
249
+ return new AuthError("unknown_error", "An unknown error occurred");
250
+ }
251
+ }
252
+ }
@@ -4,8 +4,14 @@
4
4
  */
5
5
 
6
6
  import { BaseOperatingContext } from "./BaseOperatingContext";
7
+ import { IBridgeProxy } from "../naa/IBridgeProxy";
8
+ import { BridgeProxy } from "../naa/BridgeProxy";
9
+ import { AccountInfo } from "../naa/AccountInfo";
7
10
 
8
11
  export class TeamsAppOperatingContext extends BaseOperatingContext {
12
+ protected bridgeProxy: IBridgeProxy | undefined = undefined;
13
+ protected activeAccount: AccountInfo | undefined = undefined;
14
+
9
15
  /*
10
16
  * TODO: Once we have determine the bundling code return here to specify the name of the bundle
11
17
  * containing the implementation for this operating context
@@ -33,6 +39,18 @@ export class TeamsAppOperatingContext extends BaseOperatingContext {
33
39
  return TeamsAppOperatingContext.ID;
34
40
  }
35
41
 
42
+ getBridgeProxy(): IBridgeProxy | undefined {
43
+ return this.bridgeProxy;
44
+ }
45
+
46
+ getActiveAccount(): AccountInfo | undefined {
47
+ return this.activeAccount;
48
+ }
49
+
50
+ setActiveAccount(account: AccountInfo): void {
51
+ this.activeAccount = account;
52
+ }
53
+
36
54
  /**
37
55
  * Checks whether the operating context is available.
38
56
  * Confirms that the code is running a browser rather. This is required.
@@ -40,9 +58,31 @@ export class TeamsAppOperatingContext extends BaseOperatingContext {
40
58
  */
41
59
  async initialize(): Promise<boolean> {
42
60
  /*
43
- * TODO: Add implementation to check for presence of inject MetaOSHub JavaScript interface
44
- * TODO: Make pre-flight token request to ensure that App is eligible to use Nested App Auth
61
+ * TODO: Add implementation to check for presence of inject Nested App Auth Bridge JavaScript interface
62
+ *
45
63
  */
46
- return false;
64
+ try {
65
+ if (typeof window !== "undefined") {
66
+ const bridgeProxy: IBridgeProxy = await BridgeProxy.create();
67
+ /*
68
+ * Because we want single sign on we need to attempt to
69
+ * grab the active account as part of initialization
70
+ * this.activeAccount = await bridgeProxy.getActiveAccount();
71
+ */
72
+ try {
73
+ this.activeAccount = await bridgeProxy.getActiveAccount();
74
+ } catch (e) {
75
+ this.activeAccount = undefined;
76
+ }
77
+ this.bridgeProxy = bridgeProxy;
78
+ this.available = bridgeProxy !== undefined;
79
+ } else {
80
+ this.available = false;
81
+ }
82
+ } catch (e) {
83
+ this.available = false;
84
+ } finally {
85
+ return this.available;
86
+ }
47
87
  }
48
88
  }
@@ -0,0 +1,48 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { BaseOperatingContext } from "./BaseOperatingContext";
7
+
8
+ export class UnknownOperatingContext extends BaseOperatingContext {
9
+ /*
10
+ * TODO: Once we have determine the bundling code return here to specify the name of the bundle
11
+ * containing the implementation for this operating context
12
+ */
13
+ static readonly MODULE_NAME: string = "";
14
+
15
+ /**
16
+ * Unique identifier for the operating context
17
+ */
18
+ static readonly ID: string = "UnknownOperatingContext";
19
+
20
+ /**
21
+ * Return the module name. Intended for use with import() to enable dynamic import
22
+ * of the implementation associated with this operating context
23
+ * @returns
24
+ */
25
+ getModuleName(): string {
26
+ return UnknownOperatingContext.MODULE_NAME;
27
+ }
28
+ /**
29
+ * Returns the unique identifier for this operating context
30
+ * @returns string
31
+ */
32
+ getId(): string {
33
+ return UnknownOperatingContext.ID;
34
+ }
35
+
36
+ /**
37
+ * Checks whether the operating context is available.
38
+ * Confirms that the code is running a browser rather. This is required.
39
+ * @returns Promise<boolean> indicating whether this operating context is currently available.
40
+ */
41
+ async initialize(): Promise<boolean> {
42
+ /**
43
+ * This operating context is in use when we have not checked for what the operating context is.
44
+ * The context is unknown until we check it.
45
+ */
46
+ return true;
47
+ }
48
+ }
@@ -1,3 +1,3 @@
1
1
  /* eslint-disable header/header */
2
2
  export const name = "@azure/msal-browser";
3
- export const version = "3.1.0";
3
+ export const version = "3.3.0";
@@ -5,12 +5,13 @@
5
5
 
6
6
  import { InteractionType } from "./BrowserConstants";
7
7
  import {
8
- ClientAuthError,
9
8
  ICrypto,
10
9
  RequestStateObject,
11
10
  ProtocolUtils,
12
11
  ServerAuthorizationCodeResponse,
13
12
  UrlString,
13
+ createClientAuthError,
14
+ ClientAuthErrorCodes,
14
15
  } from "@azure/msal-common";
15
16
 
16
17
  export type BrowserStateObject = {
@@ -36,7 +37,7 @@ export class BrowserProtocolUtils {
36
37
  ProtocolUtils.parseRequestState(browserCrypto, state);
37
38
  return requestStateObj.libraryState.meta as BrowserStateObject;
38
39
  } catch (e) {
39
- throw ClientAuthError.createInvalidStateError(state, e as string);
40
+ throw createClientAuthError(ClientAuthErrorCodes.invalidState);
40
41
  }
41
42
  }
42
43