public string Create(Funcionario func) { var json = JsonConvert.SerializeObject(func); JObject jObject = JObject.Parse(json); jObject.Property("Id").Remove(); json = jObject.ToString(); var projectJson = new StringContent( json, Encoding.UTF8, "application/json"); var client = new HttpClient(); HttpResponseMessage response = client.PostAsync(Settings.HostApiGateWay + $"employee", projectJson).Result; if (response.IsSuccessStatusCode) { AutenticationServices aut = new AutenticationServices(); response = aut.GenerateUserPass(func); if (response.IsSuccessStatusCode) { return("Funcionário Cadastrado"); } else { return($"Erro ao cadastrar funcionário. {response.ReasonPhrase}"); } } else { return($"Erro ao cadastrar funcionário. {response.ReasonPhrase}"); } }
public async Task <IActionResult> AutenticarAsync(String login, String password) { AutenticationServices aut = new AutenticationServices(); _ = new ClaimsIdentity(); try { HttpResponseMessage responseMessage = await aut.Autenticar(login, password); var customerJsonString = await responseMessage.Content.ReadAsStringAsync(); if (responseMessage.IsSuccessStatusCode) { var userJson = JsonConvert.DeserializeObject <User>(customerJsonString); var claims = new List <Claim> { new Claim(ClaimTypes.Name, userJson.Name), new Claim(ClaimTypes.NameIdentifier, userJson.Login), new Claim(ClaimTypes.Role, userJson.Role), new Claim(ClaimTypes.Rsa, userJson.Token) }; var claimsIdentity = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme); var authProperties = new AuthenticationProperties { //AllowRefresh = <bool>, // Refreshing the authentication session should be allowed. ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(5), // The time at which the authentication ticket expires. A // value set here overrides the ExpireTimeSpan option of // CookieAuthenticationOptions set with AddCookie. //IsPersistent = true, // Whether the authentication session is persisted across // multiple requests. When used with cookies, controls // whether the cookie's lifetime is absolute (matching the // lifetime of the authentication ticket) or session-based. //IssuedUtc = <DateTimeOffset>, // The time at which the authentication ticket was issued. //RedirectUri = <string> // The full path or absolute URI to be used as an http // redirect response value. }; await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties); return(RedirectToAction("Index", "Home")); } else { ViewData["MessageError"] = customerJsonString; return(View("Index", UserLog)); } } catch (Exception e) { ViewData["MessageError"] = e.Message; return(View("Index", UserLog)); } }