gomij

gomij

  • 854
  • 836
  • 886

How to set long expiry to JWT Token?

Feb 20 2024 12:03 PM
private string GenerateJSONWebToken(pswd user)
{
    var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]));
    var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
 
    var token = new JwtSecurityToken(_config["Jwt:Issuer"],
      _config["Jwt:Issuer"],
      null,
      expires: DateTime.Now.AddYears(100),
      signingCredentials: credentials);

    return new JwtSecurityTokenHandler().WriteToken(token);
}

Answers (3)