static void Main(string[] args) { var handler = new WebRequestHandler(); handler.ClientCertificates.Add( X509.CurrentUser .My .SubjectDistinguishedName .Find("CN=client") .First()); //var handler = new HttpClientHandler //{ // ClientCertificateOptions = ClientCertificateOption.Automatic //}; var client = new HttpClient(handler) { BaseAddress = new Uri("https://web.local:444/api/") }; client.SetBasicAuthentication("bob", "bob"); var result = client.GetStringAsync("identity").Result; Console.WriteLine(JArray.Parse(result)); }
//static TokenResponse GetClientToken() //{ // var client = new OAuth2Client( // new Uri("https://HFL0100:44333/connect/token"), // "silicon", // "F621F470-9731-4A25-80EF-67A6F7C5F4B8"); // ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; // return client.RequestClientCredentialsAsync("api1").Result; //} static TokenResponse RevokeToken(string token) { //var client = new OAuth2Client( // new Uri("https://HFL0100:44333/connect/revocation"), // "carbon", // "21B5F798-BE55-42BC-8AA8-0025B903DC3B"); //ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; //var a = new System.Collections.Generic.Dictionary<string, string>(); //a.Add("token", token); //a.Add("token_type_hint", "access_token"); //return client. (a).Result; var client = new HttpClient(); client.SetBasicAuthentication("carbon", "21B5F798-BE55-42BC-8AA8-0025B903DC3B"); var postBody = new System.Collections.Generic.Dictionary <string, string> { { "token", token }, //{ "token_type_hint", "refresh_token" } { "token_type_hint", "access_token" } }; var result = client.PostAsync("https://HFL0100:44333/connect/revocation", new FormUrlEncodedContent(postBody)).Result; return(null); }
private static string GetToken() { var client = new HttpClient(); client.SetBasicAuthentication("dominick", "abc!123"); // SAML11 //var response = client.GetAsync("https://idsrv.local/issue/simple?realm=urn:testrp&tokenType=saml11").Result; // SAML2 var response = client.GetAsync("https://idsrv.local/issue/simple?realm=urn:testrp&tokenType=saml2").Result; response.EnsureSuccessStatusCode(); var tokenResponse = response.Content.ReadAsStringAsync().Result; var json = JObject.Parse(tokenResponse); return(json["access_token"].ToString()); }