static void Main(string[] args) { HttpClientCallerService httpService = new HttpClientCallerService(new DefaultHttpClientCaller()); string defaultResponse = httpService.GET("http://www.google.com.tr", "", null, ""); httpService = new HttpClientCallerService(new MockHttpClientCaller()); string mockResponse = httpService.GET("http://www.google.com.tr", "", null, ""); }
static void Main(string[] args) { //Auth and get access token from auth server first. var authServerUrl = "http://localhost:5003/api/auth/login"; var loginCredentials = new UserLogin() { Username = "******", Password = "******" }; string loginCredJson = JsonConvert.SerializeObject(loginCredentials); string accessTokenResponse = new HttpClientCallerService(new DefaultHttpClientCaller()).POST(authServerUrl, loginCredJson, "application/json"); AccessTokenResponse authResponse = JsonConvert.DeserializeObject <AccessTokenResponse>(accessTokenResponse); Dictionary <string, string> httpHeaders = new Dictionary <string, string>() { { "Authorization", "Bearer " + authResponse.AccessToken } }; //Send same access token to ger response from WEB API1 var client1Url = "http://localhost:5000/api/values"; System.Console.WriteLine(new HttpClientCallerService(new DefaultHttpClientCaller()).GET(client1Url, httpHeaders, "application/json")); //Send same access token to ger response from WEB API2 var client2Url = "http://localhost:5002/api/values"; System.Console.WriteLine(new HttpClientCallerService(new DefaultHttpClientCaller()).GET(client2Url, httpHeaders, "application/json")); System.Console.Read(); }
public static IntrospectTokenResponse IntrospectAccessToken(KeyCloakOAuthClientConfig keyCloakClientOption, string token) { string introspectTokenJson = new HttpClientCallerService(new DefaultHttpClientCaller()).POST(keyCloakClientOption.TokenIntrospectEndpoint, string.Format("token={0}&client_id={1}&client_secret={2}", token, keyCloakClientOption.Client_Id, keyCloakClientOption.Client_Secret), "application/x-www-form-urlencoded"); return(JsonConvert.DeserializeObject <IntrospectTokenResponse>(introspectTokenJson)); }
public static AccessTokenResponse GetAccessToken(KeyCloakOAuthAPIConfig keyCloakServerOptions) { string accessTokenJson = new HttpClientCallerService(new DefaultHttpClientCaller()).POST(keyCloakServerOptions.AccessTokenEndpoint, string.Format("grant_type={0}&client_id={1}&client_secret={2}", keyCloakServerOptions.Grant_Type, keyCloakServerOptions.Client_Id, keyCloakServerOptions.Client_Secret), "application/x-www-form-urlencoded"); return(JsonConvert.DeserializeObject <AccessTokenResponse>(accessTokenJson)); }