OfficeJs:Outlook外接程序:对话框API的messageParent不与OWA一起使用

时间:2019-01-08 08:09:18

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

背景: 我有一个Outlook外挂程序,它基本上会打开一个登录对话框,从中打开在我的网站上托管的外挂程序页面用户从这里重定向到auth0,从那里他重定向到login.live.com并发布auth,我得到一个代码或错误回到我的网站上的另一个页面。

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

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

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

代码

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(开瓶器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(仅在mywebsite上托管(与父窗口相同),此文件将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} 操作系统Windows 10 JavaScript V8 7.1.302.31 Flash 32.0.0.101

1 个答案:

答案 0 :(得分:1)

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

我们使用了托管在auth0url.auth0.com域上的auth0。在对话框控件中,该控件从my.website.com传递到auth0url.auth0.com,然后是MS登录屏幕,然后返回my.website.com,而我们 did 在AppDomains中指定了该域。由于某种原因,办公室图书馆未能意识到这一点。并抱怨

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”。

相关问题