示例#1
0
        public async Task <IActionResult> CallApi()
        {
            //ViewData["Message"] = "Your contact page.";

            //return View();

            //var apiUri = "http://localhost:5002/api/values";

            //var at = await HttpContext.Authentication.GetTokenAsync

            //var client = new HttpClient();

            //var response = await client.GetAsync(apiUri);
            //if (response.IsSuccessStatusCode)
            //{
            //    var json = await response.Content.ReadAsStringAsync();
            //    ViewData["json"] = json;
            //}
            //else
            //{
            //    ViewData["json"] = response.StatusCode;
            //}

            using (var client = new System.Net.Http.HttpClient())
            {
                Microsoft.AspNetCore.Http.Authentication.AuthenticationManager authentication = HttpContext.Authentication;
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", await HttpContext.GetTokenAsync("access_token"));

                var id_token = HttpContext.GetTokenAsync("access_token").Result;

                //var response = await client.GetAsync("http://localhost:5002/api/values");
                var response = await client.GetAsync("http://hiveidentityserver.azurewebsites.net/api/values");

                if (!response.IsSuccessStatusCode)
                {
                    return(View("About"));
                }
            }

            return(View("Index"));
        }
示例#2
0
 protected virtual void UninitializeAuthenticationManager(Microsoft.AspNetCore.Http.Authentication.AuthenticationManager instance)
 {
 }