in src/app/ContosoTraders.Api.Products/Controllers/LoginController.cs [32:59]
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!
var securityKey = config["SecurityKey"] ?? AuthConstants.DefaultJwtSigningKey;
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"] ?? "ContosoWebsite",
expires: DateTime.Now.AddDays(expiresInDays),
signingCredentials: creds);
return new AccessToken
{
Token = new JwtSecurityTokenHandler().WriteToken(token),
ExpiresIn = expiresInDays * 24 * 60 * 60,
TokenType = "bearer"
};
}