Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Office initialize not working anymore in safari 17.4 #4438

Open
Githamza opened this issue May 10, 2024 · 2 comments
Open

Office initialize not working anymore in safari 17.4 #4438

Githamza opened this issue May 10, 2024 · 2 comments
Assignees
Labels
Area: add-ins platform Issue related to the add-ins platform Area: Common APIs Issues related to common apis Needs: attention 👋 Waiting on Microsoft to provide feedback Status: under investigation Issue is being investigated Type: product bug Bug in the Office Add-ins platform or Office JavaScript APIs

Comments

@Githamza
Copy link

Githamza commented May 10, 2024

Since updating safari from 16 to 17 , the Initialize function does not work . So the authentication too

export default (() => {
  alert("baseUrl");
  console.log("baseUrl");
  // The initialize function must be run each time a new page is loaded, should get client_id and login url from url parameters
  Office.initialize = async () => {
    console.log("msalInstanceterer");
    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")
        ? "xxxxxx"
        : "xxxxxxxc0c2bd127807";

      const baseUrl = window.location.origin;
      alert(baseUrl);
      console.log("baseUrl", baseUrl);

      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);
      await msalInstance.initialize();
      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}`;
          Office.context.ui.messageParent(JSON.stringify({ status: "failure", result: errorData }));
        });
    } catch (error) {
      console.log("error", error);
    }
  };
})();
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP label May 10, 2024
@Githamza Githamza changed the title Office initialize not working anymore in safara 17.4 Office initialize not working anymore in safari 17.4 May 10, 2024
@shanshanzheng-dev
Copy link

Hi @Githamza Thanks for reporting the issue. Could you elaborate a bit more about how this is related to our office JS APIs? Thanks!

@Rick-Kirkham
Copy link
Contributor

@shanshanzheng-dev The Office.initialize() method is part of the Office.js API library.
@Githamza The person who normally gets assigned issues about the runtimes is new to our org and I can't yet assign her this issue, but I will in a few days.

@Rick-Kirkham Rick-Kirkham added Needs: attention 👋 Waiting on Microsoft to provide feedback Type: product bug Bug in the Office Add-ins platform or Office JavaScript APIs Status: under investigation Issue is being investigated Area: add-ins platform Issue related to the add-ins platform Area: Common APIs Issues related to common apis and removed Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: add-ins platform Issue related to the add-ins platform Area: Common APIs Issues related to common apis Needs: attention 👋 Waiting on Microsoft to provide feedback Status: under investigation Issue is being investigated Type: product bug Bug in the Office Add-ins platform or Office JavaScript APIs
Projects
None yet
Development

No branches or pull requests

4 participants