Reputation: 241
I've created an Office Addin for Word. When I try to authenticate to Office 365, I'm using Office.context.ui.displayDialogAsync
to open a dialog. My callback is successfull and the dialog opens. After the dialog opens the api makes a call to _dlg.addEventHandler(Office.EventType.DialogEventReceived, processMessage);
which is returning an error code of 12003
which means https is required, but my page is served via https.
Not sure why I'm getting this error, if my page is served via https?
$scope.startLogin = function () {
showLoginPopup("/Auth.html").then(function successCallback(response) {
// authentication has succeeded but to get the authenication context for the
// user which is stored in localStorage we need to reload the page.
window.location.reload();
}, function errorCallback(response) {
console.log(response);
});
};
var _dlg;
var _dlgDefer;
var showLoginPopup = function (url) {
_dlgDefer = $q.defer();
Office.context.ui.displayDialogAsync('https://' + location.hostname + url, { height: 40, width: 40}, function (result) {
console.log("dialog has initialized. wiring up events");
_dlg = result.value;
console.log(result.value)
_dlg.addEventHandler(Office.EventType.DialogEventReceived, processMessage);
});
return _dlgDefer.promise;
}
function processMessage(arg) {
console.log(arg.error)
var msg = arg.message;
console.log("Message received in processMessage");
if (msg && msg === "success") {
//we now have a valid auth token in the localStorage
_dlg.close();
_dlgDefer.resolve();
} else {
//something went wrong with authentication
_dlg.close();
console.log("Authentication failed: " + arg.message);
_dlgDefer.reject();
}
}
Upvotes: 0
Views: 427
Reputation: 9659
Some things in your code lead me to think that you may be using old examples. There have been some changes in the Dialog APIs. If you haven't already, please read Use the Dialog API in your Office Add-ins.
12003 does not mean that the original page that is passed as a parameter to displayDialogAsync() is non-HTTPS. Rather, it means that the dialog has been redirected to a non-HTTPS address after initially opening an HTTPS URL. You need to look at the script for your Auth.html page and see what URLs the dialog is being redirected to.
Another thing I noticed: Your handler for DialogEventReceived tests for "success" as arg.message. The DialogEventReceived is really only for error handling now. Normally, success should be conveyed to the host page with a call of messageParent(). You handle these messages on the host page with a handler for the event DialogMessageReceived.
Upvotes: 2