How can I share Azure Active Directory authentication between server side and client script?

169 views Asked by At

I currently have an MVC app that's using the Microsoft.Owin.Security.WSFederation package for authentication with Azure's Active Directory. This lets me use the Authorize attribute on my controllers to redirect users to the Microsoft login site.

I now have the requirement to add access to a WebAPI project that will be hosted on a different domain but will use the same AD store.

I've managed to pull together something using the ADAL JS library provided by Azure but this gives the following process:

  • user visits site and is redirected to Azure login
  • user logs in and is returned to site
  • JS code checks for login and redirects to Azure
  • user is already authenticated so redirects back to site with token
  • JS picks up token, stores it, and redirects to the original page

So it works, but involves 4 redirects, which seems like a huge overhead.

I thought that there might be some way of pulling a bearer token out of the authorisation credentials returned when the WSFederation succeeds but I can't see anything like that in the data. And, even if I could, I don't know how I'd be able to then refresh the token from the client script. So I strongly suspect I'm doing something fundamentally wrong.

What would be the best process for sharing authentication between the two sites?

0

There are 0 answers