public async Task <AuthenticatedUser> Authenticate(string username, string password) { var data = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("grant_type", "password"), new KeyValuePair <string, string>("username", username), new KeyValuePair <string, string>("password", password) }); using (HttpResponseMessage response = await ApiClient.PostAsync("/Token", data)) { if (response.IsSuccessStatusCode) { var result = await response.Content.ReadAsStringAsync(); AuthenticatedUser authenticatedUser = JsonConvert.DeserializeObject <AuthenticatedUser>(result); return(authenticatedUser); } throw new Exception(response.ReasonPhrase); } }
public async Task <AuthenticatedUser> AuthenticateAsync(string username, string password) { FormUrlEncodedContent data = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("grant_type", "password"), new KeyValuePair <string, string>("username", username), new KeyValuePair <string, string>("password", password), }); using (HttpResponseMessage response = await ApiClient.PostAsync("/token", data)) { if (response.IsSuccessStatusCode) { AuthenticatedUser result = await response.Content.ReadAsAsync <AuthenticatedUser>(); return(result); } else { throw new Exception(response.ReasonPhrase); } } }