Reputation: 121
I've been in the process of updating a .Net Framework 4.8 web & web API to .Net 6. This app is hosted in Azure App Services and used the authentication settings/easy auth for both Azure AD (with personnel accounts) and Google. We allow unauthenticated request, so users can access the home page and the download for the client.
I'm having issues with this after the .Net 6 update, as User.Identity.IsAuthenticated is not being set and I can't retrieve any claims to pick up the users email address. /.auth/login/aad works and I can see information at /.auth/me.
According to documentation from Microsoft, they say that there shouldn't be any code needed, but that is seems to not be the case: https://learn.microsoft.com/en-us/azure/app-service/scenario-secure-app-authentication-app-service#automatic-authentication-provided-by-app-service
I've also found this https://github.com/AzureAD/microsoft-identity-web/wiki/1.2.0#integration-with-azure-app-services-authentication-of-web-apps-running-with-microsoftidentityweb
Things that aren't working:
builder.Services.AddAuthentication(AppServicesAuthenticationDefaults.AuthenticationScheme)
.AddAppServicesAuthentication();
Also not working (have the Azure Ad section created in the app settings)
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));
I have tried many more things over the last couple of days, but can't remember them all.
I would rather have easy auth working with the same end points as this app has a WPF client that is using /.auth/login/aad to login in. I don't want to have to rewrite how auth is done completely in the frontend client.
So how do you set up Easy Auth in Azure App Services and have the claims brought in to the app?
Thank you in advance!
Upvotes: 2
Views: 970
Reputation: 121
While I did try KK.AspNetCore.EasyAuthAuthentication & MaximeRouiller.Azure.AppService.EasyAuth. I finally had success with NEasyAuthMiddleware! That bridged the gap successfully between the App Services Authentication & populating the claims. Nice and clear instructions on how to implement as well.
Upvotes: 1