@azure/msal-browser
Version:
Microsoft Authentication Library for js
73 lines (70 loc) • 2.74 kB
JavaScript
/*! @azure/msal-browser v5.13.0 2026-06-10 */
;
import { createBrowserAuthError } from '../error/BrowserAuthError.mjs';
import { getEARForm, getCodeForm } from '../protocol/Authorize.mjs';
import { emptyNavigateUri } from '../error/BrowserAuthErrorCodes.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Navigates the given hidden iframe to the provided URL.
* @param frame
* @param requestUrl
*/
async function initiateCodeRequest(frame, requestUrl, logger, correlationId) {
if (!requestUrl) {
// Throw error if request URL is empty.
logger.info("1l7hyp", correlationId);
throw createBrowserAuthError(emptyNavigateUri);
}
frame.src = requestUrl;
return frame;
}
async function initiateCodeFlowWithPost(frame, config, authority, request, logger, performanceClient) {
if (!frame.contentDocument) {
throw "No document associated with iframe!";
}
const form = await getCodeForm(frame.contentDocument, config, authority, request, logger, performanceClient);
form.submit();
return frame;
}
async function initiateEarRequest(frame, config, authority, request, logger, performanceClient) {
if (!frame.contentDocument) {
throw "No document associated with iframe!";
}
const form = await getEARForm(frame.contentDocument, config, authority, request, logger, performanceClient);
form.submit();
return frame;
}
/**
* @hidden
* Creates a new hidden iframe for silent token renewal. Callers navigate it
* (set `src` or submit a form) after registering the response listener.
* @ignore
*/
function createHiddenIframe() {
const authFrame = document.createElement("iframe");
authFrame.className = "msalSilentIframe";
authFrame.title = "Microsoft Authentication";
authFrame.style.visibility = "hidden";
authFrame.style.position = "absolute";
authFrame.style.width = authFrame.style.height = "0";
authFrame.style.border = "0";
authFrame.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms");
authFrame.setAttribute("allow", "local-network-access *");
document.body.appendChild(authFrame);
return authFrame;
}
/**
* @hidden
* Removes a hidden iframe from `document.body` if it is a direct child.
* @param iframe - The iframe element to remove.
*/
function removeHiddenIframe(iframe) {
if (document.body === iframe.parentNode) {
document.body.removeChild(iframe);
}
}
export { createHiddenIframe, initiateCodeFlowWithPost, initiateCodeRequest, initiateEarRequest, removeHiddenIframe };
//# sourceMappingURL=SilentHandler.mjs.map