0

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?

dmc
  • 807
  • 2
  • 10
  • 25
  • What client and version are you using? – Outlook Add-ins Team - MSFT May 21 '19 at 20:46
  • Hi @OutlookAdd-insTeam-MSFT I am using Outlook / Office 2016 with build number greater than 16.0.4390.1000 (as specified) in the DialogAPI requirements. The Dialog is opening fine and loading my external url which I have in the AppDomains manifest. It is only when it goes to the redirectUrl which is localhost:port that it goes into error. And if I add Index.html in my addin folder to have a default page (e.g. localhost:port will load index.html) or if I make the redirectUrl an external one - I am not getting any errors but it doesn’t trigger the DialogMessageReceived event so nothing happens. – dmc May 21 '19 at 20:59
  • Is localhost in your appdomains? What build of Outlook are you using? – Outlook Add-ins Team - MSFT May 21 '19 at 23:36
  • @OutlookAdd-insTeam-MSFT Yes I have https://localhost in my manifest... Also tried adding with the specific port like https://localhost:44352 but still the same error. – dmc May 21 '19 at 23:48
  • @OutlookAdd-insTeam-MSFT Note: I also get the same 12002 error using Office 365 directly for authentication (instead of using our custom IdentityServer) which confirms that the redirect is the issue aside from the fact that the authentication is successful. Any ideas what I'm missing or doing wrong? Not sure if this is relevant, but the redirectUrl https://localhost:44352 actually returns error 403 when I load it in a browser. Adding Index.html fixes this, but then the Dialog never calls the DialogMessageReceived. – dmc May 22 '19 at 00:54
  • The index.html file is a default file for almost every webserver. So if you try to navigate to https://localhost:44352/, the browser will actually navigate to https://localhost:44352/index.html, which I believe you are already aware of. Now, the index.html page needs to be coded just like an add-in's page. So it needs `office.js` and another `app.js` included. Then in the `app.js`, you can add `Office.initialize`, and then also invoke `Office.context.ui.messageParent("some message");`. This will trigger the handler for the `DialogMessageReceived` in your add-in. – Outlook Add-ins Team - MSFT May 30 '19 at 00:27
  • Can you confirm that this is what you are doing? if not, please try that. – Outlook Add-ins Team - MSFT May 30 '19 at 00:27
  • Hi @OutlookAdd-insTeam-MSFT Thanks. Nope, my index.html is completely empty :) I only added it to see what happens. But now that you've mentioned that, that completely makes sense! Not sure why I didn't think of that. I'll get back to my new add-in project tomorrow and try that and I'll let you know how it goes. – dmc May 30 '19 at 10:29
  • @OutlookAdd-insTeam-MSFT also I thought I'd mention this but I'm not sure if it's related but as a quick workaround (before your last comment), we decided to get OAuth working in our old VSTO Outlook Add-In and was actually getting a similar behaviour wherein the dialog goes into error when it redirects after the OAuth login. Funny thing is, in our VSTO it was going into error because the dialog redirects to a url for favicon which our server don't have (not sure if it's IE expecting a favicon or the dialog api) . But we were able to work around this in our VSTO...But I still aim to get the – dmc May 30 '19 at 10:35
  • new addin working – dmc May 30 '19 at 10:36
  • Thanks for confirming the issue with the index.html file. We are glad that you were also able to resolve the VSTO issue. That seems quite strange that there was a redirect to the favicon. Please let us know if the proposed changes to the index.html fixes the new add-in. – Outlook Add-ins Team - MSFT May 30 '19 at 22:53

0 Answers0