public async Task <IActionResult> GetCoreApiData() { string access_token = await HttpContext.GetTokenAsync("access_token"); using (HttpClient client = new HttpClient()) { client.SetBearerToken(access_token); HttpResponseMessage response = await client.GetAsync("https://localhost:44331/api/hello"); if (response.IsSuccessStatusCode) { string message = await response.Content.ReadAsStringAsync(); return(Ok(message)); } else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { var tokenResponse = await _identityHelpers.RenewToken(); client.SetBearerToken(tokenResponse.AccessToken); response = await client.GetAsync("https://localhost:44331/api/hello"); if (response.IsSuccessStatusCode) { string message = await response.Content.ReadAsStringAsync(); return(Ok(message)); } return(StatusCode(401)); } else { return(BadRequest()); } } }