internal static async Task <TaskStatus> LogIn(HttpClient httpClient, string username, string password) { HttpContent content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("grant_type", "password"), new KeyValuePair <string, string>("username", username), new KeyValuePair <string, string>("password", password), }); HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "/token"); requestMessage.Content = content; HttpResponseMessage responseMessage = null; try { responseMessage = await httpClient.SendAsync(requestMessage); } catch (Exception ex) { TaskStatus status = ApiHelper.ServerIsOpen(ex); return(status.IsError ? status : new TaskStatus(true, status.Message)); } ResponseToken token = await responseMessage.Content.ReadAsAsync <ResponseToken>(); if (responseMessage.IsSuccessStatusCode) { ApiHelper.AddAuthorization(token.token_type, token.access_token); return(new TaskStatus(false)); } else { return(new TaskStatus(true, token.error_description)); } }