UseJwtBearerAuthentication does not get User.Identity.Name populated

后端 未结 2 797
南方客
南方客 2020-12-18 18:19

I am trying to use JWT for authentication mechanism in ASP.NET Core Web API project. Suppose this project has not MVC part and does no

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 18:50

    in your claims (second code snippet) I can only see this:

    new Claim(ClaimTypes.NameIdentifier, applicationUser.UserName),
    

    but you need to add this:

    new Claim(ClaimTypes.Name, applicationUser.UserName),
    

    then User.Identity.Name should contain the username.

提交回复
热议问题