1

I am developing a .NET Core 3.1 MVC App and then publishing it to Azure Web App. In the Azure portal, for this hosted app -> I enabled App Service Authentication with AzureAD Login. But then the authentication doesn't work as "User.Identity.IsAuthenticated" is always coming as false in the Controller and I can't fetch other user details I want to, like email etc. Upon searching I found there is a workaround using a Nuget Package for >Net Core 2.2 (https://github.com/MaximRouiller/MaximeRouiller.Azure.AppService.EasyAuth), but I don't see any solution for 3.1.

However, when I setup custom auth by disabling the App Service Authentication in Azure, and set the auth in Startup.cs like this:

services.AddAuthentication(AzureADDefaults.AuthenticationScheme).AddAzureAD(options => Configuration.Bind("AzureAd", options));

and this:

app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints => ...

with config in appsettings.json, the auth works fine and I can fetch user details as well.

But our preferred solution is not to have any auth settings/custom auth in code and rather handle it fully on the portal using Azure AD Easy Auth with .NET Core 3.1 MVC app. Would really appreciate any help.

David Liang
  • 20,385
  • 6
  • 44
  • 70
tanmayghosh2507
  • 773
  • 3
  • 12
  • 31
  • Does your workaround definitely lead to a secure app? How does this approach working during local development? Can you debug locally, or are you restricted to publishing to Azure every time you want to test a change? – Dan Harris Oct 18 '20 at 19:42

1 Answers1

1

This is a known limitation for EasyAuth and .NET Core as documented. The User Principal is implemented differently in .NET Core and EasyAuth can't grab those details automagically like it can in .NETFX. That is why you need to use Maxime's workaround.

Ryan Hill
  • 1,821
  • 2
  • 8
  • 21