question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UserNameClaimType changed from default to 'name', breaking authentication

See original GitHub issue

Describe the bug

I am using Azure Signal R on a Blazor Server side app. Everything had been working well for last 2 years in .net 5. Last week I upgraded the app to .net 6 and authentication broke.

After investigation, it is turns out that Azure SignalR is the likely cause - it changes the UserName Claim Type from http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name to name - thereby causing User.Identity.Name to be null, even though User.Identity.IsAuthenticated is true.

For more details, see this: https://stackoverflow.com/questions/72267840/in-aspnet-6-running-on-azure-app-services-user-identity-name-is-null-because-th

In order to get authentication working again I have to do this, when configuring Authentication.

                   if (IsProduction)
                   {
                       options.ClaimsIdentity.UserNameClaimType = "name";
                   }

To Reproduce

Reproducing this has proven challenging thus far. I created a brand new Blazor Server project using ASPNET 6 and Azure Signal R, and deployed that to Azure App Server. The results there do not match what I am seeing on my production project.

There, (in the fresh ASPNET 6 project), the UserNameClaimType remains intact (http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name), but a new claim, unique_name is added by the Azure SignalR middleware, containing the same value as the UserName claim.

Authentication continues to work. If my upgraded ASPNET 5 behaved like this, it would be perfect.

Would you know in what circumstances the UserNameClaimTypes are transformed as described above? That could help me find a solution.

Exceptions (if any)

No Exceptions are thrown - just that User.Identity.Name is null

Further technical details

  • Your Azure SignalR SDK version : 1.17
  • Your Server ASPNETCORE : 6
  • Your SignalR Client SDK version : ASPNET CORE 6

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Mike-E-angelocommented, Jul 30, 2022

I am incorporating Azure SignalR Service into my Blazor Server-side application and encountered this issue that has taken a few hours to track down.

ClaimsIdentity.IsAuthenticated is true while the ClaimsIdentity.Name is null.

EDIT: OK… after taking some time to read, the answer is to add the following direct dependency in the csproj that is referencing Microsoft.AspNetCore.Authentication.JwtBearer:

<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.22.0" />

After doing this it works! 🙏

1reaction
josephsctancommented, May 20, 2022

👍 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

In ASPNET 6 running on Azure App Services, User.Identity. ...
Prod environment (Azure App Service) : Authentication is broken. When someone logs in, 'Identity.IsAuthenticated' is true, but 'Identity.Name' ...
Read more >
Breaking changes 3.3.0
The ExternalRedirectKeys property is no longer used and can be removed. The UsernameClaimType property was renamed ExternalProvidersConfiguration.
Read more >
Configure ASP.NET Core Identity
Understand ASP.NET Core Identity default values and learn how to configure Identity properties to use custom values.
Read more >
Breaking change: Default authentication scheme - .NET
Learn about the breaking change in ASP.NET Core 7.0 where a singly registered authentication scheme will cause it to be used as the...
Read more >
Jwt claim typ. Sorted by: 7. Improve this question. This name i
By default Name claim type maps to UniqueName, you need to change it's mapping. Instead of a content byte array, a JWT payload...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found