@azure/msal-browser 3.0.2 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. package/dist/app/IPublicClientApplication.d.ts +2 -0
  2. package/dist/app/IPublicClientApplication.d.ts.map +1 -1
  3. package/dist/app/IPublicClientApplication.mjs +22 -18
  4. package/dist/app/IPublicClientApplication.mjs.map +1 -1
  5. package/dist/app/PublicClientApplication.d.ts +20 -6
  6. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  7. package/dist/app/PublicClientApplication.mjs +24 -7
  8. package/dist/app/PublicClientApplication.mjs.map +1 -1
  9. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +3 -4
  10. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
  11. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +17 -16
  12. package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +1 -1
  13. package/dist/broker/nativeBroker/NativeStatusCodes.d.ts +8 -0
  14. package/dist/broker/nativeBroker/NativeStatusCodes.d.ts.map +1 -0
  15. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +16 -0
  16. package/dist/broker/nativeBroker/NativeStatusCodes.mjs.map +1 -0
  17. package/dist/cache/AsyncMemoryStorage.mjs +4 -3
  18. package/dist/cache/AsyncMemoryStorage.mjs.map +1 -1
  19. package/dist/cache/BrowserCacheManager.d.ts +10 -3
  20. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  21. package/dist/cache/BrowserCacheManager.mjs +58 -29
  22. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  23. package/dist/cache/BrowserStorage.d.ts.map +1 -1
  24. package/dist/cache/BrowserStorage.mjs +7 -9
  25. package/dist/cache/BrowserStorage.mjs.map +1 -1
  26. package/dist/cache/CryptoKeyStore.mjs +1 -1
  27. package/dist/cache/CryptoKeyStore.mjs.map +1 -1
  28. package/dist/cache/DatabaseStorage.d.ts.map +1 -1
  29. package/dist/cache/DatabaseStorage.mjs +9 -8
  30. package/dist/cache/DatabaseStorage.mjs.map +1 -1
  31. package/dist/cache/MemoryStorage.mjs +1 -1
  32. package/dist/cache/MemoryStorage.mjs.map +1 -1
  33. package/dist/cache/TokenCache.d.ts.map +1 -1
  34. package/dist/cache/TokenCache.mjs +30 -30
  35. package/dist/cache/TokenCache.mjs.map +1 -1
  36. package/dist/config/Configuration.d.ts +1 -0
  37. package/dist/config/Configuration.d.ts.map +1 -1
  38. package/dist/config/Configuration.mjs +12 -16
  39. package/dist/config/Configuration.mjs.map +1 -1
  40. package/dist/controllers/ControllerFactory.mjs +1 -1
  41. package/dist/controllers/ControllerFactory.mjs.map +1 -1
  42. package/dist/controllers/IController.d.ts +5 -28
  43. package/dist/controllers/IController.d.ts.map +1 -1
  44. package/dist/controllers/StandardController.d.ts +17 -31
  45. package/dist/controllers/StandardController.d.ts.map +1 -1
  46. package/dist/controllers/StandardController.mjs +78 -83
  47. package/dist/controllers/StandardController.mjs.map +1 -1
  48. package/dist/crypto/BrowserCrypto.d.ts +44 -49
  49. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  50. package/dist/crypto/BrowserCrypto.mjs +78 -77
  51. package/dist/crypto/BrowserCrypto.mjs.map +1 -1
  52. package/dist/crypto/CryptoOps.d.ts +1 -10
  53. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  54. package/dist/crypto/CryptoOps.mjs +23 -34
  55. package/dist/crypto/CryptoOps.mjs.map +1 -1
  56. package/dist/crypto/PkceGenerator.d.ts +6 -22
  57. package/dist/crypto/PkceGenerator.d.ts.map +1 -1
  58. package/dist/crypto/PkceGenerator.mjs +48 -49
  59. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  60. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  61. package/dist/crypto/SignedHttpRequest.mjs.map +1 -1
  62. package/dist/encode/Base64Decode.d.ts +6 -19
  63. package/dist/encode/Base64Decode.d.ts.map +1 -1
  64. package/dist/encode/Base64Decode.mjs +31 -68
  65. package/dist/encode/Base64Decode.mjs.map +1 -1
  66. package/dist/encode/Base64Encode.d.ts +15 -27
  67. package/dist/encode/Base64Encode.d.ts.map +1 -1
  68. package/dist/encode/Base64Encode.mjs +36 -75
  69. package/dist/encode/Base64Encode.mjs.map +1 -1
  70. package/dist/error/BrowserAuthError.d.ts +63 -195
  71. package/dist/error/BrowserAuthError.d.ts.map +1 -1
  72. package/dist/error/BrowserAuthError.mjs +159 -381
  73. package/dist/error/BrowserAuthError.mjs.map +1 -1
  74. package/dist/error/BrowserAuthErrorCodes.d.ts +46 -0
  75. package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -0
  76. package/dist/error/BrowserAuthErrorCodes.mjs +54 -0
  77. package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -0
  78. package/dist/error/BrowserConfigurationAuthError.d.ts +9 -46
  79. package/dist/error/BrowserConfigurationAuthError.d.ts.map +1 -1
  80. package/dist/error/BrowserConfigurationAuthError.mjs +20 -73
  81. package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
  82. package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts +4 -0
  83. package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts.map +1 -0
  84. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +12 -0
  85. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs.map +1 -0
  86. package/dist/error/NativeAuthError.d.ts +17 -45
  87. package/dist/error/NativeAuthError.d.ts.map +1 -1
  88. package/dist/error/NativeAuthError.mjs +49 -79
  89. package/dist/error/NativeAuthError.mjs.map +1 -1
  90. package/dist/error/NativeAuthErrorCodes.d.ts +3 -0
  91. package/dist/error/NativeAuthErrorCodes.d.ts.map +1 -0
  92. package/dist/error/NativeAuthErrorCodes.mjs +11 -0
  93. package/dist/error/NativeAuthErrorCodes.mjs.map +1 -0
  94. package/dist/event/EventHandler.d.ts.map +1 -1
  95. package/dist/event/EventHandler.mjs +3 -2
  96. package/dist/event/EventHandler.mjs.map +1 -1
  97. package/dist/event/EventMessage.mjs +1 -1
  98. package/dist/event/EventMessage.mjs.map +1 -1
  99. package/dist/event/EventType.mjs +1 -1
  100. package/dist/event/EventType.mjs.map +1 -1
  101. package/dist/index.d.ts +6 -6
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.mjs +8 -4
  104. package/dist/index.mjs.map +1 -1
  105. package/dist/interaction_client/BaseInteractionClient.d.ts +2 -1
  106. package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
  107. package/dist/interaction_client/BaseInteractionClient.mjs +7 -8
  108. package/dist/interaction_client/BaseInteractionClient.mjs.map +1 -1
  109. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  110. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs.map +1 -1
  111. package/dist/interaction_client/NativeInteractionClient.d.ts +4 -10
  112. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  113. package/dist/interaction_client/NativeInteractionClient.mjs +32 -38
  114. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  115. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  116. package/dist/interaction_client/PopupClient.mjs +16 -15
  117. package/dist/interaction_client/PopupClient.mjs.map +1 -1
  118. package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
  119. package/dist/interaction_client/RedirectClient.mjs +7 -6
  120. package/dist/interaction_client/RedirectClient.mjs.map +1 -1
  121. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  122. package/dist/interaction_client/SilentAuthCodeClient.mjs +9 -11
  123. package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
  124. package/dist/interaction_client/SilentCacheClient.d.ts +4 -2
  125. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  126. package/dist/interaction_client/SilentCacheClient.mjs +19 -25
  127. package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
  128. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  129. package/dist/interaction_client/SilentIframeClient.mjs +20 -47
  130. package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
  131. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
  132. package/dist/interaction_client/SilentRefreshClient.mjs +11 -20
  133. package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
  134. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  135. package/dist/interaction_client/StandardInteractionClient.mjs +18 -38
  136. package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
  137. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  138. package/dist/interaction_handler/InteractionHandler.mjs +13 -16
  139. package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
  140. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  141. package/dist/interaction_handler/RedirectHandler.mjs +12 -11
  142. package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
  143. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  144. package/dist/interaction_handler/SilentHandler.mjs +11 -11
  145. package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
  146. package/dist/navigation/NavigationClient.mjs +1 -1
  147. package/dist/navigation/NavigationClient.mjs.map +1 -1
  148. package/dist/network/FetchClient.d.ts.map +1 -1
  149. package/dist/network/FetchClient.mjs +9 -8
  150. package/dist/network/FetchClient.mjs.map +1 -1
  151. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  152. package/dist/operatingcontext/BaseOperatingContext.mjs.map +1 -1
  153. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  154. package/dist/operatingcontext/StandardOperatingContext.mjs.map +1 -1
  155. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +1 -1
  156. package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
  157. package/dist/packageMetadata.d.ts +1 -1
  158. package/dist/packageMetadata.mjs +2 -2
  159. package/dist/packageMetadata.mjs.map +1 -1
  160. package/dist/request/ClearCacheRequest.d.ts +11 -0
  161. package/dist/request/ClearCacheRequest.d.ts.map +1 -0
  162. package/dist/telemetry/BrowserPerformanceClient.d.ts +2 -4
  163. package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -1
  164. package/dist/telemetry/BrowserPerformanceClient.mjs +2 -6
  165. package/dist/telemetry/BrowserPerformanceClient.mjs.map +1 -1
  166. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  167. package/dist/telemetry/BrowserPerformanceMeasurement.mjs.map +1 -1
  168. package/dist/utils/BrowserConstants.mjs +1 -1
  169. package/dist/utils/BrowserConstants.mjs.map +1 -1
  170. package/dist/utils/BrowserProtocolUtils.d.ts.map +1 -1
  171. package/dist/utils/BrowserProtocolUtils.mjs +4 -4
  172. package/dist/utils/BrowserProtocolUtils.mjs.map +1 -1
  173. package/dist/utils/BrowserStringUtils.mjs +1 -1
  174. package/dist/utils/BrowserStringUtils.mjs.map +1 -1
  175. package/dist/utils/BrowserUtils.d.ts +0 -9
  176. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  177. package/dist/utils/BrowserUtils.mjs +8 -33
  178. package/dist/utils/BrowserUtils.mjs.map +1 -1
  179. package/lib/msal-browser.cjs +8729 -9566
  180. package/lib/msal-browser.cjs.map +1 -1
  181. package/lib/msal-browser.js +8729 -9566
  182. package/lib/msal-browser.js.map +1 -1
  183. package/lib/msal-browser.min.js +68 -62
  184. package/package.json +7 -5
  185. package/src/app/IPublicClientApplication.ts +236 -0
  186. package/src/app/PublicClientApplication.ts +417 -0
  187. package/src/broker/nativeBroker/NativeMessageHandler.ts +416 -0
  188. package/src/broker/nativeBroker/NativeRequest.ts +52 -0
  189. package/src/broker/nativeBroker/NativeResponse.ts +56 -0
  190. package/src/broker/nativeBroker/NativeStatusCodes.ts +13 -0
  191. package/src/cache/AsyncMemoryStorage.ts +158 -0
  192. package/src/cache/BrowserCacheManager.ts +2009 -0
  193. package/src/cache/BrowserStorage.ts +52 -0
  194. package/src/cache/CryptoKeyStore.ts +63 -0
  195. package/src/cache/DatabaseStorage.ts +287 -0
  196. package/src/cache/IAsyncMemoryStorage.ts +36 -0
  197. package/src/cache/ITokenCache.ts +21 -0
  198. package/src/cache/IWindowStorage.ts +36 -0
  199. package/src/cache/MemoryStorage.ts +42 -0
  200. package/src/cache/TokenCache.ts +484 -0
  201. package/src/config/Configuration.ts +383 -0
  202. package/src/controllers/ControllerFactory.ts +55 -0
  203. package/src/controllers/IController.ts +134 -0
  204. package/src/controllers/StandardController.ts +2170 -0
  205. package/src/crypto/BrowserCrypto.ts +151 -0
  206. package/src/crypto/CryptoOps.ts +235 -0
  207. package/src/crypto/PkceGenerator.ts +115 -0
  208. package/src/crypto/SignedHttpRequest.ts +76 -0
  209. package/src/encode/Base64Decode.ts +46 -0
  210. package/src/encode/Base64Encode.ts +52 -0
  211. package/src/error/BrowserAuthError.ts +352 -0
  212. package/src/error/BrowserAuthErrorCodes.ts +57 -0
  213. package/src/error/BrowserConfigurationAuthError.ts +64 -0
  214. package/src/error/BrowserConfigurationAuthErrorCodes.ts +9 -0
  215. package/src/error/NativeAuthError.ts +113 -0
  216. package/src/error/NativeAuthErrorCodes.ts +7 -0
  217. package/src/event/EventHandler.ts +177 -0
  218. package/src/event/EventMessage.ts +125 -0
  219. package/src/event/EventType.ts +33 -0
  220. package/src/index.ts +157 -0
  221. package/src/interaction_client/BaseInteractionClient.ts +307 -0
  222. package/src/interaction_client/HybridSpaAuthorizationCodeClient.ts +16 -0
  223. package/src/interaction_client/NativeInteractionClient.ts +925 -0
  224. package/src/interaction_client/PopupClient.ts +926 -0
  225. package/src/interaction_client/RedirectClient.ts +616 -0
  226. package/src/interaction_client/SilentAuthCodeClient.ts +165 -0
  227. package/src/interaction_client/SilentCacheClient.ts +125 -0
  228. package/src/interaction_client/SilentIframeClient.ts +301 -0
  229. package/src/interaction_client/SilentRefreshClient.ts +118 -0
  230. package/src/interaction_client/StandardInteractionClient.ts +450 -0
  231. package/src/interaction_handler/InteractionHandler.ts +251 -0
  232. package/src/interaction_handler/RedirectHandler.ts +229 -0
  233. package/src/interaction_handler/SilentHandler.ts +269 -0
  234. package/src/navigation/INavigationClient.ts +23 -0
  235. package/src/navigation/NavigationClient.ts +55 -0
  236. package/src/navigation/NavigationOptions.ts +18 -0
  237. package/src/network/FetchClient.ts +130 -0
  238. package/src/operatingcontext/BaseOperatingContext.ts +82 -0
  239. package/src/operatingcontext/StandardOperatingContext.ts +49 -0
  240. package/src/operatingcontext/TeamsAppOperatingContext.ts +48 -0
  241. package/src/packageMetadata.ts +3 -0
  242. package/src/request/AuthorizationCodeRequest.ts +19 -0
  243. package/src/request/AuthorizationUrlRequest.ts +17 -0
  244. package/src/request/ClearCacheRequest.ts +16 -0
  245. package/src/request/EndSessionPopupRequest.ts +26 -0
  246. package/src/request/EndSessionRequest.ts +23 -0
  247. package/src/request/PopupRequest.ts +51 -0
  248. package/src/request/PopupWindowAttributes.ts +22 -0
  249. package/src/request/RedirectRequest.ts +51 -0
  250. package/src/request/SilentRequest.ts +49 -0
  251. package/src/request/SsoSilentRequest.ts +44 -0
  252. package/src/response/AuthenticationResult.ts +13 -0
  253. package/src/telemetry/BrowserPerformanceClient.ts +226 -0
  254. package/src/telemetry/BrowserPerformanceMeasurement.ts +144 -0
  255. package/src/utils/BrowserConstants.ts +241 -0
  256. package/src/utils/BrowserProtocolUtils.ts +58 -0
  257. package/src/utils/BrowserStringUtils.ts +143 -0
  258. package/src/utils/BrowserUtils.ts +156 -0
  259. package/dist/crypto/GuidGenerator.d.ts +0 -13
  260. package/dist/crypto/GuidGenerator.d.ts.map +0 -1
  261. package/dist/crypto/GuidGenerator.mjs +0 -104
  262. package/dist/crypto/GuidGenerator.mjs.map +0 -1
  263. package/dist/crypto/ISubtleCrypto.d.ts +0 -10
  264. package/dist/crypto/ISubtleCrypto.d.ts.map +0 -1
  265. package/dist/crypto/ModernBrowserCrypto.d.ts +0 -10
  266. package/dist/crypto/ModernBrowserCrypto.d.ts.map +0 -1
  267. package/dist/crypto/ModernBrowserCrypto.mjs +0 -31
  268. package/dist/crypto/ModernBrowserCrypto.mjs.map +0 -1
  269. package/dist/internals.d.ts +0 -23
  270. package/dist/internals.d.ts.map +0 -1
  271. package/dist/internals.mjs +0 -28
  272. package/dist/internals.mjs.map +0 -1
  273. package/dist/network/XhrClient.d.ts +0 -41
  274. package/dist/network/XhrClient.d.ts.map +0 -1
  275. package/dist/network/XhrClient.mjs +0 -125
  276. package/dist/network/XhrClient.mjs.map +0 -1
  277. package/dist/utils/MathUtils.d.ts +0 -12
  278. package/dist/utils/MathUtils.d.ts.map +0 -1
  279. package/dist/utils/MathUtils.mjs +0 -26
  280. package/dist/utils/MathUtils.mjs.map +0 -1
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/AzureAD/microsoft-authentication-library-for-js.git"
12
12
  },
