@azure/msal-browser
Version:
Microsoft Authentication Library for js
354 lines (346 loc) • 15.3 kB
JavaScript
/*! @azure/msal-browser v5.30.0 2026-11-18 */
;
;
var msalBrowser_cjs = require('../msal-browser.cjs');
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Unified error taxonomy shared by NAA and PWB.
*
* Each code maps to exactly one of the four base MSAL error classes
* (`AuthError`, `ClientAuthError`, `ServerError`,
* `InteractionRequiredAuthError`) via `toAuthError` in
* `./WebBrokerBridgeErrorMap`.
*/
const WebBrokerBridgeErrorCode = {
/* Interaction / auth outcomes */
UserInteractionRequired: "user_interaction_required",
UserCanceled: "user_canceled",
/* Environment / connectivity */
NoNetwork: "no_network",
AccountUnavailable: "account_unavailable",
BridgeDisabled: "bridge_disabled",
BridgeUnavailable: "bridge_unavailable",
/* Server-side outcomes */
TransientError: "transient_error",
PersistentError: "persistent_error",
/* Broker-channel failures */
BridgeTimeout: "bridge_timeout",
BridgeHandshakeFailed: "bridge_handshake_failed",
BridgeConnectionReset: "bridge_connection_reset",
BridgeResponseInvalid: "bridge_response_invalid",
PopupWillRedirect: "popup_will_redirect",
ShrGenerationError: "shr_generation_error",
/* Fallback */
Unknown: "unknown",
};
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Lift a normalized `WebBrokerBridgeError` to one of the four base
* MSAL error classes. Callers are responsible for lowering
* transport-specific errors into `WebBrokerBridgeError` before calling
* this function.
*/
function toAuthError(err) {
const correlationId = err.correlationId ?? "";
switch (err.code) {
case WebBrokerBridgeErrorCode.UserInteractionRequired:
return new msalBrowser_cjs.InteractionRequiredAuthError(err.innerErrorCode || "", correlationId, err.description, err.subError);
case WebBrokerBridgeErrorCode.TransientError:
case WebBrokerBridgeErrorCode.PersistentError:
return new msalBrowser_cjs.ServerError(err.innerErrorCode || "", correlationId, err.description, err.subError);
case WebBrokerBridgeErrorCode.UserCanceled:
return new msalBrowser_cjs.ClientAuthError(msalBrowser_cjs.ClientAuthErrorCodes.userCanceled, correlationId);
case WebBrokerBridgeErrorCode.NoNetwork:
return new msalBrowser_cjs.ClientAuthError(msalBrowser_cjs.ClientAuthErrorCodes.noNetworkConnectivity, correlationId);
case WebBrokerBridgeErrorCode.AccountUnavailable:
return new msalBrowser_cjs.ClientAuthError(msalBrowser_cjs.ClientAuthErrorCodes.noAccountFound, correlationId);
case WebBrokerBridgeErrorCode.BridgeDisabled:
return new msalBrowser_cjs.ClientAuthError(msalBrowser_cjs.ClientAuthErrorCodes.nestedAppAuthBridgeDisabled, correlationId);
case WebBrokerBridgeErrorCode.BridgeUnavailable:
/*
* NAA parity: pass through inner code when the broker supplied
* one, otherwise fall back to the disabled code.
*/
return new msalBrowser_cjs.ClientAuthError(err.innerErrorCode ||
msalBrowser_cjs.ClientAuthErrorCodes.nestedAppAuthBridgeDisabled, correlationId, err.description);
/*
* PWB broker-channel failures. The common code doubles as the
* concrete errorCode on AuthError so the original error identity
* can be recovered by round-tripping the string.
*/
case WebBrokerBridgeErrorCode.BridgeTimeout:
case WebBrokerBridgeErrorCode.BridgeHandshakeFailed:
case WebBrokerBridgeErrorCode.BridgeConnectionReset:
case WebBrokerBridgeErrorCode.BridgeResponseInvalid:
case WebBrokerBridgeErrorCode.PopupWillRedirect:
case WebBrokerBridgeErrorCode.ShrGenerationError:
return new msalBrowser_cjs.AuthError(err.code, correlationId, err.description, err.subError);
case WebBrokerBridgeErrorCode.Unknown:
default:
return new msalBrowser_cjs.AuthError(err.innerErrorCode || "unknown_error", correlationId, err.description || "An unknown error occurred", err.subError);
}
}
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Correlates outbound requests with inbound responses by `requestId`.
*/
class PendingRequestRegistry {
constructor() {
this.pending = new Map();
}
/**
* Register a pending request. Returns a promise that resolves when a
* response with the matching `requestId` arrives, or rejects if the
* caller invokes `reject` for that id.
*/
register(requestId) {
return new Promise((resolve, reject) => {
this.pending.set(requestId, { resolve, reject });
});
}
/** Resolve a pending request. No-op if `requestId` isn't registered. */
resolve(requestId, response) {
const entry = this.pending.get(requestId);
if (entry === undefined) {
return;
}
this.pending.delete(requestId);
entry.resolve(response);
}
/** Reject a pending request. No-op if `requestId` isn't registered. */
reject(requestId, reason) {
const entry = this.pending.get(requestId);
if (entry === undefined) {
return;
}
this.pending.delete(requestId);
entry.reject(reason);
}
/** True if `requestId` has an in-flight registration. */
has(requestId) {
return this.pending.has(requestId);
}
/**
* Register, then invoke `send` synchronously. If `send` throws, the
* pending entry is cleared and the promise rejects with the thrown
* error.
*/
async sendAndAwait(message, send) {
const promise = this.register(message.requestId);
try {
send(message);
}
catch (err) {
this.reject(message.requestId, err);
}
return promise;
}
}
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Promotes `extraParameters.resource` to the top-level `resource` field.
*
* Pre-5.5.0 embedded apps do not have a top-level `resource` field.
*
* @param request - The request to transform.
* @returns A new request with `resource` promoted if applicable.
*/
function normalizeResourceField(request) {
if (request.extraParameters?.resource) {
const { resource, ...remainingParams } = request.extraParameters;
const result = { ...request };
result.resource = resource;
result.extraParameters = remainingParams;
return result;
}
return request;
}
/**
* Demotes the top-level `resource` field into `extraParameters.resource`.
*
* Pre-5.5.0 embedded apps do not have a top-level `resource` field.
*
* @param request - The request to transform.
* @returns A new request with `resource` demoted if applicable.
*/
function addResourceField(request) {
if (request.resource) {
const resource = request.resource;
const result = { ...request };
result.extraParameters = {
...result.extraParameters,
resource,
};
delete result.resource;
return result;
}
return request;
}
/**
* Normalize an incoming request from any embedded-app version so that
* the broker PCA methods can consume it correctly.
*
* - Folds legacy field values into their current equivalents.
* - Strips legacy field names from the returned object.
* - Is idempotent: safe to call on requests that already use current names.
*
* @param request - The request from a broker auth request.
* @returns A new request with current field names only.
*/
function normalizeIncomingRequest(request) {
const normalized = normalizeResourceField(request);
const currentFields = { ...normalized };
const { tokenQueryParameters, tokenBodyParameters, authorizePostBodyParameters, } = currentFields;
delete currentFields.tokenQueryParameters;
delete currentFields.tokenBodyParameters;
delete currentFields.authorizePostBodyParameters;
/*
* tokenQueryParameters (removed in v5) → extraQueryParameters.
* Current values win on key conflicts.
*/
if (tokenQueryParameters) {
currentFields.extraQueryParameters = {
...tokenQueryParameters,
...currentFields.extraQueryParameters,
};
}
/*
* tokenBodyParameters (removed in v5) → extraParameters.
* Current values win on key conflicts.
*/
if (tokenBodyParameters) {
currentFields.extraParameters = {
...tokenBodyParameters,
...currentFields.extraParameters,
};
}
/*
* authorizePostBodyParameters (removed in v5) → extraParameters.
* Merged after tokenBodyParameters; current values still win.
*/
if (authorizePostBodyParameters) {
currentFields.extraParameters = {
...authorizePostBodyParameters,
...currentFields.extraParameters,
};
}
return currentFields;
}
/**
* Add legacy field aliases to an outgoing request so that an older broker
* can still consume the parameters.
*
* - Copies current field values into all known legacy field names.
* - Merges extraParameters into extraQueryParameters (extraParameters wins)
* so the v4 broker sees them on the /authorize query string.
* - Deliberately omits authorizePostBodyParameters.
* - Is idempotent: safe to call multiple times.
*
* @param request - The request about to be wrapped in a broker auth request.
* @returns A new request carrying both current and legacy field names.
*/
function addLegacyRequestFields(request) {
const result = {
...addResourceField(request),
};
// extraQueryParameters → also set legacy tokenQueryParameters (removed in v5)
if (result.extraQueryParameters) {
result.tokenQueryParameters = { ...result.extraQueryParameters };
}
// extraParameters → also set legacy field aliases (removed in v5)
if (result.extraParameters) {
// Token endpoint is always POST, so body params always apply.
result.tokenBodyParameters = { ...result.extraParameters };
/*
* In v5, extraParameters are sent on the /authorize query string (GET)
* or POST body depending on httpMethod. The v4 broker reads
* extraQueryParameters for both flows' query strings, so merging here
* covers both. We intentionally omit authorizePostBodyParameters
* because v4 throws if it is present without httpMethod === "POST",
* and the embedded app cannot expect control over how the request
* is made.
*/
result.extraQueryParameters = {
...result.extraQueryParameters,
...result.extraParameters,
};
}
return result;
}
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Shared performance event names for web broker bridge operations.
*
* @internal
*/
const PairwiseBrokerApplicationInitializeBrokering = "pairwiseBrokerApplicationInitializeBrokering";
const BrokerClientApplicationHandleBrokerHandshake = "brokerClientApplicationHandleBrokerHandshake";
const BrokerClientApplicationBrokeredSSOSilentRequest = "brokerClientApplicationBrokeredSSOSilentRequest";
const BrokerClientApplicationBrokeredSilentRequest = "brokerClientApplicationBrokeredSilentRequest";
const EmbeddedClientApplicationSendSSOSilentRequest = "embeddedSSOSilent";
const EmbeddedClientApplicationSendPopupRequest = "embeddedPopup";
const EmbeddedClientApplicationHandleRedirectRequest = "embeddedHandleRedirect";
const EmbeddedClientApplicationSendSilentRefreshRequest = "embeddedSilentRefresh";
const EmbeddedSendSilentRefreshRequestInternal = "embeddedSilentRefreshInternal";
const SendHandshakeRequest = "sendHandshakeRequest";
const SendMessageToBroker = "sendMessageToBroker";
const SendRequest = "sendRequest";
const HandleResponse = "handleBrokerResponse";
const GetFrameDepth = "getFrameDepth";
const OnHandshakeResponse = "onHandshakeResponse";
const HandleBrokerMessage = "handleBrokerMessage";
const PostMessageToAllDescendantFrames = "postMessageToAllDescendantFrames";
const HandleBrokerAuthRequest = "handleBrokerAuthRequest";
const BrokeredSilentRequest = "brokeredSilentRequest";
const BrokeredSsoSilentRequest = "brokeredSsoSilentRequest";
const BrokeredRedirectRequest = "brokeredRedirectRequest";
const BrokeredPopupRequest = "brokeredPopupRequest";
const InteractiveBrokerRequest = "interactiveBrokerRequest";
const AcquireTokenByBroker = "acquireTokenByBroker";
exports.AcquireTokenByBroker = AcquireTokenByBroker;
exports.BrokerClientApplicationBrokeredSSOSilentRequest = BrokerClientApplicationBrokeredSSOSilentRequest;
exports.BrokerClientApplicationBrokeredSilentRequest = BrokerClientApplicationBrokeredSilentRequest;
exports.BrokerClientApplicationHandleBrokerHandshake = BrokerClientApplicationHandleBrokerHandshake;
exports.BrokeredPopupRequest = BrokeredPopupRequest;
exports.BrokeredRedirectRequest = BrokeredRedirectRequest;
exports.BrokeredSilentRequest = BrokeredSilentRequest;
exports.BrokeredSsoSilentRequest = BrokeredSsoSilentRequest;
exports.EmbeddedClientApplicationHandleRedirectRequest = EmbeddedClientApplicationHandleRedirectRequest;
exports.EmbeddedClientApplicationSendPopupRequest = EmbeddedClientApplicationSendPopupRequest;
exports.EmbeddedClientApplicationSendSSOSilentRequest = EmbeddedClientApplicationSendSSOSilentRequest;
exports.EmbeddedClientApplicationSendSilentRefreshRequest = EmbeddedClientApplicationSendSilentRefreshRequest;
exports.EmbeddedSendSilentRefreshRequestInternal = EmbeddedSendSilentRefreshRequestInternal;
exports.GetFrameDepth = GetFrameDepth;
exports.HandleBrokerAuthRequest = HandleBrokerAuthRequest;
exports.HandleBrokerMessage = HandleBrokerMessage;
exports.HandleResponse = HandleResponse;
exports.InteractiveBrokerRequest = InteractiveBrokerRequest;
exports.OnHandshakeResponse = OnHandshakeResponse;
exports.PairwiseBrokerApplicationInitializeBrokering = PairwiseBrokerApplicationInitializeBrokering;
exports.PendingRequestRegistry = PendingRequestRegistry;
exports.PostMessageToAllDescendantFrames = PostMessageToAllDescendantFrames;
exports.SendHandshakeRequest = SendHandshakeRequest;
exports.SendMessageToBroker = SendMessageToBroker;
exports.SendRequest = SendRequest;
exports.WebBrokerBridgeErrorCode = WebBrokerBridgeErrorCode;
exports.addLegacyRequestFields = addLegacyRequestFields;
exports.addResourceField = addResourceField;
exports.normalizeIncomingRequest = normalizeIncomingRequest;
exports.normalizeResourceField = normalizeResourceField;
exports.toAuthError = toAuthError;
//# sourceMappingURL=msal-web-broker-bridge.cjs.map