问题
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
回答1:
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'.
来源:https://stackoverflow.com/questions/54087582/officejs-outlook-addin-dialog-apis-messageparent-not-working-with-owa