首页 > 解决方案 > Office Dialog API messageParent 在 Word 的 Edge 中不起作用

问题描述

如果我不复制 _host_Info,我会在 IE 和 Edge 的对话框弹出窗口中收到“警告 office.js 已在 office 客户端之外加载”。

我正在使用中间人服务身份验证流程。它在 Firefox、Chrome 和 Word 桌面客户端上运行良好,即使没有 _host_Info。

当我复制 _host_Info 时,对话框会在最后一次重定向回插件时自动关闭。

脚步:

  1. 触发 Office.context.ui.displayDialogAsync,带有查询 redirectb64 的插件位置,其中包含指向 mvc 外部登录的 url,并将 uri 重定向回插件。
  2. 插件再次打开检查redirectb64是否存在并将其解码回url
  3. 从窗口位置,我们将主机信息复制到重定向 url
  4. 重定向到挑战登录提供程序的 mvc 应用程序,然后返回到 mvc 应用程序进行登录,并在重定向回带有访问令牌和其他查询参数的插件之后。

从对话框事件处理程序中,我得到对话框关闭错误。

代码:

/* Render application after Office initializes */
Office.initialize = async () => {

    let redirectUrl:string = window.atob(UrlHelper.getUrlParameter("redirectb64"));
    if(redirectUrl !== "") {
        console.log("DialogUrl",window.location);
        console.log("Redirectb64 (atob)",redirectUrl);

        //Must copy over this to the redirectUri;
        let hostInfo:string = encodeURIComponent("&_host_Info=" + UrlHelper.getUrlParameter("_host_Info"));
        redirectUrl = StringHelper.insert(redirectUrl.indexOf("&state="),redirectUrl,hostInfo);
        console.log("Redirectb64 (atob) with hostInfo",redirectUrl);
        window.location.href = redirectUrl;
        return;
    }

    var response:AxiosResponse = await axios.get("assets/appconfig.json");
    console.log("config loaded.", response.data);
    AuthHelper.SetAccessToken();

    //console.log("AuthHelper.SetAccessToken", typeof AuthHelper.SetAccessToken);

    const myLanguage: string = Office.context.displayLanguage;
    render(App,myLanguage, true, response.data);
};

在 login.microsoft.com 回调到 mvc 应用程序之后,对话 api 似乎丢失了对话的轨迹。为什么?

标签: office-jsmicrosoft-edgeoffice-addins

解决方案


对于“office.js 已在外部加载”警告,您可以参考此线程Office.js 只能在 Office 应用程序中工作,例如在任务窗格中。要运行您正在开发的加载项,您需要将其旁加载到 Office 应用程序中。

此外,在使用中间人服务 API 时应该小心。通常,该服务有一个 API 方法来进行初始调用并创建上下文对象。像这样的对象不能完全字符串化,因此不能从 Office 对话框传递到父页面。更多信息可以参考文章的中间人服务部分。

建议使用 Office Dialog APIs 打开登录页面。关于在身份验证流程中使用 Dialog API,您可以参考这篇文章


推荐阅读