public string Login() { var request = base.Client.CreateRequest(HttpMethod.Post, "identityserver/connect/token"); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.Authorization = new AuthenticationHeaderValue("Basic", UserLogin.GetClientCredentials()); request.Headers.Host = base.Client.UrlApi.Replace("http://", ""); request.Content = new FormUrlEncodedContent(new Dictionary <string, string> { { "grant_type", "password" }, { "username", base.Client.User.Login }, { "password", base.Client.User.Password }, { "scope", "Agents Monitoring" } }); using (var httpClient = new HttpClient()) using (request) using (var response = httpClient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult()) { if (!response.IsSuccessStatusCode) { throw new Exception($"Erro na comunicação com a API, não foi possivel obter o token. status de erro: {response.StatusCode}"); } dynamic content = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult()); return(content.access_token.ToString()); } }