private string GenerateJWT(User user) { var key = new SymmetricSecurityKey(Encoding.ASCII .GetBytes(Environment.GetEnvironmentVariable("Key_Token"))); var credential = new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature); var rights = _userAuthentication.CreateRights(user); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(rights), Expires = DateTime.Now.ToUniversalTime().AddMinutes(GlobalParameters.TokenValidityInMinutes), SigningCredentials = credential }; var tokenHandler = new JwtSecurityTokenHandler(); var token = tokenHandler.CreateToken(tokenDescriptor); return(tokenHandler.WriteToken(token)); }