Skip to content

Instantly share code, notes, and snippets.

Created October 7, 2020 13:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
public static string GenerateToken(string id, int days, string secret)
var tokenDescriptor = new SecurityTokenDescriptor
Subject = new ClaimsIdentity(new[]
new Claim(ClaimTypes.Name, id)
Expires = DateTime.UtcNow.AddDays(Convert.ToInt32(days)),
SigningCredentials = new SigningCredentials(
new SymmetricSecurityKey(Convert.FromBase64String(secret)),
return new JwtSecurityTokenHandler().WriteToken(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment