@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.
- package/dist/app/IPublicClientApplication.d.ts +2 -0
- package/dist/app/IPublicClientApplication.d.ts.map +1 -1
- package/dist/app/IPublicClientApplication.mjs +4 -1
- package/dist/app/IPublicClientApplication.mjs.map +1 -1
- package/dist/app/PublicClientApplication.d.ts +6 -0
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.mjs +8 -1
- package/dist/app/PublicClientApplication.mjs.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs +5 -4
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +1 -1
- package/dist/cache/AsyncMemoryStorage.mjs +4 -3
- package/dist/cache/AsyncMemoryStorage.mjs.map +1 -1
- package/dist/cache/BrowserCacheManager.d.ts +9 -2
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +54 -26
- package/dist/cache/BrowserCacheManager.mjs.map +1 -1
- package/dist/cache/BrowserStorage.mjs +1 -1
- 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 +7 -11
- 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 +3 -27
- package/dist/controllers/IController.d.ts.map +1 -1
- package/dist/controllers/StandardController.d.ts +6 -25
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +28 -52
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
- package/dist/crypto/BrowserCrypto.mjs +4 -3
- package/dist/crypto/BrowserCrypto.mjs.map +1 -1
- package/dist/crypto/CryptoOps.d.ts +0 -3
- package/dist/crypto/CryptoOps.d.ts.map +1 -1
- package/dist/crypto/CryptoOps.mjs +14 -17
- package/dist/crypto/CryptoOps.mjs.map +1 -1
- package/dist/crypto/ModernBrowserCrypto.mjs +1 -1
- package/dist/crypto/ModernBrowserCrypto.mjs.map +1 -1
- package/dist/crypto/PkceGenerator.d.ts +0 -1
- package/dist/crypto/PkceGenerator.d.ts.map +1 -1
- package/dist/crypto/PkceGenerator.mjs +8 -8
- 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 +17 -70
- 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 +54 -195
- package/dist/error/BrowserAuthError.d.ts.map +1 -1
- package/dist/error/BrowserAuthError.mjs +150 -381
- package/dist/error/BrowserAuthError.mjs.map +1 -1
- package/dist/error/BrowserAuthErrorCodes.d.ts +45 -0
- package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/BrowserAuthErrorCodes.mjs +53 -0
- package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -0
- package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
- package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
- package/dist/error/NativeAuthError.d.ts.map +1 -1
- package/dist/error/NativeAuthError.mjs +5 -4
- package/dist/error/NativeAuthError.mjs.map +1 -1
- package/dist/event/EventHandler.mjs +1 -1
- 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 +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +5 -3
- 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 +1 -1
- 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 +22 -30
- 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 +5 -4
- 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 +10 -8
- 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 +4 -3
- 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 +8 -7
- 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 +9 -9
- 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 +11 -10
- 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 +10 -9
- 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 +3 -3
- 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 +6579 -7102
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +6579 -7102
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +65 -62
- package/package.json +7 -5
- package/src/app/IPublicClientApplication.ts +199 -0
- package/src/app/PublicClientApplication.ts +405 -0
- package/src/broker/nativeBroker/NativeMessageHandler.ts +419 -0
- package/src/broker/nativeBroker/NativeRequest.ts +52 -0
- package/src/broker/nativeBroker/NativeResponse.ts +56 -0
- package/src/cache/AsyncMemoryStorage.ts +158 -0
- package/src/cache/BrowserCacheManager.ts +1994 -0
- package/src/cache/BrowserStorage.ts +54 -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 +375 -0
- package/src/controllers/ControllerFactory.ts +55 -0
- package/src/controllers/IController.ts +131 -0
- package/src/controllers/StandardController.ts +2107 -0
- package/src/crypto/BrowserCrypto.ts +135 -0
- package/src/crypto/CryptoOps.ts +247 -0
- package/src/crypto/ISubtleCrypto.ts +30 -0
- package/src/crypto/ModernBrowserCrypto.ts +69 -0
- package/src/crypto/PkceGenerator.ts +76 -0
- package/src/crypto/SignedHttpRequest.ts +76 -0
- package/src/encode/Base64Decode.ts +26 -0
- package/src/encode/Base64Encode.ts +52 -0
- package/src/error/BrowserAuthError.ts +340 -0
- package/src/error/BrowserAuthErrorCodes.ts +56 -0
- package/src/error/BrowserConfigurationAuthError.ts +133 -0
- package/src/error/NativeAuthError.ts +141 -0
- package/src/event/EventHandler.ts +176 -0
- package/src/event/EventMessage.ts +125 -0
- package/src/event/EventType.ts +33 -0
- package/src/index.ts +152 -0
- package/src/interaction_client/BaseInteractionClient.ts +301 -0
- package/src/interaction_client/HybridSpaAuthorizationCodeClient.ts +16 -0
- package/src/interaction_client/NativeInteractionClient.ts +907 -0
- package/src/interaction_client/PopupClient.ts +926 -0
- package/src/interaction_client/RedirectClient.ts +616 -0
- package/src/interaction_client/SilentAuthCodeClient.ts +163 -0
- package/src/interaction_client/SilentCacheClient.ts +133 -0
- package/src/interaction_client/SilentIframeClient.ts +301 -0
- package/src/interaction_client/SilentRefreshClient.ts +120 -0
- package/src/interaction_client/StandardInteractionClient.ts +481 -0
- package/src/interaction_handler/InteractionHandler.ts +246 -0
- package/src/interaction_handler/RedirectHandler.ts +225 -0
- package/src/interaction_handler/SilentHandler.ts +266 -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 +57 -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/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,120 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { StandardInteractionClient } from "./StandardInteractionClient";
|
|
7
|
+
import {
|
|
8
|
+
CommonSilentFlowRequest,
|
|
9
|
+
ServerTelemetryManager,
|
|
10
|
+
RefreshTokenClient,
|
|
11
|
+
AuthError,
|
|
12
|
+
AzureCloudOptions,
|
|
13
|
+
PerformanceEvents,
|
|
14
|
+
} from "@azure/msal-common";
|
|
15
|
+
import { ApiId } from "../utils/BrowserConstants";
|
|
16
|
+
import {
|
|
17
|
+
createBrowserAuthError,
|
|
18
|
+
BrowserAuthErrorCodes,
|
|
19
|
+
} from "../error/BrowserAuthError";
|
|
20
|
+
import { AuthenticationResult } from "../response/AuthenticationResult";
|
|
21
|
+
|
|
22
|
+
export class SilentRefreshClient extends StandardInteractionClient {
|
|
23
|
+
/**
|
|
24
|
+
* Exchanges the refresh token for new tokens
|
|
25
|
+
* @param request
|
|
26
|
+
*/
|
|
27
|
+
async acquireToken(
|
|
28
|
+
request: CommonSilentFlowRequest
|
|
29
|
+
): Promise<AuthenticationResult> {
|
|
30
|
+
this.performanceClient.addQueueMeasurement(
|
|
31
|
+
PerformanceEvents.SilentRefreshClientAcquireToken,
|
|
32
|
+
request.correlationId
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
this.performanceClient.setPreQueueTime(
|
|
36
|
+
PerformanceEvents.InitializeBaseRequest,
|
|
37
|
+
request.correlationId
|
|
38
|
+
);
|
|
39
|
+
const silentRequest: CommonSilentFlowRequest = {
|
|
40
|
+
...request,
|
|
41
|
+
...(await this.initializeBaseRequest(request, request.account)),
|
|
42
|
+
};
|
|
43
|
+
const acquireTokenMeasurement = this.performanceClient.startMeasurement(
|
|
44
|
+
PerformanceEvents.SilentRefreshClientAcquireToken,
|
|
45
|
+
silentRequest.correlationId
|
|
46
|
+
);
|
|
47
|
+
const serverTelemetryManager = this.initializeServerTelemetryManager(
|
|
48
|
+
ApiId.acquireTokenSilent_silentFlow
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const refreshTokenClient = await this.createRefreshTokenClient(
|
|
52
|
+
serverTelemetryManager,
|
|
53
|
+
silentRequest.authority,
|
|
54
|
+
silentRequest.azureCloudOptions
|
|
55
|
+
);
|
|
56
|
+
this.logger.verbose("Refresh token client created");
|
|
57
|
+
// Send request to renew token. Auth module will throw errors if token cannot be renewed.
|
|
58
|
+
this.performanceClient.setPreQueueTime(
|
|
59
|
+
PerformanceEvents.RefreshTokenClientAcquireTokenByRefreshToken,
|
|
60
|
+
request.correlationId
|
|
61
|
+
);
|
|
62
|
+
return refreshTokenClient
|
|
63
|
+
.acquireTokenByRefreshToken(silentRequest)
|
|
64
|
+
.then((result) => result as AuthenticationResult)
|
|
65
|
+
.then((result: AuthenticationResult) => {
|
|
66
|
+
acquireTokenMeasurement.end({
|
|
67
|
+
success: true,
|
|
68
|
+
fromCache: result.fromCache,
|
|
69
|
+
requestId: result.requestId,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return result;
|
|
73
|
+
})
|
|
74
|
+
.catch((e: AuthError) => {
|
|
75
|
+
(e as AuthError).setCorrelationId(this.correlationId);
|
|
76
|
+
serverTelemetryManager.cacheFailedRequest(e);
|
|
77
|
+
acquireTokenMeasurement.end({
|
|
78
|
+
errorCode: e.errorCode,
|
|
79
|
+
subErrorCode: e.subError,
|
|
80
|
+
success: false,
|
|
81
|
+
});
|
|
82
|
+
throw e;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Currently Unsupported
|
|
88
|
+
*/
|
|
89
|
+
logout(): Promise<void> {
|
|
90
|
+
// Synchronous so we must reject
|
|
91
|
+
return Promise.reject(
|
|
92
|
+
createBrowserAuthError(
|
|
93
|
+
BrowserAuthErrorCodes.silentLogoutUnsupported
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Creates a Refresh Client with the given authority, or the default authority.
|
|
100
|
+
* @param serverTelemetryManager
|
|
101
|
+
* @param authorityUrl
|
|
102
|
+
*/
|
|
103
|
+
protected async createRefreshTokenClient(
|
|
104
|
+
serverTelemetryManager: ServerTelemetryManager,
|
|
105
|
+
authorityUrl?: string,
|
|
106
|
+
azureCloudOptions?: AzureCloudOptions
|
|
107
|
+
): Promise<RefreshTokenClient> {
|
|
108
|
+
// Create auth module.
|
|
109
|
+
this.performanceClient.setPreQueueTime(
|
|
110
|
+
PerformanceEvents.StandardInteractionClientGetClientConfiguration,
|
|
111
|
+
this.correlationId
|
|
112
|
+
);
|
|
113
|
+
const clientConfig = await this.getClientConfiguration(
|
|
114
|
+
serverTelemetryManager,
|
|
115
|
+
authorityUrl,
|
|
116
|
+
azureCloudOptions
|
|
117
|
+
);
|
|
118
|
+
return new RefreshTokenClient(clientConfig, this.performanceClient);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ServerTelemetryManager,
|
|
8
|
+
CommonAuthorizationCodeRequest,
|
|
9
|
+
Constants,
|
|
10
|
+
AuthorizationCodeClient,
|
|
11
|
+
ClientConfiguration,
|
|
12
|
+
AuthorityOptions,
|
|
13
|
+
Authority,
|
|
14
|
+
AuthorityFactory,
|
|
15
|
+
ServerAuthorizationCodeResponse,
|
|
16
|
+
UrlString,
|
|
17
|
+
CommonEndSessionRequest,
|
|
18
|
+
ProtocolUtils,
|
|
19
|
+
ResponseMode,
|
|
20
|
+
IdTokenClaims,
|
|
21
|
+
AccountInfo,
|
|
22
|
+
AzureCloudOptions,
|
|
23
|
+
PerformanceEvents,
|
|
24
|
+
AuthError,
|
|
25
|
+
} from "@azure/msal-common";
|
|
26
|
+
import { BaseInteractionClient } from "./BaseInteractionClient";
|
|
27
|
+
import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest";
|
|
28
|
+
import { BrowserConstants, InteractionType } from "../utils/BrowserConstants";
|
|
29
|
+
import { version } from "../packageMetadata";
|
|
30
|
+
import {
|
|
31
|
+
createBrowserAuthError,
|
|
32
|
+
BrowserAuthErrorCodes,
|
|
33
|
+
} from "../error/BrowserAuthError";
|
|
34
|
+
import {
|
|
35
|
+
BrowserProtocolUtils,
|
|
36
|
+
BrowserStateObject,
|
|
37
|
+
} from "../utils/BrowserProtocolUtils";
|
|
38
|
+
import { EndSessionRequest } from "../request/EndSessionRequest";
|
|
39
|
+
import { BrowserUtils } from "../utils/BrowserUtils";
|
|
40
|
+
import { RedirectRequest } from "../request/RedirectRequest";
|
|
41
|
+
import { PopupRequest } from "../request/PopupRequest";
|
|
42
|
+
import { SsoSilentRequest } from "../request/SsoSilentRequest";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Defines the class structure and helper functions used by the "standard", non-brokered auth flows (popup, redirect, silent (RT), silent (iframe))
|
|
46
|
+
*/
|
|
47
|
+
export abstract class StandardInteractionClient extends BaseInteractionClient {
|
|
48
|
+
/**
|
|
49
|
+
* Generates an auth code request tied to the url request.
|
|
50
|
+
* @param request
|
|
51
|
+
*/
|
|
52
|
+
protected async initializeAuthorizationCodeRequest(
|
|
53
|
+
request: AuthorizationUrlRequest
|
|
54
|
+
): Promise<CommonAuthorizationCodeRequest> {
|
|
55
|
+
this.performanceClient.addQueueMeasurement(
|
|
56
|
+
PerformanceEvents.StandardInteractionClientInitializeAuthorizationCodeRequest,
|
|
57
|
+
request.correlationId
|
|
58
|
+
);
|
|
59
|
+
this.logger.verbose(
|
|
60
|
+
"initializeAuthorizationRequest called",
|
|
61
|
+
request.correlationId
|
|
62
|
+
);
|
|
63
|
+
const generatedPkceParams =
|
|
64
|
+
await this.browserCrypto.generatePkceCodes();
|
|
65
|
+
|
|
66
|
+
const authCodeRequest: CommonAuthorizationCodeRequest = {
|
|
67
|
+
...request,
|
|
68
|
+
redirectUri: request.redirectUri,
|
|
69
|
+
code: Constants.EMPTY_STRING,
|
|
70
|
+
codeVerifier: generatedPkceParams.verifier,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
request.codeChallenge = generatedPkceParams.challenge;
|
|
74
|
+
request.codeChallengeMethod = Constants.S256_CODE_CHALLENGE_METHOD;
|
|
75
|
+
|
|
76
|
+
return authCodeRequest;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Initializer for the logout request.
|
|
81
|
+
* @param logoutRequest
|
|
82
|
+
*/
|
|
83
|
+
protected initializeLogoutRequest(
|
|
84
|
+
logoutRequest?: EndSessionRequest
|
|
85
|
+
): CommonEndSessionRequest {
|
|
86
|
+
this.logger.verbose(
|
|
87
|
+
"initializeLogoutRequest called",
|
|
88
|
+
logoutRequest?.correlationId
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const validLogoutRequest: CommonEndSessionRequest = {
|
|
92
|
+
correlationId:
|
|
93
|
+
this.correlationId || this.browserCrypto.createNewGuid(),
|
|
94
|
+
...logoutRequest,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Set logout_hint to be login_hint from ID Token Claims if present
|
|
99
|
+
* and logoutHint attribute wasn't manually set in logout request
|
|
100
|
+
*/
|
|
101
|
+
if (logoutRequest) {
|
|
102
|
+
// If logoutHint isn't set and an account was passed in, try to extract logoutHint from ID Token Claims
|
|
103
|
+
if (!logoutRequest.logoutHint) {
|
|
104
|
+
if (logoutRequest.account) {
|
|
105
|
+
const logoutHint = this.getLogoutHintFromIdTokenClaims(
|
|
106
|
+
logoutRequest.account
|
|
107
|
+
);
|
|
108
|
+
if (logoutHint) {
|
|
109
|
+
this.logger.verbose(
|
|
110
|
+
"Setting logoutHint to login_hint ID Token Claim value for the account provided"
|
|
111
|
+
);
|
|
112
|
+
validLogoutRequest.logoutHint = logoutHint;
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
this.logger.verbose(
|
|
116
|
+
"logoutHint was not set and account was not passed into logout request, logoutHint will not be set"
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
this.logger.verbose(
|
|
121
|
+
"logoutHint has already been set in logoutRequest"
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
this.logger.verbose(
|
|
126
|
+
"logoutHint will not be set since no logout request was configured"
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/*
|
|
131
|
+
* Only set redirect uri if logout request isn't provided or the set uri isn't null.
|
|
132
|
+
* Otherwise, use passed uri, config, or current page.
|
|
133
|
+
*/
|
|
134
|
+
if (!logoutRequest || logoutRequest.postLogoutRedirectUri !== null) {
|
|
135
|
+
if (logoutRequest && logoutRequest.postLogoutRedirectUri) {
|
|
136
|
+
this.logger.verbose(
|
|
137
|
+
"Setting postLogoutRedirectUri to uri set on logout request",
|
|
138
|
+
validLogoutRequest.correlationId
|
|
139
|
+
);
|
|
140
|
+
validLogoutRequest.postLogoutRedirectUri =
|
|
141
|
+
UrlString.getAbsoluteUrl(
|
|
142
|
+
logoutRequest.postLogoutRedirectUri,
|
|
143
|
+
BrowserUtils.getCurrentUri()
|
|
144
|
+
);
|
|
145
|
+
} else if (this.config.auth.postLogoutRedirectUri === null) {
|
|
146
|
+
this.logger.verbose(
|
|
147
|
+
"postLogoutRedirectUri configured as null and no uri set on request, not passing post logout redirect",
|
|
148
|
+
validLogoutRequest.correlationId
|
|
149
|
+
);
|
|
150
|
+
} else if (this.config.auth.postLogoutRedirectUri) {
|
|
151
|
+
this.logger.verbose(
|
|
152
|
+
"Setting postLogoutRedirectUri to configured uri",
|
|
153
|
+
validLogoutRequest.correlationId
|
|
154
|
+
);
|
|
155
|
+
validLogoutRequest.postLogoutRedirectUri =
|
|
156
|
+
UrlString.getAbsoluteUrl(
|
|
157
|
+
this.config.auth.postLogoutRedirectUri,
|
|
158
|
+
BrowserUtils.getCurrentUri()
|
|
159
|
+
);
|
|
160
|
+
} else {
|
|
161
|
+
this.logger.verbose(
|
|
162
|
+
"Setting postLogoutRedirectUri to current page",
|
|
163
|
+
validLogoutRequest.correlationId
|
|
164
|
+
);
|
|
165
|
+
validLogoutRequest.postLogoutRedirectUri =
|
|
166
|
+
UrlString.getAbsoluteUrl(
|
|
167
|
+
BrowserUtils.getCurrentUri(),
|
|
168
|
+
BrowserUtils.getCurrentUri()
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
this.logger.verbose(
|
|
173
|
+
"postLogoutRedirectUri passed as null, not setting post logout redirect uri",
|
|
174
|
+
validLogoutRequest.correlationId
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return validLogoutRequest;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Parses login_hint ID Token Claim out of AccountInfo object to be used as
|
|
183
|
+
* logout_hint in end session request.
|
|
184
|
+
* @param account
|
|
185
|
+
*/
|
|
186
|
+
protected getLogoutHintFromIdTokenClaims(
|
|
187
|
+
account: AccountInfo
|
|
188
|
+
): string | null {
|
|
189
|
+
const idTokenClaims: IdTokenClaims | undefined = account.idTokenClaims;
|
|
190
|
+
if (idTokenClaims) {
|
|
191
|
+
if (idTokenClaims.login_hint) {
|
|
192
|
+
return idTokenClaims.login_hint;
|
|
193
|
+
} else {
|
|
194
|
+
this.logger.verbose(
|
|
195
|
+
"The ID Token Claims tied to the provided account do not contain a login_hint claim, logoutHint will not be added to logout request"
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
this.logger.verbose(
|
|
200
|
+
"The provided account does not contain ID Token Claims, logoutHint will not be added to logout request"
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Creates an Authorization Code Client with the given authority, or the default authority.
|
|
209
|
+
* @param serverTelemetryManager
|
|
210
|
+
* @param authorityUrl
|
|
211
|
+
*/
|
|
212
|
+
protected async createAuthCodeClient(
|
|
213
|
+
serverTelemetryManager: ServerTelemetryManager,
|
|
214
|
+
authorityUrl?: string,
|
|
215
|
+
requestAzureCloudOptions?: AzureCloudOptions
|
|
216
|
+
): Promise<AuthorizationCodeClient> {
|
|
217
|
+
this.performanceClient.addQueueMeasurement(
|
|
218
|
+
PerformanceEvents.StandardInteractionClientCreateAuthCodeClient,
|
|
219
|
+
this.correlationId
|
|
220
|
+
);
|
|
221
|
+
// Create auth module.
|
|
222
|
+
this.performanceClient.setPreQueueTime(
|
|
223
|
+
PerformanceEvents.StandardInteractionClientGetClientConfiguration,
|
|
224
|
+
this.correlationId
|
|
225
|
+
);
|
|
226
|
+
const clientConfig = await this.getClientConfiguration(
|
|
227
|
+
serverTelemetryManager,
|
|
228
|
+
authorityUrl,
|
|
229
|
+
requestAzureCloudOptions
|
|
230
|
+
);
|
|
231
|
+
return new AuthorizationCodeClient(
|
|
232
|
+
clientConfig,
|
|
233
|
+
this.performanceClient
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Creates a Client Configuration object with the given request authority, or the default authority.
|
|
239
|
+
* @param serverTelemetryManager
|
|
240
|
+
* @param requestAuthority
|
|
241
|
+
* @param requestCorrelationId
|
|
242
|
+
*/
|
|
243
|
+
protected async getClientConfiguration(
|
|
244
|
+
serverTelemetryManager: ServerTelemetryManager,
|
|
245
|
+
requestAuthority?: string,
|
|
246
|
+
requestAzureCloudOptions?: AzureCloudOptions
|
|
247
|
+
): Promise<ClientConfiguration> {
|
|
248
|
+
this.performanceClient.addQueueMeasurement(
|
|
249
|
+
PerformanceEvents.StandardInteractionClientGetClientConfiguration,
|
|
250
|
+
this.correlationId
|
|
251
|
+
);
|
|
252
|
+
this.logger.verbose(
|
|
253
|
+
"getClientConfiguration called",
|
|
254
|
+
this.correlationId
|
|
255
|
+
);
|
|
256
|
+
this.performanceClient.setPreQueueTime(
|
|
257
|
+
PerformanceEvents.StandardInteractionClientGetDiscoveredAuthority,
|
|
258
|
+
this.correlationId
|
|
259
|
+
);
|
|
260
|
+
const discoveredAuthority = await this.getDiscoveredAuthority(
|
|
261
|
+
requestAuthority,
|
|
262
|
+
requestAzureCloudOptions
|
|
263
|
+
);
|
|
264
|
+
const logger = this.config.system.loggerOptions;
|
|
265
|
+
|
|
266
|
+
return {
|
|
267
|
+
authOptions: {
|
|
268
|
+
clientId: this.config.auth.clientId,
|
|
269
|
+
authority: discoveredAuthority,
|
|
270
|
+
clientCapabilities: this.config.auth.clientCapabilities,
|
|
271
|
+
},
|
|
272
|
+
systemOptions: {
|
|
273
|
+
tokenRenewalOffsetSeconds:
|
|
274
|
+
this.config.system.tokenRenewalOffsetSeconds,
|
|
275
|
+
preventCorsPreflight: true,
|
|
276
|
+
},
|
|
277
|
+
loggerOptions: {
|
|
278
|
+
loggerCallback: logger.loggerCallback,
|
|
279
|
+
piiLoggingEnabled: logger.piiLoggingEnabled,
|
|
280
|
+
logLevel: logger.logLevel,
|
|
281
|
+
correlationId: this.correlationId,
|
|
282
|
+
},
|
|
283
|
+
cacheOptions: {
|
|
284
|
+
claimsBasedCachingEnabled:
|
|
285
|
+
this.config.cache.claimsBasedCachingEnabled,
|
|
286
|
+
},
|
|
287
|
+
cryptoInterface: this.browserCrypto,
|
|
288
|
+
networkInterface: this.networkClient,
|
|
289
|
+
storageInterface: this.browserStorage,
|
|
290
|
+
serverTelemetryManager: serverTelemetryManager,
|
|
291
|
+
libraryInfo: {
|
|
292
|
+
sku: BrowserConstants.MSAL_SKU,
|
|
293
|
+
version: version,
|
|
294
|
+
cpu: Constants.EMPTY_STRING,
|
|
295
|
+
os: Constants.EMPTY_STRING,
|
|
296
|
+
},
|
|
297
|
+
telemetry: this.config.telemetry,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* @param hash
|
|
303
|
+
* @param interactionType
|
|
304
|
+
*/
|
|
305
|
+
protected validateAndExtractStateFromHash(
|
|
306
|
+
serverParams: ServerAuthorizationCodeResponse,
|
|
307
|
+
interactionType: InteractionType,
|
|
308
|
+
requestCorrelationId?: string
|
|
309
|
+
): string {
|
|
310
|
+
this.logger.verbose(
|
|
311
|
+
"validateAndExtractStateFromHash called",
|
|
312
|
+
requestCorrelationId
|
|
313
|
+
);
|
|
314
|
+
if (!serverParams.state) {
|
|
315
|
+
throw createBrowserAuthError(BrowserAuthErrorCodes.noStateInHash);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const platformStateObj =
|
|
319
|
+
BrowserProtocolUtils.extractBrowserRequestState(
|
|
320
|
+
this.browserCrypto,
|
|
321
|
+
serverParams.state
|
|
322
|
+
);
|
|
323
|
+
if (!platformStateObj) {
|
|
324
|
+
throw createBrowserAuthError(
|
|
325
|
+
BrowserAuthErrorCodes.unableToParseState
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (platformStateObj.interactionType !== interactionType) {
|
|
330
|
+
throw createBrowserAuthError(
|
|
331
|
+
BrowserAuthErrorCodes.stateInteractionTypeMismatch
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
this.logger.verbose("Returning state from hash", requestCorrelationId);
|
|
336
|
+
return serverParams.state;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Used to get a discovered version of the default authority.
|
|
341
|
+
* @param requestAuthority
|
|
342
|
+
* @param requestCorrelationId
|
|
343
|
+
*/
|
|
344
|
+
protected async getDiscoveredAuthority(
|
|
345
|
+
requestAuthority?: string,
|
|
346
|
+
requestAzureCloudOptions?: AzureCloudOptions
|
|
347
|
+
): Promise<Authority> {
|
|
348
|
+
this.performanceClient.addQueueMeasurement(
|
|
349
|
+
PerformanceEvents.StandardInteractionClientGetDiscoveredAuthority,
|
|
350
|
+
this.correlationId
|
|
351
|
+
);
|
|
352
|
+
this.logger.verbose(
|
|
353
|
+
"getDiscoveredAuthority called",
|
|
354
|
+
this.correlationId
|
|
355
|
+
);
|
|
356
|
+
const getAuthorityMeasurement =
|
|
357
|
+
this.performanceClient?.startMeasurement(
|
|
358
|
+
PerformanceEvents.StandardInteractionClientGetDiscoveredAuthority,
|
|
359
|
+
this.correlationId
|
|
360
|
+
);
|
|
361
|
+
const authorityOptions: AuthorityOptions = {
|
|
362
|
+
protocolMode: this.config.auth.protocolMode,
|
|
363
|
+
OIDCOptions: this.config.auth.OIDCOptions,
|
|
364
|
+
knownAuthorities: this.config.auth.knownAuthorities,
|
|
365
|
+
cloudDiscoveryMetadata: this.config.auth.cloudDiscoveryMetadata,
|
|
366
|
+
authorityMetadata: this.config.auth.authorityMetadata,
|
|
367
|
+
skipAuthorityMetadataCache:
|
|
368
|
+
this.config.auth.skipAuthorityMetadataCache,
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
// build authority string based on auth params, precedence - azureCloudInstance + tenant >> authority
|
|
372
|
+
const userAuthority = requestAuthority
|
|
373
|
+
? requestAuthority
|
|
374
|
+
: this.config.auth.authority;
|
|
375
|
+
|
|
376
|
+
// fall back to the authority from config
|
|
377
|
+
const builtAuthority = Authority.generateAuthority(
|
|
378
|
+
userAuthority,
|
|
379
|
+
requestAzureCloudOptions || this.config.auth.azureCloudOptions
|
|
380
|
+
);
|
|
381
|
+
this.logger.verbose(
|
|
382
|
+
"Creating discovered authority with configured authority",
|
|
383
|
+
this.correlationId
|
|
384
|
+
);
|
|
385
|
+
this.performanceClient.setPreQueueTime(
|
|
386
|
+
PerformanceEvents.AuthorityFactoryCreateDiscoveredInstance,
|
|
387
|
+
this.correlationId
|
|
388
|
+
);
|
|
389
|
+
return await AuthorityFactory.createDiscoveredInstance(
|
|
390
|
+
builtAuthority,
|
|
391
|
+
this.config.system.networkClient,
|
|
392
|
+
this.browserStorage,
|
|
393
|
+
authorityOptions,
|
|
394
|
+
this.logger,
|
|
395
|
+
this.performanceClient,
|
|
396
|
+
this.correlationId
|
|
397
|
+
)
|
|
398
|
+
.then((result: Authority) => {
|
|
399
|
+
getAuthorityMeasurement.end({
|
|
400
|
+
success: true,
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
return result;
|
|
404
|
+
})
|
|
405
|
+
.catch((error: AuthError) => {
|
|
406
|
+
getAuthorityMeasurement.end({
|
|
407
|
+
errorCode: error.errorCode,
|
|
408
|
+
subErrorCode: error.subError,
|
|
409
|
+
success: false,
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
throw error;
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Helper to initialize required request parameters for interactive APIs and ssoSilent()
|
|
418
|
+
* @param request
|
|
419
|
+
* @param interactionType
|
|
420
|
+
*/
|
|
421
|
+
protected async initializeAuthorizationRequest(
|
|
422
|
+
request: RedirectRequest | PopupRequest | SsoSilentRequest,
|
|
423
|
+
interactionType: InteractionType
|
|
424
|
+
): Promise<AuthorizationUrlRequest> {
|
|
425
|
+
this.performanceClient.addQueueMeasurement(
|
|
426
|
+
PerformanceEvents.StandardInteractionClientInitializeAuthorizationRequest,
|
|
427
|
+
this.correlationId
|
|
428
|
+
);
|
|
429
|
+
this.logger.verbose(
|
|
430
|
+
"initializeAuthorizationRequest called",
|
|
431
|
+
this.correlationId
|
|
432
|
+
);
|
|
433
|
+
const redirectUri = this.getRedirectUri(request.redirectUri);
|
|
434
|
+
const browserState: BrowserStateObject = {
|
|
435
|
+
interactionType: interactionType,
|
|
436
|
+
};
|
|
437
|
+
const state = ProtocolUtils.setRequestState(
|
|
438
|
+
this.browserCrypto,
|
|
439
|
+
(request && request.state) || Constants.EMPTY_STRING,
|
|
440
|
+
browserState
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
this.performanceClient.setPreQueueTime(
|
|
444
|
+
PerformanceEvents.InitializeBaseRequest,
|
|
445
|
+
this.correlationId
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
const validatedRequest: AuthorizationUrlRequest = {
|
|
449
|
+
...(await this.initializeBaseRequest(request)),
|
|
450
|
+
redirectUri: redirectUri,
|
|
451
|
+
state: state,
|
|
452
|
+
nonce: request.nonce || this.browserCrypto.createNewGuid(),
|
|
453
|
+
responseMode: this.config.auth.OIDCOptions
|
|
454
|
+
.serverResponseType as ResponseMode,
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
const account =
|
|
458
|
+
request.account || this.browserStorage.getActiveAccount();
|
|
459
|
+
if (account) {
|
|
460
|
+
this.logger.verbose(
|
|
461
|
+
"Setting validated request account",
|
|
462
|
+
this.correlationId
|
|
463
|
+
);
|
|
464
|
+
this.logger.verbosePii(
|
|
465
|
+
`Setting validated request account: ${account.homeAccountId}`,
|
|
466
|
+
this.correlationId
|
|
467
|
+
);
|
|
468
|
+
validatedRequest.account = account;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// Check for ADAL/MSAL v1 SSO
|
|
472
|
+
if (!validatedRequest.loginHint && !account) {
|
|
473
|
+
const legacyLoginHint = this.browserStorage.getLegacyLoginHint();
|
|
474
|
+
if (legacyLoginHint) {
|
|
475
|
+
validatedRequest.loginHint = legacyLoginHint;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
return validatedRequest;
|
|
480
|
+
}
|
|
481
|
+
}
|