@azure/msal-browser 4.11.1 → 4.13.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.mjs +1 -1
- package/dist/app/PublicClientApplication.d.ts +1 -0
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.mjs +3 -2
- package/dist/app/PublicClientApplication.mjs.map +1 -1
- package/dist/app/PublicClientNext.mjs +1 -1
- package/dist/broker/nativeBroker/IPlatformAuthHandler.d.ts +12 -0
- package/dist/broker/nativeBroker/IPlatformAuthHandler.d.ts.map +1 -0
- package/dist/broker/nativeBroker/NativeStatusCodes.mjs +1 -1
- package/dist/broker/nativeBroker/PlatformAuthDOMHandler.d.ts +30 -0
- package/dist/broker/nativeBroker/PlatformAuthDOMHandler.d.ts.map +1 -0
- package/dist/broker/nativeBroker/PlatformAuthDOMHandler.mjs +143 -0
- package/dist/broker/nativeBroker/PlatformAuthDOMHandler.mjs.map +1 -0
- package/dist/broker/nativeBroker/{NativeMessageHandler.d.ts → PlatformAuthExtensionHandler.d.ts} +16 -16
- package/dist/broker/nativeBroker/PlatformAuthExtensionHandler.d.ts.map +1 -0
- package/dist/broker/nativeBroker/{NativeMessageHandler.mjs → PlatformAuthExtensionHandler.mjs} +66 -58
- package/dist/broker/nativeBroker/PlatformAuthExtensionHandler.mjs.map +1 -0
- package/dist/broker/nativeBroker/PlatformAuthProvider.d.ts +26 -0
- package/dist/broker/nativeBroker/PlatformAuthProvider.d.ts.map +1 -0
- package/dist/broker/nativeBroker/PlatformAuthProvider.mjs +108 -0
- package/dist/broker/nativeBroker/PlatformAuthProvider.mjs.map +1 -0
- package/dist/broker/nativeBroker/{NativeRequest.d.ts → PlatformAuthRequest.d.ts} +34 -3
- package/dist/broker/nativeBroker/PlatformAuthRequest.d.ts.map +1 -0
- package/dist/broker/nativeBroker/{NativeResponse.d.ts → PlatformAuthResponse.d.ts} +24 -2
- package/dist/broker/nativeBroker/PlatformAuthResponse.d.ts.map +1 -0
- package/dist/cache/AccountManager.mjs +1 -1
- package/dist/cache/AsyncMemoryStorage.mjs +1 -1
- package/dist/cache/BrowserCacheManager.d.ts +6 -2
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +29 -3
- package/dist/cache/BrowserCacheManager.mjs.map +1 -1
- package/dist/cache/CacheHelpers.mjs +1 -1
- package/dist/cache/CookieStorage.mjs +1 -1
- package/dist/cache/DatabaseStorage.mjs +1 -1
- package/dist/cache/LocalStorage.mjs +1 -1
- package/dist/cache/MemoryStorage.mjs +1 -1
- package/dist/cache/SessionStorage.mjs +1 -1
- package/dist/cache/TokenCache.mjs +1 -1
- package/dist/config/Configuration.mjs +1 -1
- package/dist/controllers/ControllerFactory.mjs +1 -1
- package/dist/controllers/IController.d.ts +1 -1
- package/dist/controllers/IController.d.ts.map +1 -1
- package/dist/controllers/NestedAppAuthController.d.ts +1 -1
- package/dist/controllers/NestedAppAuthController.d.ts.map +1 -1
- package/dist/controllers/NestedAppAuthController.mjs +4 -2
- package/dist/controllers/NestedAppAuthController.mjs.map +1 -1
- package/dist/controllers/StandardController.d.ts +4 -3
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +56 -30
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/controllers/UnknownOperatingContextController.mjs +1 -1
- package/dist/crypto/BrowserCrypto.mjs +1 -1
- package/dist/crypto/CryptoOps.mjs +1 -1
- package/dist/crypto/PkceGenerator.mjs +1 -1
- package/dist/crypto/SignedHttpRequest.mjs +1 -1
- package/dist/encode/Base64Decode.mjs +1 -1
- package/dist/encode/Base64Encode.mjs +1 -1
- package/dist/error/BrowserAuthError.mjs +1 -1
- package/dist/error/BrowserAuthErrorCodes.mjs +1 -1
- package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
- package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +1 -1
- package/dist/error/NativeAuthError.mjs +1 -1
- package/dist/error/NativeAuthErrorCodes.mjs +1 -1
- package/dist/error/NestedAppAuthError.mjs +1 -1
- package/dist/event/EventHandler.mjs +1 -1
- package/dist/event/EventMessage.d.ts +10 -1
- package/dist/event/EventMessage.d.ts.map +1 -1
- package/dist/event/EventMessage.mjs +1 -1
- package/dist/event/EventMessage.mjs.map +1 -1
- package/dist/event/EventType.d.ts +1 -0
- package/dist/event/EventType.d.ts.map +1 -1
- package/dist/event/EventType.mjs +2 -1
- package/dist/event/EventType.mjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts +3 -3
- package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.mjs +3 -3
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
- package/dist/interaction_client/{NativeInteractionClient.d.ts → PlatformAuthInteractionClient.d.ts} +21 -23
- package/dist/interaction_client/PlatformAuthInteractionClient.d.ts.map +1 -0
- package/dist/interaction_client/{NativeInteractionClient.mjs → PlatformAuthInteractionClient.mjs} +80 -111
- package/dist/interaction_client/PlatformAuthInteractionClient.mjs.map +1 -0
- package/dist/interaction_client/PopupClient.d.ts +2 -2
- package/dist/interaction_client/PopupClient.d.ts.map +1 -1
- package/dist/interaction_client/PopupClient.mjs +7 -7
- package/dist/interaction_client/PopupClient.mjs.map +1 -1
- package/dist/interaction_client/RedirectClient.d.ts +2 -2
- package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
- package/dist/interaction_client/RedirectClient.mjs +7 -8
- package/dist/interaction_client/RedirectClient.mjs.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.d.ts +2 -2
- package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.mjs +3 -3
- package/dist/interaction_client/SilentCacheClient.mjs +1 -1
- package/dist/interaction_client/SilentIframeClient.d.ts +2 -2
- package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentIframeClient.mjs +7 -8
- package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.mjs +1 -1
- package/dist/interaction_client/StandardInteractionClient.mjs +1 -1
- package/dist/interaction_handler/InteractionHandler.mjs +1 -1
- package/dist/interaction_handler/SilentHandler.mjs +1 -1
- package/dist/naa/BridgeError.mjs +1 -1
- package/dist/naa/BridgeProxy.mjs +1 -1
- package/dist/naa/BridgeStatusCode.mjs +1 -1
- package/dist/naa/mapping/NestedAppAuthAdapter.mjs +1 -1
- package/dist/navigation/NavigationClient.mjs +1 -1
- package/dist/network/FetchClient.mjs +1 -1
- package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
- package/dist/operatingcontext/NestedAppOperatingContext.mjs +1 -1
- package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
- package/dist/operatingcontext/UnknownOperatingContext.mjs +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/protocol/Authorize.d.ts +4 -4
- package/dist/protocol/Authorize.d.ts.map +1 -1
- package/dist/protocol/Authorize.mjs +10 -9
- package/dist/protocol/Authorize.mjs.map +1 -1
- package/dist/request/RequestHelpers.mjs +1 -1
- package/dist/response/ResponseHandler.mjs +1 -1
- package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
- package/dist/utils/BrowserConstants.d.ts +8 -1
- package/dist/utils/BrowserConstants.d.ts.map +1 -1
- package/dist/utils/BrowserConstants.mjs +11 -4
- package/dist/utils/BrowserConstants.mjs.map +1 -1
- package/dist/utils/BrowserProtocolUtils.mjs +1 -1
- package/dist/utils/BrowserUtils.mjs +1 -1
- package/dist/utils/MsalFrameStatsUtils.d.ts +3 -0
- package/dist/utils/MsalFrameStatsUtils.d.ts.map +1 -0
- package/dist/utils/MsalFrameStatsUtils.mjs +23 -0
- package/dist/utils/MsalFrameStatsUtils.mjs.map +1 -0
- package/lib/msal-browser.cjs +1600 -1323
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +1600 -1323
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +66 -66
- package/lib/types/app/PublicClientApplication.d.ts +1 -0
- package/lib/types/app/PublicClientApplication.d.ts.map +1 -1
- package/lib/types/broker/nativeBroker/IPlatformAuthHandler.d.ts +12 -0
- package/lib/types/broker/nativeBroker/IPlatformAuthHandler.d.ts.map +1 -0
- package/lib/types/broker/nativeBroker/PlatformAuthDOMHandler.d.ts +30 -0
- package/lib/types/broker/nativeBroker/PlatformAuthDOMHandler.d.ts.map +1 -0
- package/lib/types/broker/nativeBroker/{NativeMessageHandler.d.ts → PlatformAuthExtensionHandler.d.ts} +16 -16
- package/lib/types/broker/nativeBroker/PlatformAuthExtensionHandler.d.ts.map +1 -0
- package/lib/types/broker/nativeBroker/PlatformAuthProvider.d.ts +26 -0
- package/lib/types/broker/nativeBroker/PlatformAuthProvider.d.ts.map +1 -0
- package/lib/types/broker/nativeBroker/{NativeRequest.d.ts → PlatformAuthRequest.d.ts} +34 -3
- package/lib/types/broker/nativeBroker/PlatformAuthRequest.d.ts.map +1 -0
- package/lib/types/broker/nativeBroker/{NativeResponse.d.ts → PlatformAuthResponse.d.ts} +24 -2
- package/lib/types/broker/nativeBroker/PlatformAuthResponse.d.ts.map +1 -0
- package/lib/types/cache/BrowserCacheManager.d.ts +6 -2
- package/lib/types/cache/BrowserCacheManager.d.ts.map +1 -1
- package/lib/types/controllers/IController.d.ts +1 -1
- package/lib/types/controllers/IController.d.ts.map +1 -1
- package/lib/types/controllers/NestedAppAuthController.d.ts +1 -1
- package/lib/types/controllers/NestedAppAuthController.d.ts.map +1 -1
- package/lib/types/controllers/StandardController.d.ts +4 -3
- package/lib/types/controllers/StandardController.d.ts.map +1 -1
- package/lib/types/event/EventMessage.d.ts +10 -1
- package/lib/types/event/EventMessage.d.ts.map +1 -1
- package/lib/types/event/EventType.d.ts +1 -0
- package/lib/types/event/EventType.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/interaction_client/BaseInteractionClient.d.ts +3 -3
- package/lib/types/interaction_client/BaseInteractionClient.d.ts.map +1 -1
- package/lib/types/interaction_client/{NativeInteractionClient.d.ts → PlatformAuthInteractionClient.d.ts} +21 -23
- package/lib/types/interaction_client/PlatformAuthInteractionClient.d.ts.map +1 -0
- package/lib/types/interaction_client/PopupClient.d.ts +2 -2
- package/lib/types/interaction_client/PopupClient.d.ts.map +1 -1
- package/lib/types/interaction_client/RedirectClient.d.ts +2 -2
- package/lib/types/interaction_client/RedirectClient.d.ts.map +1 -1
- package/lib/types/interaction_client/SilentAuthCodeClient.d.ts +2 -2
- package/lib/types/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
- package/lib/types/interaction_client/SilentIframeClient.d.ts +2 -2
- package/lib/types/interaction_client/SilentIframeClient.d.ts.map +1 -1
- package/lib/types/packageMetadata.d.ts +1 -1
- package/lib/types/protocol/Authorize.d.ts +4 -4
- package/lib/types/protocol/Authorize.d.ts.map +1 -1
- package/lib/types/utils/BrowserConstants.d.ts +8 -1
- package/lib/types/utils/BrowserConstants.d.ts.map +1 -1
- package/lib/types/utils/MsalFrameStatsUtils.d.ts +3 -0
- package/lib/types/utils/MsalFrameStatsUtils.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/app/PublicClientApplication.ts +2 -1
- package/src/broker/nativeBroker/IPlatformAuthHandler.ts +17 -0
- package/src/broker/nativeBroker/PlatformAuthDOMHandler.ts +248 -0
- package/src/broker/nativeBroker/{NativeMessageHandler.ts → PlatformAuthExtensionHandler.ts} +90 -79
- package/src/broker/nativeBroker/PlatformAuthProvider.ts +164 -0
- package/src/broker/nativeBroker/{NativeRequest.ts → PlatformAuthRequest.ts} +41 -2
- package/src/broker/nativeBroker/{NativeResponse.ts → PlatformAuthResponse.ts} +25 -1
- package/src/cache/BrowserCacheManager.ts +40 -4
- package/src/controllers/IController.ts +4 -1
- package/src/controllers/NestedAppAuthController.ts +5 -1
- package/src/controllers/StandardController.ts +87 -46
- package/src/event/EventMessage.ts +11 -0
- package/src/event/EventType.ts +1 -0
- package/src/index.ts +3 -0
- package/src/interaction_client/BaseInteractionClient.ts +4 -4
- package/src/interaction_client/{NativeInteractionClient.ts → PlatformAuthInteractionClient.ts} +136 -167
- package/src/interaction_client/PopupClient.ts +8 -7
- package/src/interaction_client/RedirectClient.ts +12 -12
- package/src/interaction_client/SilentAuthCodeClient.ts +3 -3
- package/src/interaction_client/SilentIframeClient.ts +12 -12
- package/src/packageMetadata.ts +1 -1
- package/src/protocol/Authorize.ts +12 -10
- package/src/utils/BrowserConstants.ts +9 -1
- package/src/utils/MsalFrameStatsUtils.ts +32 -0
- package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +0 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +0 -1
- package/dist/broker/nativeBroker/NativeRequest.d.ts.map +0 -1
- package/dist/broker/nativeBroker/NativeResponse.d.ts.map +0 -1
- package/dist/interaction_client/NativeInteractionClient.d.ts.map +0 -1
- package/dist/interaction_client/NativeInteractionClient.mjs.map +0 -1
- package/lib/types/broker/nativeBroker/NativeMessageHandler.d.ts.map +0 -1
- package/lib/types/broker/nativeBroker/NativeRequest.d.ts.map +0 -1
- package/lib/types/broker/nativeBroker/NativeResponse.d.ts.map +0 -1
- package/lib/types/interaction_client/NativeInteractionClient.d.ts.map +0 -1
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Logger,
|
|
8
|
+
createAuthError,
|
|
9
|
+
AuthErrorCodes,
|
|
10
|
+
IPerformanceClient,
|
|
11
|
+
StringDict,
|
|
12
|
+
} from "@azure/msal-common/browser";
|
|
13
|
+
import {
|
|
14
|
+
DOMExtraParameters,
|
|
15
|
+
PlatformAuthRequest,
|
|
16
|
+
PlatformDOMTokenRequest,
|
|
17
|
+
} from "./PlatformAuthRequest.js";
|
|
18
|
+
import { PlatformAuthConstants } from "../../utils/BrowserConstants.js";
|
|
19
|
+
import {
|
|
20
|
+
PlatformAuthResponse,
|
|
21
|
+
PlatformDOMTokenResponse,
|
|
22
|
+
} from "./PlatformAuthResponse.js";
|
|
23
|
+
import { createNativeAuthError } from "../../error/NativeAuthError.js";
|
|
24
|
+
import { IPlatformAuthHandler } from "./IPlatformAuthHandler.js";
|
|
25
|
+
|
|
26
|
+
export class PlatformAuthDOMHandler implements IPlatformAuthHandler {
|
|
27
|
+
protected logger: Logger;
|
|
28
|
+
protected performanceClient: IPerformanceClient;
|
|
29
|
+
protected correlationId: string;
|
|
30
|
+
platformAuthType: string;
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
logger: Logger,
|
|
34
|
+
performanceClient: IPerformanceClient,
|
|
35
|
+
correlationId: string
|
|
36
|
+
) {
|
|
37
|
+
this.logger = logger;
|
|
38
|
+
this.performanceClient = performanceClient;
|
|
39
|
+
this.correlationId = correlationId;
|
|
40
|
+
this.platformAuthType = PlatformAuthConstants.PLATFORM_DOM_PROVIDER;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static async createProvider(
|
|
44
|
+
logger: Logger,
|
|
45
|
+
performanceClient: IPerformanceClient,
|
|
46
|
+
correlationId: string
|
|
47
|
+
): Promise<PlatformAuthDOMHandler | undefined> {
|
|
48
|
+
logger.trace("PlatformAuthDOMHandler: createProvider called");
|
|
49
|
+
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
if (window.navigator?.platformAuthentication) {
|
|
52
|
+
const supportedContracts =
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
await window.navigator.platformAuthentication.getSupportedContracts(
|
|
55
|
+
PlatformAuthConstants.MICROSOFT_ENTRA_BROKERID
|
|
56
|
+
);
|
|
57
|
+
if (
|
|
58
|
+
supportedContracts?.includes(
|
|
59
|
+
PlatformAuthConstants.PLATFORM_DOM_APIS
|
|
60
|
+
)
|
|
61
|
+
) {
|
|
62
|
+
logger.trace("Platform auth api available in DOM");
|
|
63
|
+
return new PlatformAuthDOMHandler(
|
|
64
|
+
logger,
|
|
65
|
+
performanceClient,
|
|
66
|
+
correlationId
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Returns the Id for the broker extension this handler is communicating with
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
getExtensionId(): string {
|
|
78
|
+
return PlatformAuthConstants.MICROSOFT_ENTRA_BROKERID;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getExtensionVersion(): string | undefined {
|
|
82
|
+
return "";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getExtensionName(): string | undefined {
|
|
86
|
+
return PlatformAuthConstants.DOM_API_NAME;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Send token request to platform broker via browser DOM API
|
|
91
|
+
* @param request
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
async sendMessage(
|
|
95
|
+
request: PlatformAuthRequest
|
|
96
|
+
): Promise<PlatformAuthResponse> {
|
|
97
|
+
this.logger.trace(
|
|
98
|
+
this.platformAuthType + " - Sending request to browser DOM API"
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const platformDOMRequest: PlatformDOMTokenRequest =
|
|
103
|
+
this.initializePlatformDOMRequest(request);
|
|
104
|
+
const response: object =
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
await window.navigator.platformAuthentication.executeGetToken(
|
|
107
|
+
platformDOMRequest
|
|
108
|
+
);
|
|
109
|
+
return this.validatePlatformBrokerResponse(response);
|
|
110
|
+
} catch (e) {
|
|
111
|
+
this.logger.error(
|
|
112
|
+
this.platformAuthType + " - executeGetToken DOM API error"
|
|
113
|
+
);
|
|
114
|
+
throw e;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private initializePlatformDOMRequest(
|
|
119
|
+
request: PlatformAuthRequest
|
|
120
|
+
): PlatformDOMTokenRequest {
|
|
121
|
+
this.logger.trace(
|
|
122
|
+
this.platformAuthType + " - initializeNativeDOMRequest called"
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const {
|
|
126
|
+
accountId,
|
|
127
|
+
clientId,
|
|
128
|
+
authority,
|
|
129
|
+
scope,
|
|
130
|
+
redirectUri,
|
|
131
|
+
correlationId,
|
|
132
|
+
state,
|
|
133
|
+
storeInCache,
|
|
134
|
+
embeddedClientId,
|
|
135
|
+
extraParameters,
|
|
136
|
+
...remainingProperties
|
|
137
|
+
} = request;
|
|
138
|
+
|
|
139
|
+
const validExtraParameters: DOMExtraParameters =
|
|
140
|
+
this.getDOMExtraParams(remainingProperties);
|
|
141
|
+
|
|
142
|
+
const platformDOMRequest: PlatformDOMTokenRequest = {
|
|
143
|
+
accountId: accountId,
|
|
144
|
+
brokerId: this.getExtensionId(),
|
|
145
|
+
authority: authority,
|
|
146
|
+
clientId: clientId,
|
|
147
|
+
correlationId: correlationId || this.correlationId,
|
|
148
|
+
extraParameters: { ...extraParameters, ...validExtraParameters },
|
|
149
|
+
isSecurityTokenService: false,
|
|
150
|
+
redirectUri: redirectUri,
|
|
151
|
+
scope: scope,
|
|
152
|
+
state: state,
|
|
153
|
+
storeInCache: storeInCache,
|
|
154
|
+
embeddedClientId: embeddedClientId,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return platformDOMRequest;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private validatePlatformBrokerResponse(
|
|
161
|
+
response: object
|
|
162
|
+
): PlatformAuthResponse {
|
|
163
|
+
if (response.hasOwnProperty("isSuccess")) {
|
|
164
|
+
if (
|
|
165
|
+
response.hasOwnProperty("accessToken") &&
|
|
166
|
+
response.hasOwnProperty("idToken") &&
|
|
167
|
+
response.hasOwnProperty("clientInfo") &&
|
|
168
|
+
response.hasOwnProperty("account") &&
|
|
169
|
+
response.hasOwnProperty("scopes") &&
|
|
170
|
+
response.hasOwnProperty("expiresIn")
|
|
171
|
+
) {
|
|
172
|
+
this.logger.trace(
|
|
173
|
+
this.platformAuthType +
|
|
174
|
+
" - platform broker returned successful and valid response"
|
|
175
|
+
);
|
|
176
|
+
return this.convertToPlatformBrokerResponse(
|
|
177
|
+
response as PlatformDOMTokenResponse
|
|
178
|
+
);
|
|
179
|
+
} else if (response.hasOwnProperty("error")) {
|
|
180
|
+
const errorResponse = response as PlatformDOMTokenResponse;
|
|
181
|
+
if (
|
|
182
|
+
errorResponse.isSuccess === false &&
|
|
183
|
+
errorResponse.error &&
|
|
184
|
+
errorResponse.error.code
|
|
185
|
+
) {
|
|
186
|
+
this.logger.trace(
|
|
187
|
+
this.platformAuthType +
|
|
188
|
+
" - platform broker returned error response"
|
|
189
|
+
);
|
|
190
|
+
throw createNativeAuthError(
|
|
191
|
+
errorResponse.error.code,
|
|
192
|
+
errorResponse.error.description,
|
|
193
|
+
{
|
|
194
|
+
error: parseInt(errorResponse.error.errorCode),
|
|
195
|
+
protocol_error: errorResponse.error.protocolError,
|
|
196
|
+
status: errorResponse.error.status,
|
|
197
|
+
properties: errorResponse.error.properties,
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
throw createAuthError(
|
|
204
|
+
AuthErrorCodes.unexpectedError,
|
|
205
|
+
"Response missing expected properties."
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private convertToPlatformBrokerResponse(
|
|
210
|
+
response: PlatformDOMTokenResponse
|
|
211
|
+
): PlatformAuthResponse {
|
|
212
|
+
this.logger.trace(
|
|
213
|
+
this.platformAuthType + " - convertToNativeResponse called"
|
|
214
|
+
);
|
|
215
|
+
const nativeResponse: PlatformAuthResponse = {
|
|
216
|
+
access_token: response.accessToken,
|
|
217
|
+
id_token: response.idToken,
|
|
218
|
+
client_info: response.clientInfo,
|
|
219
|
+
account: response.account,
|
|
220
|
+
expires_in: response.expiresIn,
|
|
221
|
+
scope: response.scopes,
|
|
222
|
+
state: response.state || "",
|
|
223
|
+
properties: response.properties || {},
|
|
224
|
+
extendedLifetimeToken: response.extendedLifetimeToken ?? false,
|
|
225
|
+
shr: response.proofOfPossessionPayload,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
return nativeResponse;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private getDOMExtraParams(
|
|
232
|
+
extraParameters: Record<string, unknown>
|
|
233
|
+
): DOMExtraParameters {
|
|
234
|
+
const stringifiedParams = Object.entries(extraParameters).reduce(
|
|
235
|
+
(record, [key, value]) => {
|
|
236
|
+
record[key] = String(value);
|
|
237
|
+
return record;
|
|
238
|
+
},
|
|
239
|
+
{} as StringDict
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const validExtraParams: DOMExtraParameters = {
|
|
243
|
+
...stringifiedParams,
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
return validExtraParams;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
|
|
7
|
+
PlatformAuthConstants,
|
|
8
8
|
NativeExtensionMethod,
|
|
9
9
|
} from "../../utils/BrowserConstants.js";
|
|
10
10
|
import {
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
AuthError,
|
|
13
13
|
createAuthError,
|
|
14
14
|
AuthErrorCodes,
|
|
15
|
-
AuthenticationScheme,
|
|
16
15
|
InProgressPerformanceEvent,
|
|
17
16
|
PerformanceEvents,
|
|
18
17
|
IPerformanceClient,
|
|
@@ -20,14 +19,16 @@ import {
|
|
|
20
19
|
import {
|
|
21
20
|
NativeExtensionRequest,
|
|
22
21
|
NativeExtensionRequestBody,
|
|
23
|
-
|
|
22
|
+
PlatformAuthRequest,
|
|
23
|
+
} from "./PlatformAuthRequest.js";
|
|
24
24
|
import { createNativeAuthError } from "../../error/NativeAuthError.js";
|
|
25
25
|
import {
|
|
26
26
|
createBrowserAuthError,
|
|
27
27
|
BrowserAuthErrorCodes,
|
|
28
28
|
} from "../../error/BrowserAuthError.js";
|
|
29
|
-
import { BrowserConfiguration } from "../../config/Configuration.js";
|
|
30
29
|
import { createNewGuid } from "../../crypto/BrowserCrypto.js";
|
|
30
|
+
import { PlatformAuthResponse } from "./PlatformAuthResponse.js";
|
|
31
|
+
import { IPlatformAuthHandler } from "./IPlatformAuthHandler.js";
|
|
31
32
|
|
|
32
33
|
type ResponseResolvers<T> = {
|
|
33
34
|
resolve: (value: T | PromiseLike<T>) => void;
|
|
@@ -36,7 +37,7 @@ type ResponseResolvers<T> = {
|
|
|
36
37
|
) => void;
|
|
37
38
|
};
|
|
38
39
|
|
|
39
|
-
export class
|
|
40
|
+
export class PlatformAuthExtensionHandler implements IPlatformAuthHandler {
|
|
40
41
|
private extensionId: string | undefined;
|
|
41
42
|
private extensionVersion: string | undefined;
|
|
42
43
|
private logger: Logger;
|
|
@@ -48,6 +49,7 @@ export class NativeMessageHandler {
|
|
|
48
49
|
private readonly windowListener: (event: MessageEvent) => void;
|
|
49
50
|
private readonly performanceClient: IPerformanceClient;
|
|
50
51
|
private readonly handshakeEvent: InProgressPerformanceEvent;
|
|
52
|
+
platformAuthType: string;
|
|
51
53
|
|
|
52
54
|
constructor(
|
|
53
55
|
logger: Logger,
|
|
@@ -66,34 +68,51 @@ export class NativeMessageHandler {
|
|
|
66
68
|
this.handshakeEvent = performanceClient.startMeasurement(
|
|
67
69
|
PerformanceEvents.NativeMessageHandlerHandshake
|
|
68
70
|
);
|
|
71
|
+
this.platformAuthType =
|
|
72
|
+
PlatformAuthConstants.PLATFORM_EXTENSION_PROVIDER;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
/**
|
|
72
76
|
* Sends a given message to the extension and resolves with the extension response
|
|
73
|
-
* @param
|
|
77
|
+
* @param request
|
|
74
78
|
*/
|
|
75
|
-
async sendMessage(
|
|
76
|
-
|
|
79
|
+
async sendMessage(
|
|
80
|
+
request: PlatformAuthRequest
|
|
81
|
+
): Promise<PlatformAuthResponse> {
|
|
82
|
+
this.logger.trace(this.platformAuthType + " - sendMessage called.");
|
|
83
|
+
|
|
84
|
+
// fall back to native calls
|
|
85
|
+
const messageBody: NativeExtensionRequestBody = {
|
|
86
|
+
method: NativeExtensionMethod.GetToken,
|
|
87
|
+
request: request,
|
|
88
|
+
};
|
|
89
|
+
|
|
77
90
|
const req: NativeExtensionRequest = {
|
|
78
|
-
channel:
|
|
91
|
+
channel: PlatformAuthConstants.CHANNEL_ID,
|
|
79
92
|
extensionId: this.extensionId,
|
|
80
93
|
responseId: createNewGuid(),
|
|
81
|
-
body:
|
|
94
|
+
body: messageBody,
|
|
82
95
|
};
|
|
83
96
|
|
|
84
97
|
this.logger.trace(
|
|
85
|
-
"
|
|
98
|
+
this.platformAuthType + " - Sending request to browser extension"
|
|
86
99
|
);
|
|
87
100
|
this.logger.tracePii(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
this.platformAuthType +
|
|
102
|
+
` - Sending request to browser extension: ${JSON.stringify(
|
|
103
|
+
req
|
|
104
|
+
)}`
|
|
91
105
|
);
|
|
92
106
|
this.messageChannel.port1.postMessage(req);
|
|
93
107
|
|
|
94
|
-
|
|
108
|
+
const response: object = await new Promise((resolve, reject) => {
|
|
95
109
|
this.resolvers.set(req.responseId, { resolve, reject });
|
|
96
110
|
});
|
|
111
|
+
|
|
112
|
+
const validatedResponse: PlatformAuthResponse =
|
|
113
|
+
this.validatePlatformBrokerResponse(response);
|
|
114
|
+
|
|
115
|
+
return validatedResponse;
|
|
97
116
|
}
|
|
98
117
|
|
|
99
118
|
/**
|
|
@@ -107,20 +126,21 @@ export class NativeMessageHandler {
|
|
|
107
126
|
logger: Logger,
|
|
108
127
|
handshakeTimeoutMs: number,
|
|
109
128
|
performanceClient: IPerformanceClient
|
|
110
|
-
): Promise<
|
|
111
|
-
logger.trace("
|
|
129
|
+
): Promise<PlatformAuthExtensionHandler> {
|
|
130
|
+
logger.trace("PlatformAuthExtensionHandler - createProvider called.");
|
|
131
|
+
|
|
112
132
|
try {
|
|
113
|
-
const preferredProvider = new
|
|
133
|
+
const preferredProvider = new PlatformAuthExtensionHandler(
|
|
114
134
|
logger,
|
|
115
135
|
handshakeTimeoutMs,
|
|
116
136
|
performanceClient,
|
|
117
|
-
|
|
137
|
+
PlatformAuthConstants.PREFERRED_EXTENSION_ID
|
|
118
138
|
);
|
|
119
139
|
await preferredProvider.sendHandshakeRequest();
|
|
120
140
|
return preferredProvider;
|
|
121
141
|
} catch (e) {
|
|
122
142
|
// If preferred extension fails for whatever reason, fallback to using any installed extension
|
|
123
|
-
const backupProvider = new
|
|
143
|
+
const backupProvider = new PlatformAuthExtensionHandler(
|
|
124
144
|
logger,
|
|
125
145
|
handshakeTimeoutMs,
|
|
126
146
|
performanceClient
|
|
@@ -135,13 +155,13 @@ export class NativeMessageHandler {
|
|
|
135
155
|
*/
|
|
136
156
|
private async sendHandshakeRequest(): Promise<void> {
|
|
137
157
|
this.logger.trace(
|
|
138
|
-
"
|
|
158
|
+
this.platformAuthType + " - sendHandshakeRequest called."
|
|
139
159
|
);
|
|
140
160
|
// Register this event listener before sending handshake
|
|
141
161
|
window.addEventListener("message", this.windowListener, false); // false is important, because content script message processing should work first
|
|
142
162
|
|
|
143
163
|
const req: NativeExtensionRequest = {
|
|
144
|
-
channel:
|
|
164
|
+
channel: PlatformAuthConstants.CHANNEL_ID,
|
|
145
165
|
extensionId: this.extensionId,
|
|
146
166
|
responseId: createNewGuid(),
|
|
147
167
|
body: {
|
|
@@ -192,7 +212,7 @@ export class NativeMessageHandler {
|
|
|
192
212
|
* @param event
|
|
193
213
|
*/
|
|
194
214
|
private onWindowMessage(event: MessageEvent): void {
|
|
195
|
-
this.logger.trace("
|
|
215
|
+
this.logger.trace(this.platformAuthType + " - onWindowMessage called");
|
|
196
216
|
// We only accept messages from ourselves
|
|
197
217
|
if (event.source !== window) {
|
|
198
218
|
return;
|
|
@@ -202,7 +222,7 @@ export class NativeMessageHandler {
|
|
|
202
222
|
|
|
203
223
|
if (
|
|
204
224
|
!request.channel ||
|
|
205
|
-
request.channel !==
|
|
225
|
+
request.channel !== PlatformAuthConstants.CHANNEL_ID
|
|
206
226
|
) {
|
|
207
227
|
return;
|
|
208
228
|
}
|
|
@@ -221,7 +241,8 @@ export class NativeMessageHandler {
|
|
|
221
241
|
*/
|
|
222
242
|
if (!handshakeResolver) {
|
|
223
243
|
this.logger.trace(
|
|
224
|
-
|
|
244
|
+
this.platformAuthType +
|
|
245
|
+
`.onWindowMessage - resolver can't be found for request ${request.responseId}`
|
|
225
246
|
);
|
|
226
247
|
return;
|
|
227
248
|
}
|
|
@@ -253,7 +274,9 @@ export class NativeMessageHandler {
|
|
|
253
274
|
* @param event
|
|
254
275
|
*/
|
|
255
276
|
private onChannelMessage(event: MessageEvent): void {
|
|
256
|
-
this.logger.trace(
|
|
277
|
+
this.logger.trace(
|
|
278
|
+
this.platformAuthType + " - onChannelMessage called."
|
|
279
|
+
);
|
|
257
280
|
const request = event.data;
|
|
258
281
|
|
|
259
282
|
const resolver = this.resolvers.get(request.responseId);
|
|
@@ -270,12 +293,14 @@ export class NativeMessageHandler {
|
|
|
270
293
|
}
|
|
271
294
|
const response = request.body.response;
|
|
272
295
|
this.logger.trace(
|
|
273
|
-
|
|
296
|
+
this.platformAuthType +
|
|
297
|
+
" - Received response from browser extension"
|
|
274
298
|
);
|
|
275
299
|
this.logger.tracePii(
|
|
276
|
-
|
|
277
|
-
response
|
|
278
|
-
|
|
300
|
+
this.platformAuthType +
|
|
301
|
+
` - Received response from browser extension: ${JSON.stringify(
|
|
302
|
+
response
|
|
303
|
+
)}`
|
|
279
304
|
);
|
|
280
305
|
if (response.status !== "Success") {
|
|
281
306
|
resolver.reject(
|
|
@@ -310,7 +335,8 @@ export class NativeMessageHandler {
|
|
|
310
335
|
} else if (method === NativeExtensionMethod.HandshakeResponse) {
|
|
311
336
|
if (!handshakeResolver) {
|
|
312
337
|
this.logger.trace(
|
|
313
|
-
|
|
338
|
+
this.platformAuthType +
|
|
339
|
+
`.onChannelMessage - resolver can't be found for request ${request.responseId}`
|
|
314
340
|
);
|
|
315
341
|
return;
|
|
316
342
|
}
|
|
@@ -323,7 +349,8 @@ export class NativeMessageHandler {
|
|
|
323
349
|
this.extensionId = request.extensionId;
|
|
324
350
|
this.extensionVersion = request.body.version;
|
|
325
351
|
this.logger.verbose(
|
|
326
|
-
|
|
352
|
+
this.platformAuthType +
|
|
353
|
+
` - Received HandshakeResponse from extension: ${this.extensionId}`
|
|
327
354
|
);
|
|
328
355
|
this.handshakeEvent.end({
|
|
329
356
|
extensionInstalled: true,
|
|
@@ -349,6 +376,30 @@ export class NativeMessageHandler {
|
|
|
349
376
|
}
|
|
350
377
|
}
|
|
351
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Validates native platform response before processing
|
|
381
|
+
* @param response
|
|
382
|
+
*/
|
|
383
|
+
private validatePlatformBrokerResponse(
|
|
384
|
+
response: object
|
|
385
|
+
): PlatformAuthResponse {
|
|
386
|
+
if (
|
|
387
|
+
response.hasOwnProperty("access_token") &&
|
|
388
|
+
response.hasOwnProperty("id_token") &&
|
|
389
|
+
response.hasOwnProperty("client_info") &&
|
|
390
|
+
response.hasOwnProperty("account") &&
|
|
391
|
+
response.hasOwnProperty("scope") &&
|
|
392
|
+
response.hasOwnProperty("expires_in")
|
|
393
|
+
) {
|
|
394
|
+
return response as PlatformAuthResponse;
|
|
395
|
+
} else {
|
|
396
|
+
throw createAuthError(
|
|
397
|
+
AuthErrorCodes.unexpectedError,
|
|
398
|
+
"Response missing expected properties."
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
352
403
|
/**
|
|
353
404
|
* Returns the Id for the browser extension this handler is communicating with
|
|
354
405
|
* @returns
|
|
@@ -365,52 +416,12 @@ export class NativeMessageHandler {
|
|
|
365
416
|
return this.extensionVersion;
|
|
366
417
|
}
|
|
367
418
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
static isPlatformBrokerAvailable(
|
|
376
|
-
config: BrowserConfiguration,
|
|
377
|
-
logger: Logger,
|
|
378
|
-
nativeExtensionProvider?: NativeMessageHandler,
|
|
379
|
-
authenticationScheme?: AuthenticationScheme
|
|
380
|
-
): boolean {
|
|
381
|
-
logger.trace("isPlatformBrokerAvailable called");
|
|
382
|
-
if (!config.system.allowPlatformBroker) {
|
|
383
|
-
logger.trace(
|
|
384
|
-
"isPlatformBrokerAvailable: allowPlatformBroker is not enabled, returning false"
|
|
385
|
-
);
|
|
386
|
-
// Developer disabled WAM
|
|
387
|
-
return false;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
if (!nativeExtensionProvider) {
|
|
391
|
-
logger.trace(
|
|
392
|
-
"isPlatformBrokerAvailable: Platform extension provider is not initialized, returning false"
|
|
393
|
-
);
|
|
394
|
-
// Extension is not available
|
|
395
|
-
return false;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
if (authenticationScheme) {
|
|
399
|
-
switch (authenticationScheme) {
|
|
400
|
-
case AuthenticationScheme.BEARER:
|
|
401
|
-
case AuthenticationScheme.POP:
|
|
402
|
-
logger.trace(
|
|
403
|
-
"isPlatformBrokerAvailable: authenticationScheme is supported, returning true"
|
|
404
|
-
);
|
|
405
|
-
return true;
|
|
406
|
-
default:
|
|
407
|
-
logger.trace(
|
|
408
|
-
"isPlatformBrokerAvailable: authenticationScheme is not supported, returning false"
|
|
409
|
-
);
|
|
410
|
-
return false;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return true;
|
|
419
|
+
getExtensionName(): string | undefined {
|
|
420
|
+
return this.getExtensionId() ===
|
|
421
|
+
PlatformAuthConstants.PREFERRED_EXTENSION_ID
|
|
422
|
+
? "chrome"
|
|
423
|
+
: this.getExtensionId()?.length
|
|
424
|
+
? "unknown"
|
|
425
|
+
: undefined;
|
|
415
426
|
}
|
|
416
427
|
}
|