@azure/msal-browser 3.2.0 → 3.4.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 (224) hide show
  1. package/dist/app/IPublicClientApplication.mjs +1 -1
  2. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  3. package/dist/app/PublicClientApplication.mjs +3 -4
  4. package/dist/app/PublicClientApplication.mjs.map +1 -1
  5. package/dist/app/PublicClientNext.d.ts +274 -0
  6. package/dist/app/PublicClientNext.d.ts.map +1 -0
  7. package/dist/app/PublicClientNext.mjs +360 -0
  8. package/dist/app/PublicClientNext.mjs.map +1 -0
  9. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +1 -1
  10. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +1 -1
  11. package/dist/cache/AsyncMemoryStorage.mjs +1 -1
  12. package/dist/cache/BrowserCacheManager.d.ts +2 -13
  13. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  14. package/dist/cache/BrowserCacheManager.mjs +26 -83
  15. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  16. package/dist/cache/BrowserStorage.mjs +1 -1
  17. package/dist/cache/CryptoKeyStore.mjs +1 -1
  18. package/dist/cache/DatabaseStorage.mjs +1 -1
  19. package/dist/cache/MemoryStorage.mjs +1 -1
  20. package/dist/cache/TokenCache.d.ts.map +1 -1
  21. package/dist/cache/TokenCache.mjs +5 -5
  22. package/dist/cache/TokenCache.mjs.map +1 -1
  23. package/dist/config/Configuration.d.ts +4 -0
  24. package/dist/config/Configuration.d.ts.map +1 -1
  25. package/dist/config/Configuration.mjs +2 -1
  26. package/dist/config/Configuration.mjs.map +1 -1
  27. package/dist/controllers/ControllerFactory.d.ts +2 -7
  28. package/dist/controllers/ControllerFactory.d.ts.map +1 -1
  29. package/dist/controllers/ControllerFactory.mjs +24 -34
  30. package/dist/controllers/ControllerFactory.mjs.map +1 -1
  31. package/dist/controllers/IController.d.ts +1 -2
  32. package/dist/controllers/IController.d.ts.map +1 -1
  33. package/dist/controllers/NestedAppAuthController.d.ts +96 -0
  34. package/dist/controllers/NestedAppAuthController.d.ts.map +1 -0
  35. package/dist/controllers/NestedAppAuthController.mjs +345 -0
  36. package/dist/controllers/NestedAppAuthController.mjs.map +1 -0
  37. package/dist/controllers/StandardController.d.ts +4 -4
  38. package/dist/controllers/StandardController.d.ts.map +1 -1
  39. package/dist/controllers/StandardController.mjs +43 -42
  40. package/dist/controllers/StandardController.mjs.map +1 -1
  41. package/dist/controllers/UnknownOperatingContextController.d.ts +88 -0
  42. package/dist/controllers/UnknownOperatingContextController.d.ts.map +1 -0
  43. package/dist/controllers/UnknownOperatingContextController.mjs +275 -0
  44. package/dist/controllers/UnknownOperatingContextController.mjs.map +1 -0
  45. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  46. package/dist/crypto/BrowserCrypto.mjs +3 -3
  47. package/dist/crypto/BrowserCrypto.mjs.map +1 -1
  48. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  49. package/dist/crypto/CryptoOps.mjs +8 -5
  50. package/dist/crypto/CryptoOps.mjs.map +1 -1
  51. package/dist/crypto/PkceGenerator.mjs +1 -1
  52. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  53. package/dist/encode/Base64Decode.mjs +1 -1
  54. package/dist/encode/Base64Encode.mjs +1 -1
  55. package/dist/error/BrowserAuthError.mjs +1 -1
  56. package/dist/error/BrowserAuthErrorCodes.mjs +1 -1
  57. package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
  58. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +1 -1
  59. package/dist/error/NativeAuthError.mjs +1 -1
  60. package/dist/error/NativeAuthErrorCodes.mjs +1 -1
  61. package/dist/error/NestedAppAuthError.d.ts +15 -0
  62. package/dist/error/NestedAppAuthError.d.ts.map +1 -0
  63. package/dist/error/NestedAppAuthError.mjs +30 -0
  64. package/dist/error/NestedAppAuthError.mjs.map +1 -0
  65. package/dist/event/EventHandler.mjs +1 -1
  66. package/dist/event/EventMessage.mjs +1 -1
  67. package/dist/event/EventType.mjs +1 -1
  68. package/dist/index.d.ts +3 -5
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.mjs +4 -2
  71. package/dist/index.mjs.map +1 -1
  72. package/dist/interaction_client/BaseInteractionClient.mjs +4 -4
  73. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  74. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  75. package/dist/interaction_client/NativeInteractionClient.mjs +18 -7
  76. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  77. package/dist/interaction_client/PopupClient.d.ts +1 -2
  78. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  79. package/dist/interaction_client/PopupClient.mjs +13 -25
  80. package/dist/interaction_client/PopupClient.mjs.map +1 -1
  81. package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
  82. package/dist/interaction_client/RedirectClient.mjs +17 -25
  83. package/dist/interaction_client/RedirectClient.mjs.map +1 -1
  84. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  85. package/dist/interaction_client/SilentAuthCodeClient.mjs +6 -8
  86. package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
  87. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  88. package/dist/interaction_client/SilentCacheClient.mjs +4 -3
  89. package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
  90. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  91. package/dist/interaction_client/SilentIframeClient.mjs +28 -19
  92. package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
  93. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
  94. package/dist/interaction_client/SilentRefreshClient.mjs +2 -12
  95. package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
  96. package/dist/interaction_client/StandardInteractionClient.mjs +5 -5
  97. package/dist/interaction_handler/InteractionHandler.d.ts +6 -13
  98. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  99. package/dist/interaction_handler/InteractionHandler.mjs +29 -56
  100. package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
  101. package/dist/interaction_handler/RedirectHandler.d.ts +14 -7
  102. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  103. package/dist/interaction_handler/RedirectHandler.mjs +28 -9
  104. package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
  105. package/dist/interaction_handler/SilentHandler.d.ts +13 -47
  106. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  107. package/dist/interaction_handler/SilentHandler.mjs +120 -155
  108. package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
  109. package/dist/naa/AccountInfo.d.ts +13 -0
  110. package/dist/naa/AccountInfo.d.ts.map +1 -0
  111. package/dist/naa/AccountRequests.d.ts +10 -0
  112. package/dist/naa/AccountRequests.d.ts.map +1 -0
  113. package/dist/naa/AuthBridge.d.ts +6 -0
  114. package/dist/naa/AuthBridge.d.ts.map +1 -0
  115. package/dist/naa/BridgeCapabilities.d.ts +4 -0
  116. package/dist/naa/BridgeCapabilities.d.ts.map +1 -0
  117. package/dist/naa/BridgeError.d.ts +10 -0
  118. package/dist/naa/BridgeError.d.ts.map +1 -0
  119. package/dist/naa/BridgeError.mjs +12 -0
  120. package/dist/naa/BridgeError.mjs.map +1 -0
  121. package/dist/naa/BridgeProxy.d.ts +72 -0
  122. package/dist/naa/BridgeProxy.d.ts.map +1 -0
  123. package/dist/naa/BridgeProxy.mjs +154 -0
  124. package/dist/naa/BridgeProxy.mjs.map +1 -0
  125. package/dist/naa/BridgeRequest.d.ts +7 -0
  126. package/dist/naa/BridgeRequest.d.ts.map +1 -0
  127. package/dist/naa/BridgeRequestEnvelope.d.ts +14 -0
  128. package/dist/naa/BridgeRequestEnvelope.d.ts.map +1 -0
  129. package/dist/naa/BridgeResponseEnvelope.d.ts +11 -0
  130. package/dist/naa/BridgeResponseEnvelope.d.ts.map +1 -0
  131. package/dist/naa/BridgeStatusCode.d.ts +11 -0
  132. package/dist/naa/BridgeStatusCode.d.ts.map +1 -0
  133. package/dist/naa/BridgeStatusCode.mjs +20 -0
  134. package/dist/naa/BridgeStatusCode.mjs.map +1 -0
  135. package/dist/naa/IBridgeProxy.d.ts +11 -0
  136. package/dist/naa/IBridgeProxy.d.ts.map +1 -0
  137. package/dist/naa/InitializeBridgeResponse.d.ts +7 -0
  138. package/dist/naa/InitializeBridgeResponse.d.ts.map +1 -0
  139. package/dist/naa/TokenRequest.d.ts +22 -0
  140. package/dist/naa/TokenRequest.d.ts.map +1 -0
  141. package/dist/naa/TokenResponse.d.ts +17 -0
  142. package/dist/naa/TokenResponse.d.ts.map +1 -0
  143. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts +26 -0
  144. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts.map +1 -0
  145. package/dist/naa/mapping/NestedAppAuthAdapter.mjs +178 -0
  146. package/dist/naa/mapping/NestedAppAuthAdapter.mjs.map +1 -0
  147. package/dist/navigation/NavigationClient.mjs +1 -1
  148. package/dist/network/FetchClient.mjs +1 -1
  149. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  150. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  151. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts +7 -0
  152. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts.map +1 -1
  153. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +45 -4
  154. package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
  155. package/dist/operatingcontext/UnknownOperatingContext.d.ts +26 -0
  156. package/dist/operatingcontext/UnknownOperatingContext.d.ts.map +1 -0
  157. package/dist/operatingcontext/UnknownOperatingContext.mjs +49 -0
  158. package/dist/operatingcontext/UnknownOperatingContext.mjs.map +1 -0
  159. package/dist/packageMetadata.d.ts +1 -1
  160. package/dist/packageMetadata.mjs +2 -2
  161. package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
  162. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  163. package/dist/utils/BrowserConstants.mjs +1 -1
  164. package/dist/utils/BrowserProtocolUtils.mjs +1 -1
  165. package/dist/utils/BrowserUtils.d.ts +54 -53
  166. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  167. package/dist/utils/BrowserUtils.mjs +114 -102
  168. package/dist/utils/BrowserUtils.mjs.map +1 -1
  169. package/lib/msal-browser.cjs +13221 -12385
  170. package/lib/msal-browser.cjs.map +1 -1
  171. package/lib/msal-browser.js +13221 -12385
  172. package/lib/msal-browser.js.map +1 -1
  173. package/lib/msal-browser.min.js +67 -68
  174. package/package.json +2 -2
  175. package/src/app/PublicClientApplication.ts +4 -3
  176. package/src/app/PublicClientNext.ts +444 -0
  177. package/src/cache/BrowserCacheManager.ts +33 -140
  178. package/src/cache/TokenCache.ts +5 -4
  179. package/src/config/Configuration.ts +5 -0
  180. package/src/controllers/ControllerFactory.ts +35 -43
  181. package/src/controllers/IController.ts +0 -6
  182. package/src/controllers/NestedAppAuthController.ts +525 -0
  183. package/src/controllers/StandardController.ts +50 -52
  184. package/src/controllers/UnknownOperatingContextController.ts +383 -0
  185. package/src/crypto/BrowserCrypto.ts +2 -2
  186. package/src/crypto/CryptoOps.ts +8 -5
  187. package/src/error/NestedAppAuthError.ts +32 -0
  188. package/src/index.ts +3 -10
  189. package/src/interaction_client/BaseInteractionClient.ts +1 -1
  190. package/src/interaction_client/NativeInteractionClient.ts +23 -6
  191. package/src/interaction_client/PopupClient.ts +41 -61
  192. package/src/interaction_client/RedirectClient.ts +42 -47
  193. package/src/interaction_client/SilentAuthCodeClient.ts +6 -16
  194. package/src/interaction_client/SilentCacheClient.ts +11 -3
  195. package/src/interaction_client/SilentIframeClient.ts +54 -34
  196. package/src/interaction_client/SilentRefreshClient.ts +5 -19
  197. package/src/interaction_client/StandardInteractionClient.ts +1 -1
  198. package/src/interaction_handler/InteractionHandler.ts +34 -104
  199. package/src/interaction_handler/RedirectHandler.ts +48 -22
  200. package/src/interaction_handler/SilentHandler.ts +177 -233
  201. package/src/naa/AccountInfo.ts +17 -0
  202. package/src/naa/AccountRequests.ts +16 -0
  203. package/src/naa/AuthBridge.ts +16 -0
  204. package/src/naa/BridgeCapabilities.ts +8 -0
  205. package/src/naa/BridgeError.ts +18 -0
  206. package/src/naa/BridgeProxy.ts +230 -0
  207. package/src/naa/BridgeRequest.ts +12 -0
  208. package/src/naa/BridgeRequestEnvelope.ts +46 -0
  209. package/src/naa/BridgeResponseEnvelope.ts +21 -0
  210. package/src/naa/BridgeStatusCode.ts +15 -0
  211. package/src/naa/IBridgeProxy.ts +25 -0
  212. package/src/naa/InitializeBridgeResponse.ts +12 -0
  213. package/src/naa/TokenRequest.ts +26 -0
  214. package/src/naa/TokenResponse.ts +61 -0
  215. package/src/naa/mapping/NestedAppAuthAdapter.ts +252 -0
  216. package/src/operatingcontext/TeamsAppOperatingContext.ts +43 -3
  217. package/src/operatingcontext/UnknownOperatingContext.ts +48 -0
  218. package/src/packageMetadata.ts +1 -1
  219. package/src/utils/BrowserUtils.ts +133 -125
  220. package/dist/utils/BrowserStringUtils.d.ts +0 -22
  221. package/dist/utils/BrowserStringUtils.d.ts.map +0 -1
  222. package/dist/utils/BrowserStringUtils.mjs +0 -144
  223. package/dist/utils/BrowserStringUtils.mjs.map +0 -1
  224. 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.2.0";
