Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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( => 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(
return new JwtSecurityTokenHandler().WriteToken(token);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment