in TailwindTraders.Website/Source/Tailwind.Traders.Web/Standalone/Controllers/LoginController.cs [39:67]
private AccessToken CreateAccessToken(string username)
{
var claims = new[]
{
new Claim(ClaimTypes.Name, username),
new Claim(ClaimTypes.Sid, Guid.NewGuid().ToString())
};
// demo only, do not do this in real life!
const string defaultSecurityKey = Constants.DefaultJwtSigningKey;
var securityKey = config["SecurityKey"] ?? defaultSecurityKey;
var encoding = Encoding.UTF8.GetBytes(securityKey);
var key = new SymmetricSecurityKey(encoding);
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var expiresInDays = 365;
var token = new JwtSecurityToken(
claims: claims,
issuer: config["Issuer"] ?? "TailWindWebsite",
expires: DateTime.Now.AddDays(expiresInDays),
signingCredentials: creds);
return new AccessToken
{
Token = new JwtSecurityTokenHandler().WriteToken(token),
ExpiresIn = expiresInDays * 24 * 60 * 60,
TokenType = "bearer"
};
}