13
- "version": "3.0.2",
13
+ "version": "3.2.0",
14
14
  "description": "Microsoft Authentication Library for js",
15
15
  "keywords": [
16
16
  "implicit",
@@ -52,13 +52,14 @@
52
52
  "lib/msal-browser.js.map",
53
53
  "lib/msal-browser.cjs",
54
54
  "lib/msal-browser.cjs.map",
55
- "lib/msal-browser.min.js"
55
+ "lib/msal-browser.min.js",
56
+ "src"
56
57
  ],
57
58
  "scripts": {
58
59
  "clean": "shx rm -rf dist lib",
59
60
  "clean:coverage": "rimraf ../../.nyc_output/*",
60
- "lint": "cd ../../ && npm run lint:browser",
61
- "lint:fix": "npm run lint -- -- --fix",
61
+ "lint": "eslint src --ext .ts",
62
+ "lint:fix": "npm run lint -- --fix",
62
63
  "test": "jest",
63
64
  "test:coverage": "jest --coverage",
64
65
  "test:coverage:only": "npm run clean:coverage && npm run test:coverage",
@@ -84,6 +85,7 @@
84
85
  "@types/node": "^20.3.1",
85
86
  "@types/sinon": "^7.5.0",
86
87
  "dotenv": "^8.2.0",
88
+ "eslint-config-msal": "^0.0.0",
87
89
  "fake-indexeddb": "^3.1.3",
88
90
  "jest": "^29.5.0",
89
91
  "jest-environment-jsdom": "^29.5.0",
@@ -98,6 +100,6 @@
98
100
  "typescript": "^4.9.5"
99
101
  },
