Created
March 24, 2019 19:27
-
-
Save Mirch/7415884ff1af1cf60161fa723b48b167 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
private string BuildToken(string email) | |
{ | |
var tokenHandler = new JwtSecurityTokenHandler(); | |
var key = Encoding.UTF8.GetBytes(_authenticationSettings.JwtKey); | |
var tokenDescriptor = new SecurityTokenDescriptor | |
{ | |
Subject = new ClaimsIdentity(new Claim[] | |
{ | |
new Claim(ClaimTypes.Name, email) | |
}), | |
Expires = DateTime.UtcNow.AddDays(7), | |
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) | |
}; | |
var jwtToken = tokenHandler.CreateToken(tokenDescriptor); | |
var token = tokenHandler.WriteToken(jwtToken); | |
return token; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment