@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.
- package/dist/app/IPublicClientApplication.d.ts +2 -0
- package/dist/app/IPublicClientApplication.d.ts.map +1 -1
- package/dist/app/IPublicClientApplication.mjs +22 -18
- package/dist/app/IPublicClientApplication.mjs.map +1 -1
- package/dist/app/PublicClientApplication.d.ts +20 -6
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.mjs +24 -7
- package/dist/app/PublicClientApplication.mjs.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +3 -4
- package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs +17 -16
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +1 -1
- package/dist/broker/nativeBroker/NativeStatusCodes.d.ts +8 -0
- package/dist/broker/nativeBroker/NativeStatusCodes.d.ts.map +1 -0
- package/dist/broker/nativeBroker/NativeStatusCodes.mjs +16 -0
- package/dist/broker/nativeBroker/NativeStatusCodes.mjs.map +1 -0
- package/dist/cache/AsyncMemoryStorage.mjs +4 -3
- package/dist/cache/AsyncMemoryStorage.mjs.map +1 -1
- package/dist/cache/BrowserCacheManager.d.ts +10 -3
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +58 -29
- package/dist/cache/BrowserCacheManager.mjs.map +1 -1
- package/dist/cache/BrowserStorage.d.ts.map +1 -1
- package/dist/cache/BrowserStorage.mjs +7 -9
- package/dist/cache/BrowserStorage.mjs.map +1 -1
- package/dist/cache/CryptoKeyStore.mjs +1 -1
- package/dist/cache/CryptoKeyStore.mjs.map +1 -1
- package/dist/cache/DatabaseStorage.d.ts.map +1 -1
- package/dist/cache/DatabaseStorage.mjs +9 -8
- package/dist/cache/DatabaseStorage.mjs.map +1 -1
- package/dist/cache/MemoryStorage.mjs +1 -1
- package/dist/cache/MemoryStorage.mjs.map +1 -1
- package/dist/cache/TokenCache.d.ts.map +1 -1
- package/dist/cache/TokenCache.mjs +30 -30
- package/dist/cache/TokenCache.mjs.map +1 -1
- package/dist/config/Configuration.d.ts +1 -0
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +12 -16
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/controllers/ControllerFactory.mjs +1 -1
- package/dist/controllers/ControllerFactory.mjs.map +1 -1
- package/dist/controllers/IController.d.ts +5 -28
- package/dist/controllers/IController.d.ts.map +1 -1
- package/dist/controllers/StandardController.d.ts +17 -31
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +78 -83
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/crypto/BrowserCrypto.d.ts +44 -49
- package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
- package/dist/crypto/BrowserCrypto.mjs +78 -77
- package/dist/crypto/BrowserCrypto.mjs.map +1 -1
- package/dist/crypto/CryptoOps.d.ts +1 -10
- package/dist/crypto/CryptoOps.d.ts.map +1 -1
- package/dist/crypto/CryptoOps.mjs +23 -34
- package/dist/crypto/CryptoOps.mjs.map +1 -1
- package/dist/crypto/PkceGenerator.d.ts +6 -22
- package/dist/crypto/PkceGenerator.d.ts.map +1 -1
- package/dist/crypto/PkceGenerator.mjs +48 -49
- package/dist/crypto/PkceGenerator.mjs.map +1 -1
- package/dist/crypto/SignedHttpRequest.mjs +1 -1
- package/dist/crypto/SignedHttpRequest.mjs.map +1 -1
- package/dist/encode/Base64Decode.d.ts +6 -19
- package/dist/encode/Base64Decode.d.ts.map +1 -1
- package/dist/encode/Base64Decode.mjs +31 -68
- package/dist/encode/Base64Decode.mjs.map +1 -1
- package/dist/encode/Base64Encode.d.ts +15 -27
- package/dist/encode/Base64Encode.d.ts.map +1 -1
- package/dist/encode/Base64Encode.mjs +36 -75
- package/dist/encode/Base64Encode.mjs.map +1 -1
- package/dist/error/BrowserAuthError.d.ts +63 -195
- package/dist/error/BrowserAuthError.d.ts.map +1 -1
- package/dist/error/BrowserAuthError.mjs +159 -381
- package/dist/error/BrowserAuthError.mjs.map +1 -1
- package/dist/error/BrowserAuthErrorCodes.d.ts +46 -0
- package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/BrowserAuthErrorCodes.mjs +54 -0
- package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -0
- package/dist/error/BrowserConfigurationAuthError.d.ts +9 -46
- package/dist/error/BrowserConfigurationAuthError.d.ts.map +1 -1
- package/dist/error/BrowserConfigurationAuthError.mjs +20 -73
- package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
- package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts +4 -0
- package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +12 -0
- package/dist/error/BrowserConfigurationAuthErrorCodes.mjs.map +1 -0
- package/dist/error/NativeAuthError.d.ts +17 -45
- package/dist/error/NativeAuthError.d.ts.map +1 -1
- package/dist/error/NativeAuthError.mjs +49 -79
- package/dist/error/NativeAuthError.mjs.map +1 -1
- package/dist/error/NativeAuthErrorCodes.d.ts +3 -0
- package/dist/error/NativeAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/NativeAuthErrorCodes.mjs +11 -0
- package/dist/error/NativeAuthErrorCodes.mjs.map +1 -0
- package/dist/event/EventHandler.d.ts.map +1 -1
- package/dist/event/EventHandler.mjs +3 -2
- package/dist/event/EventHandler.mjs.map +1 -1
- package/dist/event/EventMessage.mjs +1 -1
- package/dist/event/EventMessage.mjs.map +1 -1
- package/dist/event/EventType.mjs +1 -1
- package/dist/event/EventType.mjs.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +8 -4
- package/dist/index.mjs.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts +2 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.mjs +7 -8
- package/dist/interaction_client/BaseInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs.map +1 -1
- package/dist/interaction_client/NativeInteractionClient.d.ts +4 -10
- package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/NativeInteractionClient.mjs +32 -38
- package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/PopupClient.d.ts.map +1 -1
- package/dist/interaction_client/PopupClient.mjs +16 -15
- package/dist/interaction_client/PopupClient.mjs.map +1 -1
- package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
- package/dist/interaction_client/RedirectClient.mjs +7 -6
- package/dist/interaction_client/RedirectClient.mjs.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.mjs +9 -11
- package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentCacheClient.d.ts +4 -2
- package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentCacheClient.mjs +19 -25
- package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
- package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentIframeClient.mjs +20 -47
- package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.mjs +11 -20
- package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
- package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/StandardInteractionClient.mjs +18 -38
- package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
- package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
- package/dist/interaction_handler/InteractionHandler.mjs +13 -16
- package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
- package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
- package/dist/interaction_handler/RedirectHandler.mjs +12 -11
- package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
- package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
- package/dist/interaction_handler/SilentHandler.mjs +11 -11
- package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
- package/dist/navigation/NavigationClient.mjs +1 -1
- package/dist/navigation/NavigationClient.mjs.map +1 -1
- package/dist/network/FetchClient.d.ts.map +1 -1
- package/dist/network/FetchClient.mjs +9 -8
- package/dist/network/FetchClient.mjs.map +1 -1
- package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
- package/dist/operatingcontext/BaseOperatingContext.mjs.map +1 -1
- package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
- package/dist/operatingcontext/StandardOperatingContext.mjs.map +1 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.mjs +1 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/packageMetadata.mjs.map +1 -1
- package/dist/request/ClearCacheRequest.d.ts +11 -0
- package/dist/request/ClearCacheRequest.d.ts.map +1 -0
- package/dist/telemetry/BrowserPerformanceClient.d.ts +2 -4
- package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/BrowserPerformanceClient.mjs +2 -6
- package/dist/telemetry/BrowserPerformanceClient.mjs.map +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.mjs.map +1 -1
- package/dist/utils/BrowserConstants.mjs +1 -1
- package/dist/utils/BrowserConstants.mjs.map +1 -1
- package/dist/utils/BrowserProtocolUtils.d.ts.map +1 -1
- package/dist/utils/BrowserProtocolUtils.mjs +4 -4
- package/dist/utils/BrowserProtocolUtils.mjs.map +1 -1
- package/dist/utils/BrowserStringUtils.mjs +1 -1
- package/dist/utils/BrowserStringUtils.mjs.map +1 -1
- package/dist/utils/BrowserUtils.d.ts +0 -9
- package/dist/utils/BrowserUtils.d.ts.map +1 -1
- package/dist/utils/BrowserUtils.mjs +8 -33
- package/dist/utils/BrowserUtils.mjs.map +1 -1
- package/lib/msal-browser.cjs +8729 -9566
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +8729 -9566
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +68 -62
- package/package.json +7 -5
- package/src/app/IPublicClientApplication.ts +236 -0
- package/src/app/PublicClientApplication.ts +417 -0
- package/src/broker/nativeBroker/NativeMessageHandler.ts +416 -0
- package/src/broker/nativeBroker/NativeRequest.ts +52 -0
- package/src/broker/nativeBroker/NativeResponse.ts +56 -0
- package/src/broker/nativeBroker/NativeStatusCodes.ts +13 -0
- package/src/cache/AsyncMemoryStorage.ts +158 -0
- package/src/cache/BrowserCacheManager.ts +2009 -0
- package/src/cache/BrowserStorage.ts +52 -0
- package/src/cache/CryptoKeyStore.ts +63 -0
- package/src/cache/DatabaseStorage.ts +287 -0
- package/src/cache/IAsyncMemoryStorage.ts +36 -0
- package/src/cache/ITokenCache.ts +21 -0
- package/src/cache/IWindowStorage.ts +36 -0
- package/src/cache/MemoryStorage.ts +42 -0
- package/src/cache/TokenCache.ts +484 -0
- package/src/config/Configuration.ts +383 -0
- package/src/controllers/ControllerFactory.ts +55 -0
- package/src/controllers/IController.ts +134 -0
- package/src/controllers/StandardController.ts +2170 -0
- package/src/crypto/BrowserCrypto.ts +151 -0
- package/src/crypto/CryptoOps.ts +235 -0
- package/src/crypto/PkceGenerator.ts +115 -0
- package/src/crypto/SignedHttpRequest.ts +76 -0
- package/src/encode/Base64Decode.ts +46 -0
- package/src/encode/Base64Encode.ts +52 -0
- package/src/error/BrowserAuthError.ts +352 -0
- package/src/error/BrowserAuthErrorCodes.ts +57 -0
- package/src/error/BrowserConfigurationAuthError.ts +64 -0
- package/src/error/BrowserConfigurationAuthErrorCodes.ts +9 -0
- package/src/error/NativeAuthError.ts +113 -0
- package/src/error/NativeAuthErrorCodes.ts +7 -0
- package/src/event/EventHandler.ts +177 -0
- package/src/event/EventMessage.ts +125 -0
- package/src/event/EventType.ts +33 -0
- package/src/index.ts +157 -0
- package/src/interaction_client/BaseInteractionClient.ts +307 -0
- package/src/interaction_client/HybridSpaAuthorizationCodeClient.ts +16 -0
- package/src/interaction_client/NativeInteractionClient.ts +925 -0
- package/src/interaction_client/PopupClient.ts +926 -0
- package/src/interaction_client/RedirectClient.ts +616 -0
- package/src/interaction_client/SilentAuthCodeClient.ts +165 -0
- package/src/interaction_client/SilentCacheClient.ts +125 -0
- package/src/interaction_client/SilentIframeClient.ts +301 -0
- package/src/interaction_client/SilentRefreshClient.ts +118 -0
- package/src/interaction_client/StandardInteractionClient.ts +450 -0
- package/src/interaction_handler/InteractionHandler.ts +251 -0
- package/src/interaction_handler/RedirectHandler.ts +229 -0
- package/src/interaction_handler/SilentHandler.ts +269 -0
- package/src/navigation/INavigationClient.ts +23 -0
- package/src/navigation/NavigationClient.ts +55 -0
- package/src/navigation/NavigationOptions.ts +18 -0
- package/src/network/FetchClient.ts +130 -0
- package/src/operatingcontext/BaseOperatingContext.ts +82 -0
- package/src/operatingcontext/StandardOperatingContext.ts +49 -0
- package/src/operatingcontext/TeamsAppOperatingContext.ts +48 -0
- package/src/packageMetadata.ts +3 -0
- package/src/request/AuthorizationCodeRequest.ts +19 -0
- package/src/request/AuthorizationUrlRequest.ts +17 -0
- package/src/request/ClearCacheRequest.ts +16 -0
- package/src/request/EndSessionPopupRequest.ts +26 -0
- package/src/request/EndSessionRequest.ts +23 -0
- package/src/request/PopupRequest.ts +51 -0
- package/src/request/PopupWindowAttributes.ts +22 -0
- package/src/request/RedirectRequest.ts +51 -0
- package/src/request/SilentRequest.ts +49 -0
- package/src/request/SsoSilentRequest.ts +44 -0
- package/src/response/AuthenticationResult.ts +13 -0
- package/src/telemetry/BrowserPerformanceClient.ts +226 -0
- package/src/telemetry/BrowserPerformanceMeasurement.ts +144 -0
- package/src/utils/BrowserConstants.ts +241 -0
- package/src/utils/BrowserProtocolUtils.ts +58 -0
- package/src/utils/BrowserStringUtils.ts +143 -0
- package/src/utils/BrowserUtils.ts +156 -0
- package/dist/crypto/GuidGenerator.d.ts +0 -13
- package/dist/crypto/GuidGenerator.d.ts.map +0 -1
- package/dist/crypto/GuidGenerator.mjs +0 -104
- package/dist/crypto/GuidGenerator.mjs.map +0 -1
- package/dist/crypto/ISubtleCrypto.d.ts +0 -10
- package/dist/crypto/ISubtleCrypto.d.ts.map +0 -1
- package/dist/crypto/ModernBrowserCrypto.d.ts +0 -10
- package/dist/crypto/ModernBrowserCrypto.d.ts.map +0 -1
- package/dist/crypto/ModernBrowserCrypto.mjs +0 -31
- package/dist/crypto/ModernBrowserCrypto.mjs.map +0 -1
- package/dist/internals.d.ts +0 -23
- package/dist/internals.d.ts.map +0 -1
- package/dist/internals.mjs +0 -28
- package/dist/internals.mjs.map +0 -1
- package/dist/network/XhrClient.d.ts +0 -41
- package/dist/network/XhrClient.d.ts.map +0 -1
- package/dist/network/XhrClient.mjs +0 -125
- package/dist/network/XhrClient.mjs.map +0 -1
- package/dist/utils/MathUtils.d.ts +0 -12
- package/dist/utils/MathUtils.d.ts.map +0 -1
- package/dist/utils/MathUtils.mjs +0 -26
- package/dist/utils/MathUtils.mjs.map +0 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ICrypto,
|
|
8
|
+
Logger,
|
|
9
|
+
AccountEntity,
|
|
10
|
+
CacheManager,
|
|
11
|
+
} from "@azure/msal-common";
|
|
12
|
+
import { InteractionType } from "../utils/BrowserConstants";
|
|
13
|
+
import {
|
|
14
|
+
EventCallbackFunction,
|
|
15
|
+
EventError,
|
|
16
|
+
EventMessage,
|
|
17
|
+
EventPayload,
|
|
18
|
+
} from "./EventMessage";
|
|
19
|
+
import { EventType } from "./EventType";
|
|
20
|
+
import { createNewGuid } from "../crypto/BrowserCrypto";
|
|
21
|
+
|
|
22
|
+
export class EventHandler {
|
|
23
|
+
// Callback for subscribing to events
|
|
24
|
+
private eventCallbacks: Map<string, EventCallbackFunction>;
|
|
25
|
+
private logger: Logger;
|
|
26
|
+
private browserCrypto: ICrypto;
|
|
27
|
+
private listeningToStorageEvents: boolean;
|
|
28
|
+
|
|
29
|
+
constructor(logger: Logger, browserCrypto: ICrypto) {
|
|
30
|
+
this.eventCallbacks = new Map();
|
|
31
|
+
this.logger = logger;
|
|
32
|
+
this.browserCrypto = browserCrypto;
|
|
33
|
+
this.listeningToStorageEvents = false;
|
|
34
|
+
this.handleAccountCacheChange =
|
|
35
|
+
this.handleAccountCacheChange.bind(this);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Adds event callbacks to array
|
|
40
|
+
* @param callback
|
|
41
|
+
*/
|
|
42
|
+
addEventCallback(callback: EventCallbackFunction): string | null {
|
|
43
|
+
if (typeof window !== "undefined") {
|
|
44
|
+
const callbackId = createNewGuid();
|
|
45
|
+
this.eventCallbacks.set(callbackId, callback);
|
|
46
|
+
this.logger.verbose(
|
|
47
|
+
`Event callback registered with id: ${callbackId}`
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return callbackId;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Removes callback with provided id from callback array
|
|
58
|
+
* @param callbackId
|
|
59
|
+
*/
|
|
60
|
+
removeEventCallback(callbackId: string): void {
|
|
61
|
+
this.eventCallbacks.delete(callbackId);
|
|
62
|
+
this.logger.verbose(`Event callback ${callbackId} removed.`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Adds event listener that emits an event when a user account is added or removed from localstorage in a different browser tab or window
|
|
67
|
+
*/
|
|
68
|
+
enableAccountStorageEvents(): void {
|
|
69
|
+
if (typeof window === "undefined") {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!this.listeningToStorageEvents) {
|
|
74
|
+
this.logger.verbose("Adding account storage listener.");
|
|
75
|
+
this.listeningToStorageEvents = true;
|
|
76
|
+
window.addEventListener("storage", this.handleAccountCacheChange);
|
|
77
|
+
} else {
|
|
78
|
+
this.logger.verbose("Account storage listener already registered.");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Removes event listener that emits an event when a user account is added or removed from localstorage in a different browser tab or window
|
|
84
|
+
*/
|
|
85
|
+
disableAccountStorageEvents(): void {
|
|
86
|
+
if (typeof window === "undefined") {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (this.listeningToStorageEvents) {
|
|
91
|
+
this.logger.verbose("Removing account storage listener.");
|
|
92
|
+
window.removeEventListener(
|
|
93
|
+
"storage",
|
|
94
|
+
this.handleAccountCacheChange
|
|
95
|
+
);
|
|
96
|
+
this.listeningToStorageEvents = false;
|
|
97
|
+
} else {
|
|
98
|
+
this.logger.verbose("No account storage listener registered.");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Emits events by calling callback with event message
|
|
104
|
+
* @param eventType
|
|
105
|
+
* @param interactionType
|
|
106
|
+
* @param payload
|
|
107
|
+
* @param error
|
|
108
|
+
*/
|
|
109
|
+
emitEvent(
|
|
110
|
+
eventType: EventType,
|
|
111
|
+
interactionType?: InteractionType,
|
|
112
|
+
payload?: EventPayload,
|
|
113
|
+
error?: EventError
|
|
114
|
+
): void {
|
|
115
|
+
if (typeof window !== "undefined") {
|
|
116
|
+
const message: EventMessage = {
|
|
117
|
+
eventType: eventType,
|
|
118
|
+
interactionType: interactionType || null,
|
|
119
|
+
payload: payload || null,
|
|
120
|
+
error: error || null,
|
|
121
|
+
timestamp: Date.now(),
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
this.logger.info(`Emitting event: ${eventType}`);
|
|
125
|
+
|
|
126
|
+
this.eventCallbacks.forEach(
|
|
127
|
+
(callback: EventCallbackFunction, callbackId: string) => {
|
|
128
|
+
this.logger.verbose(
|
|
129
|
+
`Emitting event to callback ${callbackId}: ${eventType}`
|
|
130
|
+
);
|
|
131
|
+
callback.apply(null, [message]);
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Emit account added/removed events when cached accounts are changed in a different tab or frame
|
|
139
|
+
*/
|
|
140
|
+
private handleAccountCacheChange(e: StorageEvent): void {
|
|
141
|
+
try {
|
|
142
|
+
const cacheValue = e.newValue || e.oldValue;
|
|
143
|
+
if (!cacheValue) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const parsedValue = JSON.parse(cacheValue);
|
|
147
|
+
if (
|
|
148
|
+
typeof parsedValue !== "object" ||
|
|
149
|
+
!AccountEntity.isAccountEntity(parsedValue)
|
|
150
|
+
) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const accountEntity = CacheManager.toObject<AccountEntity>(
|
|
154
|
+
new AccountEntity(),
|
|
155
|
+
parsedValue
|
|
156
|
+
);
|
|
157
|
+
const accountInfo = accountEntity.getAccountInfo();
|
|
158
|
+
if (!e.oldValue && e.newValue) {
|
|
159
|
+
this.logger.info(
|
|
160
|
+
"Account was added to cache in a different window"
|
|
161
|
+
);
|
|
162
|
+
this.emitEvent(EventType.ACCOUNT_ADDED, undefined, accountInfo);
|
|
163
|
+
} else if (!e.newValue && e.oldValue) {
|
|
164
|
+
this.logger.info(
|
|
165
|
+
"Account was removed from cache in a different window"
|
|
166
|
+
);
|
|
167
|
+
this.emitEvent(
|
|
168
|
+
EventType.ACCOUNT_REMOVED,
|
|
169
|
+
undefined,
|
|
170
|
+
accountInfo
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
} catch (e) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AuthError, AccountInfo } from "@azure/msal-common";
|
|
7
|
+
import { EventType } from "./EventType";
|
|
8
|
+
import { InteractionStatus, InteractionType } from "../utils/BrowserConstants";
|
|
9
|
+
import {
|
|
10
|
+
PopupRequest,
|
|
11
|
+
RedirectRequest,
|
|
12
|
+
SilentRequest,
|
|
13
|
+
SsoSilentRequest,
|
|
14
|
+
EndSessionRequest,
|
|
15
|
+
AuthenticationResult,
|
|
16
|
+
} from "..";
|
|
17
|
+
|
|
18
|
+
export type EventMessage = {
|
|
19
|
+
eventType: EventType;
|
|
20
|
+
interactionType: InteractionType | null;
|
|
21
|
+
payload: EventPayload;
|
|
22
|
+
error: EventError;
|
|
23
|
+
timestamp: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type PopupEvent = {
|
|
27
|
+
popupWindow: Window;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type EventPayload =
|
|
31
|
+
| AccountInfo
|
|
32
|
+
| PopupRequest
|
|
33
|
+
| RedirectRequest
|
|
34
|
+
| SilentRequest
|
|
35
|
+
| SsoSilentRequest
|
|
36
|
+
| EndSessionRequest
|
|
37
|
+
| AuthenticationResult
|
|
38
|
+
| PopupEvent
|
|
39
|
+
| null;
|
|
40
|
+
|
|
41
|
+
export type EventError = AuthError | Error | null;
|
|
42
|
+
|
|
43
|
+
export type EventCallbackFunction = (message: EventMessage) => void;
|
|
44
|
+
|
|
45
|
+
export class EventMessageUtils {
|
|
46
|
+
/**
|
|
47
|
+
* Gets interaction status from event message
|
|
48
|
+
* @param message
|
|
49
|
+
* @param currentStatus
|
|
50
|
+
*/
|
|
51
|
+
static getInteractionStatusFromEvent(
|
|
52
|
+
message: EventMessage,
|
|
53
|
+
currentStatus?: InteractionStatus
|
|
54
|
+
): InteractionStatus | null {
|
|
55
|
+
switch (message.eventType) {
|
|
56
|
+
case EventType.LOGIN_START:
|
|
57
|
+
return InteractionStatus.Login;
|
|
58
|
+
case EventType.SSO_SILENT_START:
|
|
59
|
+
return InteractionStatus.SsoSilent;
|
|
60
|
+
case EventType.ACQUIRE_TOKEN_START:
|
|
61
|
+
if (
|
|
62
|
+
message.interactionType === InteractionType.Redirect ||
|
|
63
|
+
message.interactionType === InteractionType.Popup
|
|
64
|
+
) {
|
|
65
|
+
return InteractionStatus.AcquireToken;
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
case EventType.HANDLE_REDIRECT_START:
|
|
69
|
+
return InteractionStatus.HandleRedirect;
|
|
70
|
+
case EventType.LOGOUT_START:
|
|
71
|
+
return InteractionStatus.Logout;
|
|
72
|
+
case EventType.SSO_SILENT_SUCCESS:
|
|
73
|
+
case EventType.SSO_SILENT_FAILURE:
|
|
74
|
+
if (
|
|
75
|
+
currentStatus &&
|
|
76
|
+
currentStatus !== InteractionStatus.SsoSilent
|
|
77
|
+
) {
|
|
78
|
+
// Prevent this event from clearing any status other than ssoSilent
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
return InteractionStatus.None;
|
|
82
|
+
case EventType.LOGOUT_END:
|
|
83
|
+
if (
|
|
84
|
+
currentStatus &&
|
|
85
|
+
currentStatus !== InteractionStatus.Logout
|
|
86
|
+
) {
|
|
87
|
+
// Prevent this event from clearing any status other than logout
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
return InteractionStatus.None;
|
|
91
|
+
case EventType.HANDLE_REDIRECT_END:
|
|
92
|
+
if (
|
|
93
|
+
currentStatus &&
|
|
94
|
+
currentStatus !== InteractionStatus.HandleRedirect
|
|
95
|
+
) {
|
|
96
|
+
// Prevent this event from clearing any status other than handleRedirect
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
return InteractionStatus.None;
|
|
100
|
+
case EventType.LOGIN_SUCCESS:
|
|
101
|
+
case EventType.LOGIN_FAILURE:
|
|
102
|
+
case EventType.ACQUIRE_TOKEN_SUCCESS:
|
|
103
|
+
case EventType.ACQUIRE_TOKEN_FAILURE:
|
|
104
|
+
case EventType.RESTORE_FROM_BFCACHE:
|
|
105
|
+
if (
|
|
106
|
+
message.interactionType === InteractionType.Redirect ||
|
|
107
|
+
message.interactionType === InteractionType.Popup
|
|
108
|
+
) {
|
|
109
|
+
if (
|
|
110
|
+
currentStatus &&
|
|
111
|
+
currentStatus !== InteractionStatus.Login &&
|
|
112
|
+
currentStatus !== InteractionStatus.AcquireToken
|
|
113
|
+
) {
|
|
114
|
+
// Prevent this event from clearing any status other than login or acquireToken
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
return InteractionStatus.None;
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
default:
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const EventType = {
|
|
7
|
+
INITIALIZE_START: "msal:initializeStart",
|
|
8
|
+
INITIALIZE_END: "msal:initializeEnd",
|
|
9
|
+
ACCOUNT_ADDED: "msal:accountAdded",
|
|
10
|
+
ACCOUNT_REMOVED: "msal:accountRemoved",
|
|
11
|
+
LOGIN_START: "msal:loginStart",
|
|
12
|
+
LOGIN_SUCCESS: "msal:loginSuccess",
|
|
13
|
+
LOGIN_FAILURE: "msal:loginFailure",
|
|
14
|
+
ACQUIRE_TOKEN_START: "msal:acquireTokenStart",
|
|
15
|
+
ACQUIRE_TOKEN_SUCCESS: "msal:acquireTokenSuccess",
|
|
16
|
+
ACQUIRE_TOKEN_FAILURE: "msal:acquireTokenFailure",
|
|
17
|
+
ACQUIRE_TOKEN_NETWORK_START: "msal:acquireTokenFromNetworkStart",
|
|
18
|
+
SSO_SILENT_START: "msal:ssoSilentStart",
|
|
19
|
+
SSO_SILENT_SUCCESS: "msal:ssoSilentSuccess",
|
|
20
|
+
SSO_SILENT_FAILURE: "msal:ssoSilentFailure",
|
|
21
|
+
ACQUIRE_TOKEN_BY_CODE_START: "msal:acquireTokenByCodeStart",
|
|
22
|
+
ACQUIRE_TOKEN_BY_CODE_SUCCESS: "msal:acquireTokenByCodeSuccess",
|
|
23
|
+
ACQUIRE_TOKEN_BY_CODE_FAILURE: "msal:acquireTokenByCodeFailure",
|
|
24
|
+
HANDLE_REDIRECT_START: "msal:handleRedirectStart",
|
|
25
|
+
HANDLE_REDIRECT_END: "msal:handleRedirectEnd",
|
|
26
|
+
POPUP_OPENED: "msal:popupOpened",
|
|
27
|
+
LOGOUT_START: "msal:logoutStart",
|
|
28
|
+
LOGOUT_SUCCESS: "msal:logoutSuccess",
|
|
29
|
+
LOGOUT_FAILURE: "msal:logoutFailure",
|
|
30
|
+
LOGOUT_END: "msal:logoutEnd",
|
|
31
|
+
RESTORE_FROM_BFCACHE: "msal:restoreFromBFCache",
|
|
32
|
+
} as const;
|
|
33
|
+
export type EventType = (typeof EventType)[keyof typeof EventType];
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* @module @azure/msal-browser
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Warning: This set of exports is purely intended to be used by other MSAL libraries, and should be considered potentially unstable. We strongly discourage using them directly, you do so at your own risk.
|
|
13
|
+
* Breaking changes to these APIs will be shipped under a minor version, instead of a major version.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export { PublicClientApplication } from "./app/PublicClientApplication";
|
|
17
|
+
export { IController } from "./controllers/IController";
|
|
18
|
+
export {
|
|
19
|
+
Configuration,
|
|
20
|
+
BrowserAuthOptions,
|
|
21
|
+
CacheOptions,
|
|
22
|
+
BrowserSystemOptions,
|
|
23
|
+
BrowserTelemetryOptions,
|
|
24
|
+
BrowserConfiguration,
|
|
25
|
+
DEFAULT_IFRAME_TIMEOUT_MS,
|
|
26
|
+
} from "./config/Configuration";
|
|
27
|
+
export {
|
|
28
|
+
InteractionType,
|
|
29
|
+
InteractionStatus,
|
|
30
|
+
BrowserCacheLocation,
|
|
31
|
+
WrapperSKU,
|
|
32
|
+
ApiId,
|
|
33
|
+
CacheLookupPolicy,
|
|
34
|
+
} from "./utils/BrowserConstants";
|
|
35
|
+
export { BrowserUtils } from "./utils/BrowserUtils";
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* export { IController} from "./controllers/IController";
|
|
39
|
+
* export { StandardController } from "./controllers/StandardController";
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
// Browser Errors
|
|
43
|
+
export {
|
|
44
|
+
BrowserAuthError,
|
|
45
|
+
BrowserAuthErrorMessage,
|
|
46
|
+
BrowserAuthErrorCodes,
|
|
47
|
+
} from "./error/BrowserAuthError";
|
|
48
|
+
export {
|
|
49
|
+
BrowserConfigurationAuthError,
|
|
50
|
+
BrowserConfigurationAuthErrorCodes,
|
|
51
|
+
BrowserConfigurationAuthErrorMessage,
|
|
52
|
+
} from "./error/BrowserConfigurationAuthError";
|
|
53
|
+
|
|
54
|
+
// Interfaces
|
|
55
|
+
export {
|
|
56
|
+
IPublicClientApplication,
|
|
57
|
+
stubbedPublicClientApplication,
|
|
58
|
+
} from "./app/IPublicClientApplication";
|
|
59
|
+
export { INavigationClient } from "./navigation/INavigationClient";
|
|
60
|
+
export { NavigationClient } from "./navigation/NavigationClient";
|
|
61
|
+
export { NavigationOptions } from "./navigation/NavigationOptions";
|
|
62
|
+
export { PopupRequest } from "./request/PopupRequest";
|
|
63
|
+
export { RedirectRequest } from "./request/RedirectRequest";
|
|
64
|
+
export { SilentRequest } from "./request/SilentRequest";
|
|
65
|
+
export { SsoSilentRequest } from "./request/SsoSilentRequest";
|
|
66
|
+
export { EndSessionRequest } from "./request/EndSessionRequest";
|
|
67
|
+
export { EndSessionPopupRequest } from "./request/EndSessionPopupRequest";
|
|
68
|
+
export { AuthorizationUrlRequest } from "./request/AuthorizationUrlRequest";
|
|
69
|
+
export { AuthorizationCodeRequest } from "./request/AuthorizationCodeRequest";
|
|
70
|
+
export { AuthenticationResult } from "./response/AuthenticationResult";
|
|
71
|
+
export { ClearCacheRequest } from "./request/ClearCacheRequest";
|
|
72
|
+
|
|
73
|
+
// Cache
|
|
74
|
+
export { LoadTokenOptions } from "./cache/TokenCache";
|
|
75
|
+
export { ITokenCache } from "./cache/ITokenCache";
|
|
76
|
+
|
|
77
|
+
// Storage
|
|
78
|
+
export { MemoryStorage } from "./cache/MemoryStorage";
|
|
79
|
+
export { BrowserStorage } from "./cache/BrowserStorage";
|
|
80
|
+
|
|
81
|
+
// Events
|
|
82
|
+
export {
|
|
83
|
+
EventMessage,
|
|
84
|
+
EventPayload,
|
|
85
|
+
EventError,
|
|
86
|
+
EventCallbackFunction,
|
|
87
|
+
EventMessageUtils,
|
|
88
|
+
PopupEvent,
|
|
89
|
+
} from "./event/EventMessage";
|
|
90
|
+
export { EventType } from "./event/EventType";
|
|
91
|
+
|
|
92
|
+
export {
|
|
93
|
+
SignedHttpRequest,
|
|
94
|
+
SignedHttpRequestOptions,
|
|
95
|
+
} from "./crypto/SignedHttpRequest";
|
|
96
|
+
|
|
97
|
+
export {
|
|
98
|
+
PopupWindowAttributes,
|
|
99
|
+
PopupSize,
|
|
100
|
+
PopupPosition,
|
|
101
|
+
} from "./request/PopupWindowAttributes";
|
|
102
|
+
|
|
103
|
+
// Telemetry
|
|
104
|
+
export { BrowserPerformanceClient } from "./telemetry/BrowserPerformanceClient";
|
|
105
|
+
export { BrowserPerformanceMeasurement } from "./telemetry/BrowserPerformanceMeasurement";
|
|
106
|
+
|
|
107
|
+
// Common Object Formats
|
|
108
|
+
export {
|
|
109
|
+
AuthenticationScheme,
|
|
110
|
+
// Account
|
|
111
|
+
AccountInfo,
|
|
112
|
+
AccountEntity,
|
|
113
|
+
IdTokenClaims,
|
|
114
|
+
// Error
|
|
115
|
+
AuthError,
|
|
116
|
+
AuthErrorCodes,
|
|
117
|
+
AuthErrorMessage,
|
|
118
|
+
ClientAuthError,
|
|
119
|
+
ClientAuthErrorCodes,
|
|
120
|
+
ClientAuthErrorMessage,
|
|
121
|
+
ClientConfigurationError,
|
|
122
|
+
ClientConfigurationErrorCodes,
|
|
123
|
+
ClientConfigurationErrorMessage,
|
|
124
|
+
InteractionRequiredAuthError,
|
|
125
|
+
InteractionRequiredAuthErrorCodes,
|
|
126
|
+
InteractionRequiredAuthErrorMessage,
|
|
127
|
+
ServerError,
|
|
128
|
+
// Network
|
|
129
|
+
INetworkModule,
|
|
130
|
+
NetworkResponse,
|
|
131
|
+
NetworkRequestOptions,
|
|
132
|
+
// Logger Object
|
|
133
|
+
ILoggerCallback,
|
|
134
|
+
Logger,
|
|
135
|
+
LogLevel,
|
|
136
|
+
// Protocol Mode
|
|
137
|
+
ProtocolMode,
|
|
138
|
+
ServerResponseType,
|
|
139
|
+
PromptValue,
|
|
140
|
+
// Server Response
|
|
141
|
+
ExternalTokenResponse,
|
|
142
|
+
// Utils
|
|
143
|
+
StringUtils,
|
|
144
|
+
UrlString,
|
|
145
|
+
// AzureCloudInstance enum
|
|
146
|
+
AzureCloudInstance,
|
|
147
|
+
AzureCloudOptions,
|
|
148
|
+
AuthenticationHeaderParser,
|
|
149
|
+
OIDC_DEFAULT_SCOPES,
|
|
150
|
+
PerformanceCallbackFunction,
|
|
151
|
+
PerformanceEvent,
|
|
152
|
+
PerformanceEvents,
|
|
153
|
+
// Telemetry
|
|
154
|
+
InProgressPerformanceEvent,
|
|
155
|
+
} from "@azure/msal-common";
|
|
156
|
+
|
|
157
|
+
export { version } from "./packageMetadata";
|