设置值:
List<Claim> claims = new List<Claim>()获取:
{
new Claim(ClaimTypes.NameIdentifier, userNo),
new Claim(ClaimTypes.Name, userName),
new Claim("ntAccount", card.ntAccount),
new Claim("userNo", card.userNo),
//new Claim(ClaimTypes.Role, "admin")
};
var claims = HttpContext.User.Claims;
//获取用户token
var access_token = HttpContext.GetTokenAsync("access_token");
var accessToken = HttpContext.GetTokenAsync(OpenIdConnectParameterNames.AccessToken);
var refresh_token = HttpContext.GetTokenAsync("refresh_token");
var refreshToken = HttpContext.GetTokenAsync(OpenIdConnectParameterNames.RefreshToken);
//获取用户信息
var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
var username = HttpContext.User.FindFirst(d => d.Type == "preferred_username")?.Value;
var roleName = HttpContext.User.FindFirst(ClaimTypes.Role)?.Value;
var clientId = HttpContext.User.FindFirst(d => d.Type == "client_id")?.Value;
var user_id = HttpContext.User.FindFirst("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value;
var role_name = HttpContext.User.FindFirst(d => d.Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/role")?.Value;
- 本文标题: NETCore之Token信息Claims获取用户登录信息
- 文章分类:【.NET/Web】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.