Page 1 of 1

How to stay inside outlook Add-in when authenticating

PostPosted: Wed Jan 11, 2023 11:53 pm
by swingman
Hi all,

now another interesting problem, Servoy is running inside an iFrame in Microsoft Outlook and I want to Authenticate against Azure AD.
Code: Select all
function authorize() {
   var service = plugins.oauth.getOAuthService(plugins.oauth.OAuthProviders.MICROSOFT_AD, clientId, clientSecret, 'User.read', state, callback);
   application.showURL(service.getAuthorizationURL());
}

function microsoft_ad_callback(a,args) {
   var service = plugins.oauth.getOAuthService(plugins.oauth.OAuthProviders.MICROSOFT_AD, clientId, clientSecret, 'User.read', state, callback);
   service.setAccessToken(args.code);
   /** @type {plugins.oauth.OAuthResponseJSON} */
   var response = service.executeGetRequest("https://graph.microsoft.com/v1.0/me");
   if (response.getCode() == 200) {
      var json = response.getAsJSON();
                //more code here
        } else {
                //failed
        }
}


Now, application.showURL, simply adds another tab to my web browser, displays the authentication dialog from Microsoft. If I authenticate, I end up with a normal Servoy running in my browser.
I want to stay within Microsoft Outlook, how can I show the service.getAuthorizationURL() so I can authenticate?

Re: How to stay inside outlook Add-in when authenticating

PostPosted: Thu Jan 12, 2023 11:05 am
by emera
You need to use
application.showURL(service.getAuthorizationURL(), "_self");
because application.showURL(service.getAuthorizationURL()) shows it by default in a new tab.

Re: How to stay inside outlook Add-in when authenticating

PostPosted: Thu Jan 12, 2023 1:46 pm
by swingman
Hi, I tried that but I still ended up in the default browser.
After a rethink, I have decided as the user is already logged into their computer and email, I can trust Microsoft to tell me who the user is and check if the user has an account which is not disabled on Servoy and simply let them in.