how to get claims of another user using ASP.NET Core

偶尔善良 提交于 2020-01-03 13:40:12

问题


I'm still learning identities with asp.net core. I'm doing a claims-based token authorization. Most examples are about "Current" logged in user. In my case my RPC service is receiving a username & password of some user in the identity DB. I need to

  1. verify that a user with such credentials exist
  2. get all the claims of that user

so to verify if the user exists, I'm using this:

ApplicationUser applicationUser = await _userManager.FindByNameAsync(username);
bool exist = await _userManager.CheckPasswordAsync(applicationUser, password);
if (!exist)
{
    // log and return
}

I don't know how to do the 2nd step properly. I guess I could do a simple linq to collect all user's claims, but I'm sure there is a better way using the identity methods.


回答1:


You need to use the GetClaimsAsync() method. For example:

var claims = await _userManager.GetClaimsAsync(applicationUser);

See MSDN



来源:https://stackoverflow.com/questions/40490820/how-to-get-claims-of-another-user-using-asp-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!