0

I have an endpoint to which I would like to include the X509 certificate that I have just installed as a Current User. I am making use of RestSharp. Below is the code snippet. I would like to find out the best mechanism to do so. I have tried a number of solutions online but to no avail.

        var restClient = new RestClient("");
        var request = new RestRequest(Method.POST);
        request.AddHeader("Accept", "application/json");
        request.AddHeader("Content-Type", "application/json; charset=utf-8");
        request.Parameters.Clear();
        request.AddHeader("Authorization", string.Format("Bearer {0}", Get()));
        request.AddHeader("ClientID", "443E8BE7-3844-4555-898D-93F728B0BD50");
        //request.AddJsonBody(stock);

        //var certfile = Path.Combine("C:\\", "certificate.pfx");
        var certname = "Minet.pfx";
        X509Store store = new X509Store("apo.dmvic.com", StoreLocation.CurrentUser);
        store.Open(OpenFlags.ReadOnly);
        X509Certificate2Collection col = (X509Certificate2Collection)store.Certificates.Find(X509FindType.FindBySubjectName, certname, true);
        X509Certificate2 cert = null;

        request.AddParameter("application/json", Serialize(stock), ParameterType.RequestBody);
        IRestResponse response = await restClient.ExecuteAsync(request);
Nickson
  • 135
  • 12
  • Maybe You could try to set the clientId in your JsonBody with other parameters as the document:https://connect2id.com/products/server/docs/guides/oauth-client-authentication – Ruikai Feng May 10 '22 at 08:58
  • Managed to get a well explained solution from the link: "[https://stackoverflow.com/questions/49069197/add-certificate-on-request-with-restsharp?noredirect=1&lq=1]" – Nickson May 10 '22 at 13:44

0 Answers0