@azure/msal-browser
Version:
Microsoft Authentication Library for js
135 lines (132 loc) • 5.66 kB
JavaScript
/*! @azure/msal-browser v5.6.3 2026-04-01 */
;
import { StubPerformanceClient, ProtocolMode, Logger, LogLevel, createClientConfigurationError, ClientConfigurationErrorCodes, StubbedNetworkModule, DEFAULT_SYSTEM_OPTIONS, Constants, AzureCloudInstance } from '@azure/msal-common/browser';
import { BrowserCacheLocation } from '../utils/BrowserConstants.mjs';
import { NavigationClient } from '../navigation/NavigationClient.mjs';
import { FetchClient } from '../network/FetchClient.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
// Default timeout for popup windows and iframes in milliseconds
const DEFAULT_POPUP_TIMEOUT_MS = 60000;
const DEFAULT_IFRAME_TIMEOUT_MS = 10000;
const DEFAULT_REDIRECT_TIMEOUT_MS = 30000;
const DEFAULT_NATIVE_BROKER_HANDSHAKE_TIMEOUT_MS = 2000;
/**
* MSAL function that sets the default options when not explicitly configured from app developer
*
* @param auth
* @param cache
* @param system
*
* @returns Configuration object
*/
function buildConfiguration({ auth: userInputAuth, cache: userInputCache, system: userInputSystem, experimental: userInputExperimental, telemetry: userInputTelemetry, }, isBrowserEnvironment) {
// Default auth options for browser
const DEFAULT_AUTH_OPTIONS = {
clientId: "",
authority: `${Constants.DEFAULT_AUTHORITY}`,
knownAuthorities: [],
cloudDiscoveryMetadata: "",
authorityMetadata: "",
redirectUri: typeof window !== "undefined" && window.location
? window.location.href.split("?")[0].split("#")[0]
: "",
postLogoutRedirectUri: "",
clientCapabilities: [],
OIDCOptions: {
responseMode: Constants.ResponseMode.FRAGMENT,
defaultScopes: [
Constants.OPENID_SCOPE,
Constants.PROFILE_SCOPE,
Constants.OFFLINE_ACCESS_SCOPE,
],
},
azureCloudOptions: {
azureCloudInstance: AzureCloudInstance.None,
tenant: "",
},
instanceAware: false,
isMcp: false,
};
// Default cache options for browser
const DEFAULT_CACHE_OPTIONS = {
cacheLocation: BrowserCacheLocation.SessionStorage,
cacheRetentionDays: 5,
};
// Default logger options for browser
const DEFAULT_LOGGER_OPTIONS = {
// eslint-disable-next-line @typescript-eslint/no-empty-function
loggerCallback: () => {
// allow users to not set logger call back
},
logLevel: LogLevel.Info,
piiLoggingEnabled: false,
};
// Default system options for browser
const DEFAULT_BROWSER_SYSTEM_OPTIONS = {
...DEFAULT_SYSTEM_OPTIONS,
loggerOptions: DEFAULT_LOGGER_OPTIONS,
networkClient: isBrowserEnvironment
? new FetchClient()
: StubbedNetworkModule,
navigationClient: new NavigationClient(),
popupBridgeTimeout: userInputSystem?.popupBridgeTimeout || DEFAULT_POPUP_TIMEOUT_MS,
iframeBridgeTimeout: userInputSystem?.iframeBridgeTimeout || DEFAULT_IFRAME_TIMEOUT_MS,
redirectNavigationTimeout: DEFAULT_REDIRECT_TIMEOUT_MS,
allowRedirectInIframe: false,
navigatePopups: true,
allowPlatformBroker: false,
nativeBrokerHandshakeTimeout: userInputSystem?.nativeBrokerHandshakeTimeout ||
DEFAULT_NATIVE_BROKER_HANDSHAKE_TIMEOUT_MS,
protocolMode: ProtocolMode.AAD,
};
const providedSystemOptions = {
...DEFAULT_BROWSER_SYSTEM_OPTIONS,
...userInputSystem,
loggerOptions: userInputSystem?.loggerOptions || DEFAULT_LOGGER_OPTIONS,
};
const DEFAULT_TELEMETRY_OPTIONS = {
application: {
appName: "",
appVersion: "",
},
client: new StubPerformanceClient(),
};
const DEFAULT_EXPERIMENTAL_OPTIONS = {
iframeTimeoutTelemetry: false,
};
// Throw an error if user has set OIDCOptions without being in OIDC protocol mode
if (userInputSystem?.protocolMode !== ProtocolMode.OIDC &&
userInputAuth?.OIDCOptions) {
const logger = new Logger(providedSystemOptions.loggerOptions);
logger.warning(JSON.stringify(createClientConfigurationError(ClientConfigurationErrorCodes.cannotSetOIDCOptions)), "");
}
// Throw an error if user has set allowPlatformBroker to true with OIDC protocol mode
if (userInputSystem?.protocolMode &&
userInputSystem.protocolMode === ProtocolMode.OIDC &&
providedSystemOptions?.allowPlatformBroker) {
throw createClientConfigurationError(ClientConfigurationErrorCodes.cannotAllowPlatformBroker);
}
const overlayedConfig = {
auth: {
...DEFAULT_AUTH_OPTIONS,
...userInputAuth,
OIDCOptions: {
...DEFAULT_AUTH_OPTIONS.OIDCOptions,
...userInputAuth?.OIDCOptions,
},
},
cache: { ...DEFAULT_CACHE_OPTIONS, ...userInputCache },
system: providedSystemOptions,
experimental: {
...DEFAULT_EXPERIMENTAL_OPTIONS,
...userInputExperimental,
},
telemetry: { ...DEFAULT_TELEMETRY_OPTIONS, ...userInputTelemetry },
};
return overlayedConfig;
}
export { DEFAULT_IFRAME_TIMEOUT_MS, DEFAULT_NATIVE_BROKER_HANDSHAKE_TIMEOUT_MS, DEFAULT_POPUP_TIMEOUT_MS, DEFAULT_REDIRECT_TIMEOUT_MS, buildConfiguration };
//# sourceMappingURL=Configuration.mjs.map