Since I updated Safari to 17.4
Office context item is empty on the authentification page.
import { PublicClientApplication } from "@azure/msal-browser";
export default (() => {
// The initialize function must be run each time a new page is loaded, should get client_id and login url from url parameters
Office.onReady(async (infos) => {
try {
const login_url = new URLSearchParams(window.location.search).get("MSAL_LOGIN_URL")?.trim();
// check if there is localhost on utl so assign bla to a const otherwise asign blabla
const client_id = window.location.href.includes("localhost")
? "xxxx-2e02d357f9e0"
: "xxxx-c0c2bd127807";
const baseUrl = window.location.origin;
const msalInstance = new PublicClientApplication({
auth: {
clientId: client_id,
authority: "https://login.microsoftonline.com/common",
redirectUri: `${baseUrl}/loginfile.html`,
},
cache: {
cacheLocation: "localStorage", // needed to avoid "login required" error
storeAuthStateInCookie: true, // recommended to avoid certain IE/Edge issues
},
});
// handleRedirectPromise should be invoked on every page load
console.log("msalInstance", msalInstance);
try {
await msalInstance.initialize();
} catch (error) {
Office.context.ui.messageParent(JSON.stringify({ status: "error", result: JSON.stringify(error) }));
}
msalInstance
.handleRedirectPromise()
.then(async (response) => {
// If response is non-null, it means page is returning from AAD with a successful response
if (response) {
Office.context.ui.messageParent(JSON.stringify({ status: "success", result: response.accessToken }));
} else {
// Otherwise, invoke login
await msalInstance.loginRedirect({
scopes: ["profile", "openid", "user.read", "mail.readwrite", "tasks.readwrite"],
});
Office.context.ui.messageParent(JSON.stringify({ status: "success", result: response.accessToken }));
}
})
.catch((error) => {
const errorData: string = `errorMessage: ${error.errorCode}
message: ${error.errorMessage}
errorCode: ${error.stack}`;
});
} catch (error) {
Office.context.ui.messageParent(JSON.stringify({ status: "error", result: JSON.stringify(error) }));
}
});
})();
When I click on context
In Chrome and Edge it’s working.