private IEnumerable <Claim> GetTokenClaims(current_user_access access_user) { return(new List <Claim> { new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(JwtRegisteredClaimNames.Email, access_user.Email), new Claim(JwtRegisteredClaimNames.Typ, string.Join(",", access_user.UserType)), new Claim(JwtRegisteredClaimNames.GivenName, access_user.UserName), new Claim(JwtRegisteredClaimNames.Exp, access_user.ExpireTime.ToShortDateString()) }); }
public string RenderAccessToken(current_user_access access_user) { var audience = _configuration["TokenAuthentication:siteUrl"]; var jwtToken = new JwtSecurityToken( issuer: audience, audience: audience, claims: GetTokenClaims(access_user), expires: access_user.ExpireTime, signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Constant.SecretSercurityKey)), SecurityAlgorithms.HmacSha256) ); return(new JwtSecurityTokenHandler().WriteToken(jwtToken)); }