I have an MVC web application that uses OWIN / openid connect to authenticate users with https://login.windows.net/common/. It's based on the azure / office 365 sample here: https://github.com/OfficeDev/Research-Project-Code-Sample.
If I understand the authentication flow correctly it goes like this:
- the app checks (based on a cookie) if there is already an authenticated user
- if not, then it redirects to the providers authorization page (login.microsoftonline.com)
- the page redirects back to my app with an auth code
- My app calls the provider again with the auth code for an access token (or is it an id_token?)
- My app (the OWIN component) extracts the various openid properties and sets them on the threads current principal
That works fine.
Now I want my MVC application to call my Web API application. The Web API application is never called directly by the browser but always by the MVC client. The Web API application doesn't use cookies and can't redirect if a request is made with incorrect or stale authentication info. The Web API application should be able to be called with the authentication token that the MVC application got and use this to set a ClaimsPrincipal on the executing thread. An alternative might be for me to use some custom solution in the MVC app for encrypting the user info and sending it on to the Web API, but this would be a last resort. I would much prefer to use standard owin.