User.Identity.Name is null for Blazor Wasm hosted in asp.net core.
There is no such claim as name or email. I’m using default template of Visual Studio.
services.AddIdentityServer().AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
services.AddAuthentication().AddIdentityServerJwt();
Am I missing something?
Let me know if you need more information.
3
Answers
Your code does not make any real sense. You don’t host IdentityServer inside a blazor application, instead you have a separate dedicated services that implements OpenIDConnect and that can authenticate users and give out tokens.
In a blazor application you typically have this type of skeleton to configure authentication:
See this article for details:
How do I implement Blazor authentication with OpenID Connect?
I had been struggling with the same issue for few months already. After try many approaches, finally I come out with the solution.
Please let me know if this solve the issue. Thank you 🙂
I had this same issue in an API controller I added to my Blazor WASM hosted server project. Adding this to my
program.cs
file is what fixed it for me:services.Configure<IdentityOptions>(options => options.ClaimsIdentity.UserIdClaimType = ClaimTypes.NameIdentifier);
Source: https://github.com/dotnet/AspNetCore.Docs/issues/17517