Get current identity in aspnet core app when azure app service authentication is enabled
Currently when using an aspnet core application with azure app service authentication, the current identity is never set.
Thanks for your feedback!
This is a really neat workaround to get the identity of a currently authenticated user!
At this time we are not considering adding 1st party support for this method to ensure the highest level of compatibility with the multi-tennant hosting level of App Service.
Extracting the currently authenticated user from each incoming request ensures your application can be migrated between web workers and is fully compatible with our scaling operations.
Azure App Service Team
sigh... This is not completed. With .net 4.5 when you have the application running in an app service with ez auth enabled, the current identity is set. You can fetch it using the CurrentPrincipal.
I had to write my own middleware to do this: https://github.com/lpunderscore/azureappservice-authentication-middleware.
It is only tested with AAD auth.
Something like this should be included in .net core and support all auth providers available to app service auth.
It looks like you can get the identity of the current authenticated user in the authorization portion of every HTTP request into your app. The header will be X-MS-CLIENT-PRINCIPAL-ID. Check out this doc for more info: https://docs.microsoft.com/en-us/azure/app-service-api/app-service-api-authentication
Please let me know if there is a specific system call you are trying to use, or if that header has everything you need.
Alex, Azure App Service Team