100
102
  "dependencies": {
101
- "@azure/msal-common": "14.0.2"
103
+ "@azure/msal-common": "14.1.0"
102
104
  }
103
105
  }
@@ -0,0 +1,236 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ AccountInfo,
8
+ Logger,
9
+ PerformanceCallbackFunction,
10
+ } from "@azure/msal-common";
11
+ import { RedirectRequest } from "../request/RedirectRequest";
12
+ import { PopupRequest } from "../request/PopupRequest";
13
+ import { SilentRequest } from "../request/SilentRequest";
14
+ import { SsoSilentRequest } from "../request/SsoSilentRequest";
15
+ import { EndSessionRequest } from "../request/EndSessionRequest";
16
+ import {
17
+ BrowserConfigurationAuthErrorCodes,
18
+ createBrowserConfigurationAuthError,
19
+ } from "../error/BrowserConfigurationAuthError";
20
+ import { WrapperSKU } from "../utils/BrowserConstants";
21
+ import { INavigationClient } from "../navigation/INavigationClient";
22
+ import { EndSessionPopupRequest } from "../request/EndSessionPopupRequest";
23
+ import { ITokenCache } from "../cache/ITokenCache";
24
+ import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest";
25
+ import { BrowserConfiguration } from "../config/Configuration";
26
+ import { AuthenticationResult } from "../response/AuthenticationResult";
27
+ import { EventCallbackFunction } from "../event/EventMessage";
28
+ import { ClearCacheRequest } from "../request/ClearCacheRequest";
29
+
30
+ export interface IPublicClientApplication {
31
+ initialize(): Promise<void>;
32
+ acquireTokenPopup(request: PopupRequest): Promise<AuthenticationResult>;
33
+ acquireTokenRedirect(request: RedirectRequest): Promise<void>;
34
+ acquireTokenSilent(
35
+ silentRequest: SilentRequest
36
+ ): Promise<AuthenticationResult>;
37
+ acquireTokenByCode(
38
+ request: AuthorizationCodeRequest
39
+ ): Promise<AuthenticationResult>;
40
+ addEventCallback(callback: EventCallbackFunction): string | null;
41
+ removeEventCallback(callbackId: string): void;
42
+ addPerformanceCallback(callback: PerformanceCallbackFunction): string;
43
+ removePerformanceCallback(callbackId: string): boolean;
44
+ enableAccountStorageEvents(): void;
45
+ disableAccountStorageEvents(): void;
46
+ getAccountByHomeId(homeAccountId: string): AccountInfo | null;
47
+ getAccountByLocalId(localId: string): AccountInfo | null;
48
+ getAccountByUsername(userName: string): AccountInfo | null;
49
+ getAllAccounts(): AccountInfo[];
50
+ handleRedirectPromise(hash?: string): Promise<AuthenticationResult | null>;
51
+ loginPopup(request?: PopupRequest): Promise<AuthenticationResult>;
52
+ loginRedirect(request?: RedirectRequest): Promise<void>;
53
+ logout(logoutRequest?: EndSessionRequest): Promise<void>;
54
+ logoutRedirect(logoutRequest?: EndSessionRequest): Promise<void>;
55
+ logoutPopup(logoutRequest?: EndSessionPopupRequest): Promise<void>;
56
+ ssoSilent(request: SsoSilentRequest): Promise<AuthenticationResult>;
57
+ getTokenCache(): ITokenCache;
58
+ getLogger(): Logger;
59
+ setLogger(logger: Logger): void;
60
+ setActiveAccount(account: AccountInfo | null): void;
61
+ getActiveAccount(): AccountInfo | null;
62
+ initializeWrapperLibrary(sku: WrapperSKU, version: string): void;
63
+ setNavigationClient(navigationClient: INavigationClient): void;
64
+ /** @internal */
65
+ getConfiguration(): BrowserConfiguration;
66
+ hydrateCache(
67
+ result: AuthenticationResult,
68
+ request:
69
+ | SilentRequest
70
+ | SsoSilentRequest
71
+ | RedirectRequest
72
+ | PopupRequest
73
+ ): Promise<void>;
74
+ clearCache(logoutRequest?: ClearCacheRequest): Promise<void>;
75
+ }
76
+
77
+ export const stubbedPublicClientApplication: IPublicClientApplication = {
78
+ initialize: () => {
79
+ return Promise.reject(
80
+ createBrowserConfigurationAuthError(
81
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
82
+ )
83
+ );
84
+ },
85
+ acquireTokenPopup: () => {
86
+ return Promise.reject(
87
+ createBrowserConfigurationAuthError(
88
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
89
+ )
90
+ );
91
+ },
92
+ acquireTokenRedirect: () => {
93
+ return Promise.reject(
94
+ createBrowserConfigurationAuthError(
95
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
96
+ )
97
+ );
98
+ },
99
+ acquireTokenSilent: () => {
100
+ return Promise.reject(
101
+ createBrowserConfigurationAuthError(
102
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
103
+ )
104
+ );
105
+ },
106
+ acquireTokenByCode: () => {
107
+ return Promise.reject(
108
+ createBrowserConfigurationAuthError(
109
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
110
+ )
111
+ );
112
+ },
113
+ getAllAccounts: () => {
114
+ return [];
115
+ },
116
+ getAccountByHomeId: () => {
117
+ return null;
118
+ },
119
+ getAccountByUsername: () => {
120
+ return null;
121
+ },
122
+ getAccountByLocalId: () => {
123
+ return null;
124
+ },
125
+ handleRedirectPromise: () => {
126
+ return Promise.reject(
127
+ createBrowserConfigurationAuthError(
128
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
129
+ )
130
+ );
131
+ },
132
+ loginPopup: () => {
133
+ return Promise.reject(
134
+ createBrowserConfigurationAuthError(
135
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
136
+ )
137
+ );
138
+ },
139
+ loginRedirect: () => {
140
+ return Promise.reject(
141
+ createBrowserConfigurationAuthError(
142
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
143
+ )
144
+ );
145
+ },
146
+ logout: () => {
147
+ return Promise.reject(
148
+ createBrowserConfigurationAuthError(
149
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
150
+ )
151
+ );
152
+ },
153
+ logoutRedirect: () => {
154
+ return Promise.reject(
155
+ createBrowserConfigurationAuthError(
156
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
157
+ )
158
+ );
159
+ },
160
+ logoutPopup: () => {
161
+ return Promise.reject(
162
+ createBrowserConfigurationAuthError(
163
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
164
+ )
165
+ );
166
+ },
167
+ ssoSilent: () => {
168
+ return Promise.reject(
169
+ createBrowserConfigurationAuthError(
170
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
171
+ )
172
+ );
173
+ },
174
+ addEventCallback: () => {
175
+ return null;
176
+ },
177
+ removeEventCallback: () => {
178
+ return;
179
+ },
180
+ addPerformanceCallback: () => {
181
+ return "";
182
+ },
183
+ removePerformanceCallback: () => {
184
+ return false;
185
+ },
186
+ enableAccountStorageEvents: () => {
187
+ return;
188
+ },
189
+ disableAccountStorageEvents: () => {
190
+ return;
191
+ },
192
+ getTokenCache: () => {
193
+ throw createBrowserConfigurationAuthError(
194
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
195
+ );
196
+ },
197
+ getLogger: () => {
198
+ throw createBrowserConfigurationAuthError(
199
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
200
+ );
201
+ },
202
+ setLogger: () => {
203
+ return;
204
+ },
205
+ setActiveAccount: () => {
206
+ return;
207
+ },
208
+ getActiveAccount: () => {
209
+ return null;
210
+ },
211
+ initializeWrapperLibrary: () => {
212
+ return;
213
+ },
214
+ setNavigationClient: () => {
215
+ return;
216
+ },
217
+ getConfiguration: () => {
218
+ throw createBrowserConfigurationAuthError(
219
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
220
+ );
221
+ },
222
+ hydrateCache: () => {
223
+ return Promise.reject(
224
+ createBrowserConfigurationAuthError(
225
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
226
+ )
227
+ );
228
+ },
229
+ clearCache: () => {
230
+ return Promise.reject(
231
+ createBrowserConfigurationAuthError(
232
+ BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
233
+ )
234
+ );
235
+ },
236
+ };
@@ -0,0 +1,417 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ITokenCache } from "../cache/ITokenCache";
7
+ import { INavigationClient } from "../navigation/INavigationClient";
8
+ import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest";
9
+ import { PopupRequest } from "../request/PopupRequest";
10
+ import { RedirectRequest } from "../request/RedirectRequest";
11
+ import { SilentRequest } from "../request/SilentRequest";
12
+ import { WrapperSKU } from "../utils/BrowserConstants";
13
+ import { IPublicClientApplication } from "./IPublicClientApplication";
14
+ import { IController } from "../controllers/IController";
15
+ import {
16
+ PerformanceCallbackFunction,
17
+ AccountInfo,
18
+ AccountFilter,
19
+ Logger,
20
+ } from "@azure/msal-common";
21
+ import { EndSessionRequest } from "../request/EndSessionRequest";
22
+ import { SsoSilentRequest } from "../request/SsoSilentRequest";
23
+ import { ControllerFactory } from "../controllers/ControllerFactory";
24
+ import { StandardController } from "../controllers/StandardController";
25
+ import { BrowserConfiguration, Configuration } from "../config/Configuration";
26
+ import { StandardOperatingContext } from "../operatingcontext/StandardOperatingContext";
27
+ import { AuthenticationResult } from "../response/AuthenticationResult";
28
+ import { EventCallbackFunction } from "../event/EventMessage";
29
+ import { ClearCacheRequest } from "../request/ClearCacheRequest";
30
+
31
+ /**
32
+ * The PublicClientApplication class is the object exposed by the library to perform authentication and authorization functions in Single Page Applications
33
+ * to obtain JWT tokens as described in the OAuth 2.0 Authorization Code Flow with PKCE specification.
34
+ */
35
+ export class PublicClientApplication implements IPublicClientApplication {
36
+ protected controller: IController;
37
+
38
+ public static async createPublicClientApplication(
39
+ configuration: Configuration
40
+ ): Promise<IPublicClientApplication> {
41
+ const factory = new ControllerFactory(configuration);
42
+ const controller = await factory.createController();
43
+ const pca = new PublicClientApplication(configuration, controller);
44
+
45
+ return pca;
46
+ }
47
+
48
+ /**
49
+ * @constructor
50
+ * Constructor for the PublicClientApplication used to instantiate the PublicClientApplication object
51
+ *
52
+ * Important attributes in the Configuration object for auth are:
53
+ * - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal : https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview
54
+ * - authority: the authority URL for your application.
55
+ * - redirect_uri: the uri of your application registered in the portal.
56
+ *
57
+ * In Azure AD, authority is a URL indicating the Azure active directory that MSAL uses to obtain tokens.
58
+ * It is of the form https://login.microsoftonline.com/{Enter_the_Tenant_Info_Here}
59
+ * If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
60
+ * If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
61
+ * If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
62
+ * To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
63
+ *
64
+ * In Azure B2C, authority is of the form https://{instance}/tfp/{tenant}/{policyName}/
65
+ * Full B2C functionality will be available in this library in future versions.
66
+ *
67
+ * @param configuration Object for the MSAL PublicClientApplication instance
68
+ * @param IController Optional parameter to explictly set the controller. (Will be removed when we remove public constructor)
69
+ */
70
+ public constructor(configuration: Configuration, controller?: IController) {
71
+ if (controller) {
72
+ this.controller = controller;
73
+ } else {
74
+ const standardOperatingContext = new StandardOperatingContext(
75
+ configuration
76
+ );
77
+ this.controller = new StandardController(standardOperatingContext);
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Initializer function to perform async startup tasks such as connecting to WAM extension
83
+ */
84
+ async initialize(): Promise<void> {
85
+ return this.controller.initialize();
86
+ }
87
+
88
+ /**
89
+ * Use when you want to obtain an access_token for your API via opening a popup window in the user's browser
90
+ *
91
+ * @param request
92
+ *
93
+ * @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
94
+ */
95
+ async acquireTokenPopup(
96
+ request: PopupRequest
97
+ ): Promise<AuthenticationResult> {
98
+ return this.controller.acquireTokenPopup(request);
99
+ }
100
+
101
+ /**
102
+ * Use when you want to obtain an access_token for your API by redirecting the user's browser window to the authorization endpoint. This function redirects
103
+ * the page, so any code that follows this function will not execute.
104
+ *
105
+ * IMPORTANT: It is NOT recommended to have code that is dependent on the resolution of the Promise. This function will navigate away from the current
106
+ * browser window. It currently returns a Promise in order to reflect the asynchronous nature of the code running in this function.
107
+ *
108
+ * @param request
109
+ */
110
+ acquireTokenRedirect(request: RedirectRequest): Promise<void> {
111
+ return this.controller.acquireTokenRedirect(request);
112
+ }
113
+
114
+ /**
115
+ * Silently acquire an access token for a given set of scopes. Returns currently processing promise if parallel requests are made.
116
+ *
117
+ * @param {@link (SilentRequest:type)}
118
+ * @returns {Promise.<AuthenticationResult>} - a promise that is fulfilled when this function has completed, or rejected if an error was raised. Returns the {@link AuthenticationResult} object
119
+ */
120
+ acquireTokenSilent(
121
+ silentRequest: SilentRequest
122
+ ): Promise<AuthenticationResult> {
123
+ return this.controller.acquireTokenSilent(silentRequest);
124
+ }
125
+
126
+ /**
127
+ * This function redeems an authorization code (passed as code) from the eSTS token endpoint.
128
+ * This authorization code should be acquired server-side using a confidential client to acquire a spa_code.
129
+ * This API is not indended for normal authorization code acquisition and redemption.
130
+ *
131
+ * Redemption of this authorization code will not require PKCE, as it was acquired by a confidential client.
132
+ *
133
+ * @param request {@link AuthorizationCodeRequest}
134
+ * @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
135
+ */
136
+ acquireTokenByCode(
137
+ request: AuthorizationCodeRequest
138
+ ): Promise<AuthenticationResult> {
139
+ return this.controller.acquireTokenByCode(request);
140
+ }
141
+
142
+ /**
143
+ * Adds event callbacks to array
144
+ * @param callback
145
+ */
146
+ addEventCallback(callback: EventCallbackFunction): string | null {
147
+ return this.controller.addEventCallback(callback);
148
+ }
149
+
150
+ /**
151
+ * Removes callback with provided id from callback array
152
+ * @param callbackId
153
+ */
154
+ removeEventCallback(callbackId: string): void {
155
+ return this.controller.removeEventCallback(callbackId);
156
+ }
157
+
158
+ /**
159
+ * Registers a callback to receive performance events.
160
+ *
161
+ * @param {PerformanceCallbackFunction} callback
162
+ * @returns {string}
163
+ */
164
+ addPerformanceCallback(callback: PerformanceCallbackFunction): string {
165
+ return this.controller.addPerformanceCallback(callback);
166
+ }
167
+
168
+ /**
169
+ * Removes a callback registered with addPerformanceCallback.
170
+ *
171
+ * @param {string} callbackId
172
+ * @returns {boolean}
173
+ */
174
+ removePerformanceCallback(callbackId: string): boolean {
175
+ return this.controller.removePerformanceCallback(callbackId);
176
+ }
177
+
178
+ /**
179
+ * Adds event listener that emits an event when a user account is added or removed from localstorage in a different browser tab or window
180
+ */
181
+ enableAccountStorageEvents(): void {
182
+ this.controller.enableAccountStorageEvents();
183
+ }
184
+
185
+ /**
186
+ * Removes event listener that emits an event when a user account is added or removed from localstorage in a different browser tab or window
187
+ */
188
+ disableAccountStorageEvents(): void {
189
+ this.controller.disableAccountStorageEvents();
190
+ }
191
+
192
+ /**
193
+ * Returns the first account found in the cache that matches the account filter passed in.
194
+ * @param accountFilter
195
+ * @returns The first account found in the cache matching the provided filter or null if no account could be found.
196
+ */
197
+ getAccount(accountFilter: AccountFilter): AccountInfo | null {
198
+ return this.controller.getAccount(accountFilter);
199
+ }
200
+
201
+ /**
202
+ * Returns the signed in account matching homeAccountId.
203
+ * (the account object is created at the time of successful login)
204
+ * or null when no matching account is found
205
+ * @param homeAccountId
206
+ * @returns The account object stored in MSAL
207
+ * @deprecated - Use getAccount instead
208
+ */
209
+ getAccountByHomeId(homeAccountId: string): AccountInfo | null {
210
+ return this.controller.getAccountByHomeId(homeAccountId);
211
+ }
212
+
213
+ /**
214
+ * Returns the signed in account matching localAccountId.
215
+ * (the account object is created at the time of successful login)
216
+ * or null when no matching account is found
217
+ * @param localAccountId
218
+ * @returns The account object stored in MSAL
219
+ * @deprecated - Use getAccount instead
220
+ */
221
+ getAccountByLocalId(localId: string): AccountInfo | null {
222
+ return this.controller.getAccountByLocalId(localId);
223
+ }
224
+
225
+ /**
226
+ * Returns the signed in account matching username.
227
+ * (the account object is created at the time of successful login)
228
+ * or null when no matching account is found.
229
+ * This API is provided for convenience but getAccountById should be used for best reliability
230
+ * @param userName
231
+ * @returns The account object stored in MSAL
232
+ * @deprecated - Use getAccount instead
233
+ */
234
+ getAccountByUsername(userName: string): AccountInfo | null {
235
+ return this.controller.getAccountByUsername(userName);
236
+ }
237
+
238
+ /**
239
+ * Returns all the accounts in the cache that match the optional filter. If no filter is provided, all accounts are returned.
240
+ * @param accountFilter - (Optional) filter to narrow down the accounts returned
241
+ * @returns Array of AccountInfo objects in cache
242
+ */
243
+ getAllAccounts(accountFilter?: AccountFilter): AccountInfo[] {
244
+ return this.controller.getAllAccounts(accountFilter);
245
+ }
246
+
247
+ /**
248
+ * Event handler function which allows users to fire events after the PublicClientApplication object
249
+ * has loaded during redirect flows. This should be invoked on all page loads involved in redirect
250
+ * auth flows.
251
+ * @param hash Hash to process. Defaults to the current value of window.location.hash. Only needs to be provided explicitly if the response to be handled is not contained in the current value.
252
+ * @returns Token response or null. If the return value is null, then no auth redirect was detected.
253
+ */
254
+ handleRedirectPromise(
255
+ hash?: string | undefined
256
+ ): Promise<AuthenticationResult | null> {
257
+ return this.controller.handleRedirectPromise(hash);
258
+ }
259
+
260
+ /**
261
+ * Use when initiating the login process via opening a popup window in the user's browser
262
+ *
263
+ * @param request
264
+ *
265
+ * @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
266
+ */
267
+ loginPopup(
268
+ request?: PopupRequest | undefined
269
+ ): Promise<AuthenticationResult> {
270
+ return this.controller.loginPopup(request);
271
+ }
272
+
273
+ /**
274
+ * Use when initiating the login process by redirecting the user's browser to the authorization endpoint. This function redirects the page, so
275
+ * any code that follows this function will not execute.
276
+ *
277
+ * IMPORTANT: It is NOT recommended to have code that is dependent on the resolution of the Promise. This function will navigate away from the current
278
+ * browser window. It currently returns a Promise in order to reflect the asynchronous nature of the code running in this function.
279
+ *
280
+ * @param request
281
+ */
282
+ loginRedirect(request?: RedirectRequest | undefined): Promise<void> {
283
+ return this.controller.loginRedirect(request);
284
+ }
285
+
286
+ /**
287
+ * Deprecated logout function. Use logoutRedirect or logoutPopup instead
288
+ * @param logoutRequest
289
+ * @deprecated
290
+ */
291
+ logout(logoutRequest?: EndSessionRequest): Promise<void> {
292
+ return this.controller.logout(logoutRequest);
293
+ }
294
+
295
+ /**
296
+ * Use to log out the current user, and redirect the user to the postLogoutRedirectUri.
297
+ * Default behaviour is to redirect the user to `window.location.href`.
298
+ * @param logoutRequest
299
+ */
300
+ logoutRedirect(logoutRequest?: EndSessionRequest): Promise<void> {
301
+ return this.controller.logoutRedirect(logoutRequest);
302
+ }
303
+
304
+ /**
305
+ * Clears local cache for the current user then opens a popup window prompting the user to sign-out of the server
306
+ * @param logoutRequest
307
+ */
308
+ logoutPopup(logoutRequest?: EndSessionRequest): Promise<void> {
309
+ return this.controller.logoutPopup(logoutRequest);
310
+ }
311
+
312
+ /**
313
+ * This function uses a hidden iframe to fetch an authorization code from the eSTS. There are cases where this may not work:
314
+ * - Any browser using a form of Intelligent Tracking Prevention
315
+ * - If there is not an established session with the service
316
+ *
317
+ * In these cases, the request must be done inside a popup or full frame redirect.
318
+ *
319
+ * For the cases where interaction is required, you cannot send a request with prompt=none.
320
+ *
321
+ * If your refresh token has expired, you can use this function to fetch a new set of tokens silently as long as
322
+ * you session on the server still exists.
323
+ * @param request {@link SsoSilentRequest}
324
+ *
325
+ * @returns A promise that is fulfilled when this function has completed, or rejected if an error was raised.
326
+ */
327
+ ssoSilent(request: SsoSilentRequest): Promise<AuthenticationResult> {
328
+ return this.controller.ssoSilent(request);
329
+ }
330
+
331
+ /**
332
+ * Gets the token cache for the application.
333
+ */
334
+ getTokenCache(): ITokenCache {
335
+ return this.controller.getTokenCache();
336
+ }
337
+
338
+ /**
339
+ * Returns the logger instance
340
+ */
341
+ getLogger(): Logger {
342
+ return this.controller.getLogger();
343
+ }
344
+
345
+ /**
346
+ * Replaces the default logger set in configurations with new Logger with new configurations
347
+ * @param logger Logger instance
348
+ */
349
+ setLogger(logger: Logger): void {
350
+ this.controller.setLogger(logger);
351
+ }
352
+
353
+ /**
354
+ * Sets the account to use as the active account. If no account is passed to the acquireToken APIs, then MSAL will use this active account.
355
+ * @param account
356
+ */
357
+ setActiveAccount(account: AccountInfo | null): void {
358
+ this.controller.setActiveAccount(account);
359
+ }
360
+
361
+ /**
362
+ * Gets the currently active account
363
+ */
364
+ getActiveAccount(): AccountInfo | null {
365
+ return this.controller.getActiveAccount();
366
+ }
367
+
368
+ /**
369
+ * Called by wrapper libraries (Angular & React) to set SKU and Version passed down to telemetry, logger, etc.
370
+ * @param sku
371
+ * @param version
372
+ */
373
+ initializeWrapperLibrary(sku: WrapperSKU, version: string): void {
374
+ return this.controller.initializeWrapperLibrary(sku, version);
375
+ }
376
+
377
+ /**
378
+ * Sets navigation client
379
+ * @param navigationClient
380
+ */
381
+ setNavigationClient(navigationClient: INavigationClient): void {
382
+ this.controller.setNavigationClient(navigationClient);
383
+ }
384
+
385
+ /**
386
+ * Returns the configuration object
387
+ * @internal
388
+ */
389
+ getConfiguration(): BrowserConfiguration {
390
+ return this.controller.getConfiguration();
391
+ }
392
+
393
+ /**
394
+ * Hydrates cache with the tokens and account in the AuthenticationResult object
395
+ * @param result
396
+ * @param request - The request object that was used to obtain the AuthenticationResult
397
+ * @returns
398
+ */
399
+ async hydrateCache(
400
+ result: AuthenticationResult,
401
+ request:
402
+ | SilentRequest
403
+ | SsoSilentRequest
404
+ | RedirectRequest
405
+ | PopupRequest
406
+ ): Promise<void> {
407
+ return this.controller.hydrateCache(result, request);
408
+ }
409
+
410
+ /**
411
+ * Clears tokens and account from the browser cache.
412
+ * @param logoutRequest
413
+ */
414
+ clearCache(logoutRequest?: ClearCacheRequest): Promise<void> {
415
+ return this.controller.clearCache(logoutRequest);
416
+ }
417
+ }