Can't get claims from JWT token with ASP.NET Core

前端 未结 4 1087
南笙
南笙 2021-02-12 22:49

I\'m trying to do a really simple implementation of JWT bearer authentication with ASP.NET Core. I return a response from a controller a bit like this:

    var i         


        
4条回答
  •  眼角桃花
    2021-02-12 23:28

    Access User.Claims instead of ClaimsPrinciple.Current.Claims.

    From Introduction to Identity at docs.asp.net:

    ...inside the HomeController.Index action method, you can view the User.Claims details.

    Here is the relevant source code from the MVC repository:

    public ClaimsPrincipal User
    {
       get
       {
           return HttpContext?.User;
       }
    }
    

提交回复
热议问题