Has Office Add-in for the Outlook Online. I need to implelemnt login logic to external service with next steps:
- Show my page (gateway.php) in seperate window
- Redirect to the external service authentication page
- Redirect back to my page, retrieve authentication code and notify parent application.
Using docs from MS Dev Center Authenticate and authorize with the Office dialog API and Use the Office dialog API in Office Add-ins
Both add-in and gateway.php pages are in the same domain/sub-domain. AppDomains in manifest updated. HTTPS is used. No custom ports. Its not a localhost.
The problems occurs on the stage 3: the dialog window is simply closed without any notifications or errors after its redirected back from external service auth page. Event Office.EventType.DialogEventReceived is caught in the parent window, but with error code 12006 'Dialog closed by user'. While Office.EventType.DialogMessageReceived is expected. After some debugging it's seems that next code from the office.js library is responisble:
var initialize = function OSF__OfficeAppFactory$initialize() {
_retrieveHostInfo();
_retrieveLoggingAllowed();
if (_hostInfo.hostPlatform == "web" && _hostInfo.isDialog && window == window.top && window.opener == null) {
window.open('', '_self', '');
window.close(); //<--- this what closes my window
}
And the reason for that is because due to redirect to external service page (which is outside my domain) window.opener is null.:( And i simply can't find how it should work in my case.
My page after the redirect is very simple -- just a script for the Office, but it's never even reached. Page is closed much earlier.
<html>
<head>
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.debug.js"></script>
</head>
<body>
<script lang="js" type="text/javascript">
if (typeof Office !== 'undefined'){
Office.onReady(info => {
const messageObject = {message: "CODE_FROM_GET_PARAM"};
const jsonMessage = JSON.stringify(messageObject);
Office.context.ui.messageParent(jsonMessage);
});
} else {
console.warn("Office failed");
}
</script>
</body>
</html>
For the case of redirects inside my domain -- everything works just fine. Parent is notified without any issues.
Any ideas how it should work in case of redirects to external domains? Based on the Authenticate and authorize with the Office dialog API it should.
Edited: Link to the created issue at Github.
Thanks