@azure/msal-browser 3.0.2 → 3.1.0

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