public static async Task <Usuario> Autenticar(RequestAutenticacaoPost request) { Usuario usuario = null; var response = await AutenticacaoApiAdapter.Post(request); if (response.IsValid == 1) { usuario = new Usuario { IdUsuario = 1, Login = request.Email, Token = response.Autenticacao.Token }; } return(usuario); }
public static async Task <AutenticacaoResponsePost> Post(RequestAutenticacaoPost request) { var uri = new Uri(string.Format("{0}/Autenticacao/", urlBase)); AutenticacaoResponsePost retorno = null; using (var cliente = new HttpClient()) { var data = JsonConvert.SerializeObject(request); var content = new StringContent(data, Encoding.UTF8, "application/json"); HttpResponseMessage response = await cliente.PostAsync(uri, content); if (response.IsSuccessStatusCode) { var responseString = await response.Content.ReadAsStringAsync(); retorno = JsonConvert.DeserializeObject <AutenticacaoResponsePost>(responseString); } } return(retorno); }