Search code examples
azure-active-directoryoffice365-apps

OAuth2/OpenID authentication login redirect not displaying in phone Office Web app or IOS Office Web app


I'm currently try to develop an Office web addin, integrated in the Outlook (Read and Compose).
Everything works fine, except the authentication process.
Indeed, We have to authenticate the user from within Azure AD to access another application (our own application using the Azure AD Architecture where we need to call some web apis)

The solution I used is issued from this great article from Richard diZerega :
Connecting to SharePoint from Azure web app

This solution (we opt for the last scenario) works fine in our Desktop and Web based solution.

But it clearely doesn't work in phone web app , IOS app.

The problem comes from the popup Windows allowing the user to log in.

Actually, window.open, window.location.replace etc ... don't work "as expected" in our Outlook frame.
Everytime it open a popup window. (This is a good solution when the user use the desktop or web Outlook application) I remember read somewhere that the Office Window where the plugin is loaded, is a secured Window where we can't do any sort of redirection.

I tried to work with ADAL.js, enabling the implicit flow of course, but the problem is the same. We need to redirect the frame to the Azure AD login page.

Finally, the question is : How to deal with an OAuth2/OpenID authentication in an Outlook web addin, and when we want it to work with all kind of devices ?


Solution

  • Login in Adal.Js is a page redirect by default. You don't have pop up issue. Adal.Js gets idtoken initially to be used for your own back end. It also does iframe requests to get access tokens for API endpoints. Office365 APIs support CORS api requests and you can use adal.js to send requests. Tokens will be attached to the requests if you define the endpoints in the config.

    You can read about examples here: https://blogs.office.com/2015/03/06/increasing-opportunities-javascript-developers-office-365-platform/

    or here : http://www.andrewconnell.com/blog/adal-js-cors-with-o365-apis-files-sharepoint