Skip to content

Instantly share code, notes, and snippets.

@StephanyBatista
Created November 4, 2017 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StephanyBatista/68d0071a25307956e170a45d427bced0 to your computer and use it in GitHub Desktop.
Save StephanyBatista/68d0071a25307956e170a45d427bced0 to your computer and use it in GitHub Desktop.
public string Build()
{
var claims = new List<Claim>
{
new Claim(JwtRegisteredClaimNames.Sub, this.subject),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim("NameId", this.nameId)
}
.Union(this.claims.Select(item => new Claim(item.Key, item.Value)));
var token = new JwtSecurityToken(
issuer: this.issuer,
audience: this.audience,
claims: claims,
expires: DateTime.UtcNow.AddMinutes(expiryInMinutes),
signingCredentials: new SigningCredentials(
this.securityKey,
SecurityAlgorithms.HmacSha256));
return new JwtSecurityTokenHandler().WriteToken(token);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment