【问题标题】:OfficeJs: Outlook Addin: Dialog API's messageParent not working with OWAOffice Js:Outlook 加载项:对话框 UI 消息父级无法使用 OWA
【发布时间】:2019-01-08 08:09:17
【问题描述】:

背景: 我有一个 Outlook 插件,它基本上打开了一个登录对话框,该对话框打开了我网站上托管的插件页面,从这里用户被重定向到 auth0,从那里他被重定向到 login.live.com 并发布 auth 我得到一个代码或一个错误再次返回我网站上的另一个页面。

现在,在 Outlook 胖客户端中一切正常。当我手动关闭对话框时,我会在父级中获得正确的错误代码。

问题: 在我的网站上使用 OWA 并托管插件代码时,控件不会返回到对话框中的部分。

我已经在“AppDomains”中添加了用户可以访问的所有网址。并确认父窗口和子窗口都托管在同一个域(和子域)上。

代码

manifest.xml

<AppDomains>
<AppDomain>https://auth0url.auth0.com</AppDomain>
<AppDomain>https://localhost</AppDomain>
<AppDomain>https://login.live.com</AppDomain>
<AppDomain>https://login.microsoftonline.com</AppDomain>    
<AppDomain>https://my.website.com</AppDomain>

index.html (Opener Html)

<!-- Load the Office JavaScript APIs -->
<script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/Office.js" type="text/javascript"></script>
<script src="index.js"></script>

index.js

// height and width are percentages of the size of the screen.
Office.context.ui.displayDialogAsync(fullUrl, {height: 45, width: 55, displayInIframe: false},
      function (asyncResult) {
            console.log(asyncResult);
            if (asyncResult.status === "failed") {

                //Error code 12009 means "user chose to ignore the dialog box"
                if (asyncResult.error.code === 12009) {
                  // Handle failure    
                } else {
                  // Do something else     
                }
            } else {
                dialog = asyncResult.value;
                dialog.addEventHandler(Office.EventType.DialogMessageReceived, handleToken);
                dialog.addEventHandler(Office.EventType.DialogEventReceived, dialogClosing);

       }
    });

popupRedirect.js(仅托管在我的网站上(与父窗口相同)此文件将 json 字符串触发回父窗口)

    Office.initialize = function() {
        $(document).ready(function () {

            // Some Code before this and after this not relevent to issue
            var messageObject = {outcome: "something"};
            // Tell the task pane about the outcome.
            Office.context.ui.messageParent(jsonMessage);

      ...
        });
    });

预期结果:

“messageParent”应该触发index.js的“handleToken”中写的代码

实际结果(可能相关也可能不相关)

appsforoffice.micros…16.01.debug.js:8202 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('auth0url.auth0.com') does not match the recipient window's origin ('https://my.website.com').

handleToken 中编写的代码不会被触发。

请注意:displayInIframe: true 不起作用,因为 login.live.com 不允许 iframe。

使用的测试环境:

Google Chrome 71.0.3578.98(官方版本)(64 位)(同类群组:稳定) 修订版 15234034d19b85dcd9a03b164ae89d04145d8368-refs/branch-heads/3578@{#897} 操作系统视窗 10 JavaScript V8 7.1.302.31 闪存 32.0.0.101

【问题讨论】:

    标签: office-js outlook-web-addins outlook-web-app


    【解决方案1】:

    我们的问题终于解决了,但我不知道为什么会出现这样的问题。这可能特定于我们的设置,但无论如何这里是:

    我们使用了托管在 auth0url.auth0.com 域上的 auth0。在从 my.website.com 传递到 auth0url.auth0.com 的对话框控件中,然后是 MS 登录屏幕并返回到 my.website.com 而我们 确实 在 AppDomains 中指定了此域。由于某种原因,office lib 无法识别这一点。并投诉了

    appsforoffice.micros…16.01.debug.js:8202 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('auth0url.auth0.com') does not match the recipient window's origin ('https://my.website.com')

    那么什么改变解决了这个问题?

    Auth0 还支持自定义域而不是他们的,这意味着当我们从 auth0url.auth0.com 更改为 myauth0.mywebsite.com(当然我们将其添加到 AppDomains)时,插件可以执行“postMessage”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 2021-05-18
      相关资源
      最近更新 更多