Skip to content

Instantly share code, notes, and snippets.

@evgomes
Last active November 6, 2018 23:54
Show Gist options
  • Save evgomes/54a3b702dff80afc1b6bfa346a217126 to your computer and use it in GitHub Desktop.
Save evgomes/54a3b702dff80afc1b6bfa346a217126 to your computer and use it in GitHub Desktop.
Get claims method from the token handler of JWT API.
private IEnumerable<Claim> GetClaims(User user)
{
var claims = new List<Claim>
{
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.Sub, user.Email)
};
foreach (var userRole in user.UserRoles)
{
claims.Add(new Claim(ClaimTypes.Role, userRole.Role.Name));
}
return claims;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment