Я использую JWT и добавляю их так:
private ClaimsIdentity GetClaims(User user)
{
List<Claim> claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.NameIdentifier, user.UserName));
claims.Add(new Claim(ClaimTypes.Role, user.Role));
claims.Add(new Claim(CustomClaimsTypes.IsActive, user.IsActive.ToString()));
return new ClaimsIdentity(claims);
}
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = GetClaims(user),
Expires = claimTime,
Audience = auth.Audience,
Issuer = auth.Issuer,
SigningCredentials = auth.Credentials
};
И получаю в контроллере:
var name = HttpContext.User.Claims.FirstOrDefault(f => f.Type == ClaimTypes.NameIdentifier).Value;