Outlook插件SSO认证场景下Office.context.ui.messageParent无法向父页面返回数据的问题求助
Outlook插件SSO认证场景下Office.context.ui.messageParent无法向父页面返回数据的问题求助
大家好,我开发了一个Outlook插件,采用SSO方式做用户认证,现在遇到了Office.context.ui.messageParent无法向父页面传递数据的问题,折腾了好久没解决,想请各位帮忙看看。
下面是我的具体实现流程:
Welcome.html 逻辑
在Welcome.html页面,我通过按钮点击调用displayDialogAsync打开一个登录对话框:
$("#btnLoginPopup").click(function () { // 设置对话框重定向和回调方法 Office.context.ui.displayDialogAsync("https://someUrl.co.uk/Login/Login.html", { height: 50, width: 50}, function (asyncResult) { if (asyncResult.status == Office.AsyncResultStatus.Failed) { console.log("Could not open login page", event); } else { console.log("Successfully opened"); dialog = asyncResult.value; dialog.addEventHandler(Office.EventType.DialogMessageReceived, processMessage); } }); });
同时在该页面定义了接收消息的回调函数:
function processMessage(arg) { // 关闭对话框 dialog.close(); console.error("Back"); }
Login.html 与 LoginCallback.html 逻辑
Login.html页面加载后,会自动跳转到另一个域名的外部登录页面,用户完成认证后,会被重定向回同域名下的LoginCallback.html页面。在这个回调页面里,我设置了一个按钮,点击时尝试调用messageParent向父页面发送消息,但就是不生效:
$("#btnLogin").click(function () { Office.context.ui.messageParent("In", { targetOrigin: "https://someUrl.co.uk/" }); });
遇到的问题
我尝试了两种配置,都有问题:
- 如果不把外部登录URL加到插件Manifest的AppDomains里:控制台没有报错,但父页面的
processMessage函数完全不会被触发; - 如果把外部登录URL加到AppDomains里:会直接抛出错误:
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://SomeUrlAuthUrl.co.uk') does not match the recipient window's origin ('https://someUrl.co.uk').
已尝试的解决办法
我试过以下几种方式,但都没解决问题:
- 反复添加/移除外部登录URL到AppDomains;
- 调用
Office.context.ui.messageParent("In", { targetOrigin: "*" }); - 直接调用
Office.context.ui.messageParent("In")。
插件Manifest配置
我的AppDomains部分是这样的:
<AppDomains> <AppDomain>https://SomeUrl.co.uk</AppDomain> <AppDomain>https://SomeUrlAuthUrl.co.uk</AppDomain> </AppDomains>
有没有大佬遇到过类似的问题?麻烦帮忙指点一下,万分感谢!
备注:内容来源于stack exchange,提问作者Ritesh734
相关产品推荐
相关产品推荐

