public async Task AuthorizeAsync(string userName, string password, bool isRemember = false) { var request = new HttpRequestMessage() { RequestUri = new Uri(_httpService.BaseAddress + "token"), Method = HttpMethod.Post, Content = new StringContent($"grant_type=password&username={userName}&password={password}") }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); request.Headers.UserAgent.ParseAdd("TMS ToDo Explorer UWP"); var response = await _httpService.Client.SendAsync(request); if (!response.IsSuccessStatusCode) { if (response.StatusCode == HttpStatusCode.BadRequest) { throw new BadRequestException(response); } throw new HttpResponseException(response); } AccessToken = JsonConvert.DeserializeObject <Token>(await response.Content.ReadAsStringAsync()); if (AccessToken == null) { throw new HttpResponseException(response); } IsAuthenticated = true; _httpService.ConfigureAuthorization(AccessToken); if (isRemember) { Credential = _credentialService.Save(userName, password); } }