I am using Office-js-helpers and Office.context.ui.displayDialogAsync to authenticate users in our Outlook Add-in. The dialog opens fine and I can authenticate using our IdentityServer4 url (e.g. /connect/authenticate with redirectUrl window.location.origin). However, if I don't have Index.html in my add-in folder I get the 12002 error in the DialogEventReceived handler which means the dialog cannot load the url. I don't get this error if I add Index.html in my add-in's folder (e.g. window.location.origin will be https://localhost:44352/Index.html) - But nothing happens. The DialogMessageReceived handle never triggers. I am getting this same behaviour using office-js' Authenticator.authenticate and displayDialogAsync.
Please see below snippets which authenticates fine in the dialog, but I cannot get the token/code because DialogMessageReceived never triggers or goes into error.
Using Office-js-helpers
authenticator.endpoints.add("RM", {
provider: 'RM',
clientId: "MyClientId",
baseUrl: "MyHttpsProtocol://MyDomain.DotCom/MyIdentityServer",
authorizeUrl: "/connect/authorize",
tokenUrl: "MyHttpsProtocol://MyDomain.DotCom/MyIdentityServer/connect/token",
redirectUrl: window.location.origin,
responseType: "code",
state: true,
scope: "openid profile onelist offline_access"
});
authenticator.authenticate('RM', true)
.then(function (token) {
showNotification("Token: " + prettify(token));
})
.catch(function (error) {
showNotification("No Token: " + prettify(error));
});
Using Dialog Api
Office.context.ui.displayDialogAsync("MyHttpsProtocol://MyDomain.DotCom/MyIdentityServer/connect/authorize?response_type=code&client_id=MyClientID&redirect_uri=https%3A%2F%2Flocalhost%3A44352&scope=openid%20profile%20MyProfile%20offline_access&state=3364575774",
{ height: 500, width: 500 },
function (asyncResult) {
dialog = asyncResult.value;
dialog.addEventHandler(Office.EventType.DialogMessageReceived, function (args) {
showNotification(prettify(args.message));
dialog.close();
});
dialog.addEventHandler(Office.EventType.DialogEventReceived, function (args) {
showNotification(prettify(args.error));
dialog.close();
});
}
);
Please help :) What am I missing or doing wrong?