3
+ export const version = "3.4.0";
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { Constants, UrlString } from "@azure/msal-common";
6
+ import { UrlString } from "@azure/msal-common";
7
7
  import {
8
8
  createBrowserAuthError,
9
9
  BrowserAuthErrorCodes,
@@ -11,146 +11,154 @@ import {
11
11
  import { InteractionType, BrowserConstants } from "./BrowserConstants";
12
12
 
13
13
  /**
14
- * Utility class for browser specific functions
14
+ * Clears hash from window url.
15
15
  */
16
- export class BrowserUtils {
17
- // #region Window Navigation and URL management
18
-
19
- /**
20
- * Clears hash from window url.
21
- */
22
- static clearHash(contentWindow: Window): void {
23
- // Office.js sets history.replaceState to null
24
- contentWindow.location.hash = Constants.EMPTY_STRING;
25
- if (typeof contentWindow.history.replaceState === "function") {
26
- // Full removes "#" from url
27
- contentWindow.history.replaceState(
28
- null,
29
- Constants.EMPTY_STRING,
30
- `${contentWindow.location.origin}${contentWindow.location.pathname}${contentWindow.location.search}`
31
- );
32
- }
16
+ export function clearHash(contentWindow: Window): void {
17
+ // Office.js sets history.replaceState to null
18
+ contentWindow.location.hash = "";
19
+ if (typeof contentWindow.history.replaceState === "function") {
20
+ // Full removes "#" from url
21
+ contentWindow.history.replaceState(
22
+ null,
23
+ "",
24
+ `${contentWindow.location.origin}${contentWindow.location.pathname}${contentWindow.location.search}`
25
+ );
33
26
  }
27
+ }
34
28
 
35
- /**
36
- * Replaces current hash with hash from provided url
37
- */
38
- static replaceHash(url: string): void {
39
- const urlParts = url.split("#");
40
- urlParts.shift(); // Remove part before the hash
41
- window.location.hash =
42
- urlParts.length > 0 ? urlParts.join("#") : Constants.EMPTY_STRING;
43
- }
29
+ /**
30
+ * Replaces current hash with hash from provided url
31
+ */
32
+ export function replaceHash(url: string): void {
33
+ const urlParts = url.split("#");
34
+ urlParts.shift(); // Remove part before the hash
35
+ window.location.hash = urlParts.length > 0 ? urlParts.join("#") : "";
36
+ }
44
37
 
45
- /**
46
- * Returns boolean of whether the current window is in an iframe or not.
47
- */
48
- static isInIframe(): boolean {
49
- return window.parent !== window;
50
- }
38
+ /**
39
+ * Returns boolean of whether the current window is in an iframe or not.
40
+ */
41
+ export function isInIframe(): boolean {
42
+ return window.parent !== window;
43
+ }
51
44
 
52
- /**
53
- * Returns boolean of whether or not the current window is a popup opened by msal
54
- */
55
- static isInPopup(): boolean {
56
- return (
57
- typeof window !== "undefined" &&
58
- !!window.opener &&
59
- window.opener !== window &&
60
- typeof window.name === "string" &&
61
- window.name.indexOf(`${BrowserConstants.POPUP_NAME_PREFIX}.`) === 0
62
- );
63
- }
45
+ /**
46
+ * Returns boolean of whether or not the current window is a popup opened by msal
47
+ */
48
+ export function isInPopup(): boolean {
49
+ return (
50
+ typeof window !== "undefined" &&
51
+ !!window.opener &&
52
+ window.opener !== window &&
53
+ typeof window.name === "string" &&
54
+ window.name.indexOf(`${BrowserConstants.POPUP_NAME_PREFIX}.`) === 0
55
+ );
56
+ }
64
57
 
65
- // #endregion
58
+ // #endregion
66
59
 
67
- /**
68
- * Returns current window URL as redirect uri
69
- */
70
- static getCurrentUri(): string {
71
- return window.location.href.split("?")[0].split("#")[0];
72
- }
60
+ /**
61
+ * Returns current window URL as redirect uri
62
+ */
63
+ export function getCurrentUri(): string {
64
+ return window.location.href.split("?")[0].split("#")[0];
65
+ }
73
66
 
74
- /**
75
- * Gets the homepage url for the current window location.
76
- */
77
- static getHomepage(): string {
78
- const currentUrl = new UrlString(window.location.href);
79
- const urlComponents = currentUrl.getUrlComponents();
80
- return `${urlComponents.Protocol}//${urlComponents.HostNameAndPort}/`;
81
- }
67
+ /**
68
+ * Gets the homepage url for the current window location.
69
+ */
70
+ export function getHomepage(): string {
71
+ const currentUrl = new UrlString(window.location.href);
72
+ const urlComponents = currentUrl.getUrlComponents();
73
+ return `${urlComponents.Protocol}//${urlComponents.HostNameAndPort}/`;
74
+ }
82
75
 
83
- /**
84
- * Throws error if we have completed an auth and are
85
- * attempting another auth request inside an iframe.
86
- */
87
- static blockReloadInHiddenIframes(): void {
88
- const isResponseHash = UrlString.hashContainsKnownProperties(
89
- window.location.hash
90
- );
91
- // return an error if called from the hidden iframe created by the msal js silent calls
92
- if (isResponseHash && BrowserUtils.isInIframe()) {
93
- throw createBrowserAuthError(
94
- BrowserAuthErrorCodes.blockIframeReload
95
- );
96
- }
76
+ /**
77
+ * Throws error if we have completed an auth and are
78
+ * attempting another auth request inside an iframe.
79
+ */
80
+ export function blockReloadInHiddenIframes(): void {
81
+ const isResponseHash = UrlString.hashContainsKnownProperties(
82
+ window.location.hash
83
+ );
84
+ // return an error if called from the hidden iframe created by the msal js silent calls
85
+ if (isResponseHash && isInIframe()) {
86
+ throw createBrowserAuthError(BrowserAuthErrorCodes.blockIframeReload);
97
87
  }
88
+ }
98
89
 
99
- /**
100
- * Block redirect operations in iframes unless explicitly allowed
101
- * @param interactionType Interaction type for the request
102
- * @param allowRedirectInIframe Config value to allow redirects when app is inside an iframe
103
- */
104
- static blockRedirectInIframe(
105
- interactionType: InteractionType,
106
- allowRedirectInIframe: boolean
107
- ): void {
108
- const isIframedApp = BrowserUtils.isInIframe();
109
- if (
110
- interactionType === InteractionType.Redirect &&
111
- isIframedApp &&
112
- !allowRedirectInIframe
113
- ) {
114
- // If we are not in top frame, we shouldn't redirect. This is also handled by the service.
115
- throw createBrowserAuthError(
116
- BrowserAuthErrorCodes.redirectInIframe
117
- );
118
- }
90
+ /**
91
+ * Block redirect operations in iframes unless explicitly allowed
92
+ * @param interactionType Interaction type for the request
93
+ * @param allowRedirectInIframe Config value to allow redirects when app is inside an iframe
94
+ */
95
+ export function blockRedirectInIframe(
96
+ interactionType: InteractionType,
97
+ allowRedirectInIframe: boolean
98
+ ): void {
99
+ const isIframedApp = isInIframe();
100
+ if (
101
+ interactionType === InteractionType.Redirect &&
102
+ isIframedApp &&
103
+ !allowRedirectInIframe
104
+ ) {
105
+ // If we are not in top frame, we shouldn't redirect. This is also handled by the service.
106
+ throw createBrowserAuthError(BrowserAuthErrorCodes.redirectInIframe);
119
107
  }
108
+ }
120
109
 
121
- /**
122
- * Block redirectUri loaded in popup from calling AcquireToken APIs
123
- */
124
- static blockAcquireTokenInPopups(): void {
125
- // Popups opened by msal popup APIs are given a name that starts with "msal."
126
- if (BrowserUtils.isInPopup()) {
127
- throw createBrowserAuthError(
128
- BrowserAuthErrorCodes.blockNestedPopups
129
- );
130
- }
110
+ /**
111
+ * Block redirectUri loaded in popup from calling AcquireToken APIs
112
+ */
113
+ export function blockAcquireTokenInPopups(): void {
114
+ // Popups opened by msal popup APIs are given a name that starts with "msal."
115
+ if (isInPopup()) {
116
+ throw createBrowserAuthError(BrowserAuthErrorCodes.blockNestedPopups);
131
117
  }
118
+ }
132
119
 
133
- /**
134
- * Throws error if token requests are made in non-browser environment
135
- * @param isBrowserEnvironment Flag indicating if environment is a browser.
136
- */
137
- static blockNonBrowserEnvironment(isBrowserEnvironment: boolean): void {
138
- if (!isBrowserEnvironment) {
139
- throw createBrowserAuthError(
140
- BrowserAuthErrorCodes.nonBrowserEnvironment
141
- );
142
- }
120
+ /**
121
+ * Throws error if token requests are made in non-browser environment
122
+ * @param isBrowserEnvironment Flag indicating if environment is a browser.
123
+ */
124
+ export function blockNonBrowserEnvironment(
125
+ isBrowserEnvironment: boolean
126
+ ): void {
127
+ if (!isBrowserEnvironment) {
128
+ throw createBrowserAuthError(
129
+ BrowserAuthErrorCodes.nonBrowserEnvironment
130
+ );
143
131
  }
132
+ }
144
133
 
145
- /**
146
- * Throws error if initialize hasn't been called
147
- * @param initialized
148
- */
149
- static blockAPICallsBeforeInitialize(initialized: boolean): void {
150
- if (!initialized) {
151
- throw createBrowserAuthError(
152
- BrowserAuthErrorCodes.uninitializedPublicClientApplication
153
- );
154
- }
134
+ /**
135
+ * Throws error if initialize hasn't been called
136
+ * @param initialized
137
+ */
138
+ export function blockAPICallsBeforeInitialize(initialized: boolean): void {
139
+ if (!initialized) {
140
+ throw createBrowserAuthError(
141
+ BrowserAuthErrorCodes.uninitializedPublicClientApplication
142
+ );
155
143
  }
156
144
  }
145
+
146
+ /**
147
+ * Adds a preconnect link element to the header which begins DNS resolution and SSL connection in anticipation of the /token request
148
+ * @param loginDomain Authority domain, including https protocol e.g. https://login.microsoftonline.com
149
+ * @returns
150
+ */
151
+ export function preconnect(authority: string): void {
152
+ const link = document.createElement("link");
153
+ link.rel = "preconnect";
154
+ link.href = new URL(authority).origin;
155
+ link.crossOrigin = "anonymous";
156
+ document.head.appendChild(link);
157
+
158
+ // The browser will close connection if not used within a few seconds, remove element from the header after 10s
159
+ window.setTimeout(() => {
160
+ try {
161
+ document.head.removeChild(link);
162
+ } catch {}
163
+ }, 10000); // 10s Timeout
164
+ }