UserNameClaimType changed from default to 'name', breaking authentication
See original GitHub issueDescribe 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:
- Created a year ago
- Reactions:1
- Comments:13 (8 by maintainers)
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
istrue
while theClaimsIdentity.Name
isnull
.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
:After doing this it works! 🙏
👍 👍