public IActionResult LoginEncargado([FromBody] LoginModel user) { LoginModel loginResponse = login.GetUserEncargado(user); if (loginResponse == null) { return(Ok(new { Token = "Unauthorized" })); } if (user.userName == loginResponse.userName && user.password == loginResponse.password) { var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("superSecretKey@345")); var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256); var tokeOptions = new JwtSecurityToken( issuer: "http://localhost:44344", audience: "http://localhost:44344", claims: new List <Claim>(), expires: DateTime.Now.AddMinutes(5), signingCredentials: signinCredentials ); var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions); return(Ok(new { Token = tokenString, user = "******", userName = user.userName })); } else { return(Unauthorized()); } }