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.
I had been struggling with the same issue for few months already. After try many approaches, finally I come out with the solution.
using System.Linq;
services.AddIdentityServer().AddApiAuthorization<ApplicationUser,
ApplicationDbContext>(opt =>
{
opt.IdentityResources["openid"].UserClaims.Add("name");
opt.ApiResources.Single().UserClaims.Add("name");
});
services.AddAuthentication().AddIdentityServerJwt();
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With