【问题标题】:Office Dialog API messageParent does not work in Edge for WordOffice Dialog API messageParent 在 Word 的 Edge 中不起作用
【发布时间】:2020-02-11 11:15:12
【问题描述】:

如果我不复制 _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-js microsoft-edge office-addins


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多