Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public string CreateToken(User user)
{
if (user == null)
throw new ArgumentException(nameof(user));
var claims = new[]
{
new Claim(ClaimTypes.NameIdentifier, user.Username)
};
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JwtKey"]));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature);
var token = new JwtSecurityToken(_configuration["JwtIssuer"],
_configuration["JwtAudience"],
claims,
expires: DateTime.Now.AddMonths(1),
signingCredentials: creds);
return new JwtSecurityTokenHandler().WriteToken(token);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.