OfficeJs:Outlook外接程序:对话框API的messageParent不与OWA一起使用 [英] OfficeJs: Outlook Addin: Dialog API's messageParent not working with OWA

查看:126
本文介绍了OfficeJs:Outlook外接程序:对话框API的messageParent不与OWA一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景: 我有一个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

解决方案

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

我们使用了托管在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".

Background: I have an outlook addin which basically opens up a login dialog which opens up addin page hosted on my website from here user is redirected to auth0 from where he's redirected to login.live.com and post auth I get back either a code or an error back to another page again on my website.

Now, everything works fine in the outlook thick client. When I close the dialog manually I get the right error code in parent.

Problem: When using the OWA and hosting the addin code on my website, the control does not come back to the part from the dialog.

I have already added all urls the user can go in the "AppDomains". And have confirmed that the both the parent and child window are hosted on the same domain (and subdomain).

Code

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 (Hosted on mywebsite only (same as the parent window) This file triggers the json string back to parent)

    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);

      ...
        });
    });

Expected Results:

The "messageParent" should trigger the code written in "handleToken" of the index.js

Actual Results (May or may not be related)

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').

The code written in handleToken does not get triggered.

Note that : displayInIframe: true is not working as login.live.com won't allow iframes.

Environment for Testing Used:

Google Chrome 71.0.3578.98 (Official Build) (64-bit) (cohort: Stable) Revision 15234034d19b85dcd9a03b164ae89d04145d8368-refs/branch-heads/3578@{#897} OS Windows 10 JavaScript V8 7.1.302.31 Flash 32.0.0.101

解决方案

Our issue got finally resolved, while I do not know why this should be a problem. This may be specific to our setup but anyways here it is :

We used auth0 which was hosted on auth0url.auth0.com domain. In the dialog control passed from my.website.com to auth0url.auth0.com and then MS Login screens and back to my.website.com And while we did specify this domain in the AppDomains. For some reason the office lib failed to recognize that. and complained

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')

So what change solved this ?

Auth0 also supports custom domain instead of theirs which meant when we changed from auth0url.auth0.com to myauth0.mywebsite.com (and ofcourse we added this to the AppDomains), the addin could do the 'postMessage'.

这篇关于OfficeJs:Outlook外接程序:对话框API的messageParent不与OWA一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