private string GenerateToken(Common.DataObjects.Users user) { var tokenHandler = new JwtSecurityTokenHandler(); var secretKey = Encoding.ASCII.GetBytes(_appSettings.SecretKey); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new[] { new Claim("idUser", user.idUser.ToString()) }), Expires = DateTime.UtcNow.AddMinutes(15), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(secretKey), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); return(tokenHandler.WriteToken(token)); }
private LoginResponse setResponseValues(Common.DataObjects.Users user) { return(new LoginResponse(user, GenerateToken(user))); }