public async Task <JObject> ProtectedWebApiCaller(string webApiUrl) { AuthenticationResult result = await _authenticationResult.GetAuthenticationResult(); var client = _factory.CreateClient("protectedapi"); if (result != null) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", result.AccessToken); } else { _logger.LogError("Class: ProtectedWebApiCallerService, Method: ProtectedWebApiCaller, Error: The access token is equal to null."); return(null); } try { HttpResponseMessage response = await client.GetAsync(webApiUrl); string json = await response.Content.ReadAsStringAsync(); var res = JsonConvert.DeserializeObject <JObject>(json); return(res); } catch (Exception ex) { _logger.LogError($"Class: ProtectedWebApiCallerService, Method: ProtectedWebApiCaller, {Environment.NewLine} Exception: {ex}, {Environment.NewLine} Message: {ex.Message}, {Environment.NewLine} StackTrace: {ex.StackTrace}"); return(null); } }