Created
December 28, 2019 23:04
-
-
Save xximjasonxx/2c3cacfeb051fcbb7c3098893390408a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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