public async Task <AuthenticationReponse> Login(User user) { var uri = $"{ApiConfiguration.GetBaseUrl()}/User/login"; var userJson = JsonUtils.Serialize(user); HttpResponseMessage response; try { Log.Debug($"POST request, URI = {uri}"); response = await _httpClient.PostAsync(uri, new StringContent(userJson, Encoding.UTF8, "application/json")); } catch (Exception ex) { Log.Error(ex, "POST User/login failed"); return(new AuthenticationReponse() { WasAuthenticationCorrect = false }); } Token token = null; var authenticationResponse = new AuthenticationReponse() { WasAuthenticationCorrect = response.IsSuccessStatusCode }; if (response.IsSuccessStatusCode) { Log.Debug("POST User/login success"); token = JsonUtils.Deserialize <Token>(await response.Content.ReadAsStringAsync()); authenticationResponse.Roles = token?.Roles.ToList(); authenticationResponse.PatientId = token?.UserId; authenticationResponse.Token = token?.TokenString; AuthenticationUtils.SaveUserToSession(_httpContextAccessor.HttpContext, authenticationResponse); } else { Log.Error($"POST User/login failed, status code = {response.StatusCode}"); } return(authenticationResponse); }