Exemple #1
0
        private async void getToken()
        {
            authContext = new AuthenticationContext(authority);
            AuthenticationResult authResult = authContext.AcquireToken(apiResourceId, clientId, redirectUri);
            string token = authResult.AccessToken;
            //httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
            //HttpResponseMessage response = await httpClient.GetAsync(apiBaseAddress + "/api/values");
            //string responseString = await response.Content.ReadAsStringAsync();
            //Console.WriteLine("Response = " , responseString);


            PortalApiApp apiapp = new PortalApiApp();
            apiapp.HttpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
            var res1 = apiapp.Values.Get();
            var res2 = apiapp.Values.GetById(1);
            Console.WriteLine("response=" , res1);

        }
Exemple #2
0
        private async void getToken()
        {
            authContext = new AuthenticationContext(authority);
            AuthenticationResult authResult = authContext.AcquireToken(apiResourceId, clientId, redirectUri);
            string token = authResult.AccessToken;
            //httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
            //HttpResponseMessage response = await httpClient.GetAsync(apiBaseAddress + "/api/values");
            //string responseString = await response.Content.ReadAsStringAsync();
            //Console.WriteLine("Response = " , responseString);


            PortalApiApp apiapp = new PortalApiApp();

            apiapp.HttpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
            var res1 = apiapp.Values.Get();
            var res2 = apiapp.Values.GetById(1);

            Console.WriteLine("response=", res1);
        }