0

I am able to successfully send requests to a sandbox via postman, given by a provider following their specs (see images below)

Successful request (see below)

Pfx Cert

In order to do that, aside from the respective headers and parameters (see image 2) I have to add a ssl/Tls certificate (.pfx) given that the server requires a 2 way handshake so it needs SSl client certificate:

enter image description here

Authorization (see below).

enter image description here

Headers (see below) enter image description here

Body (see below)

enter image description here

Now, I am trying to do ir programatically using dotnet core 6, but I keep running into the same problem:

Error

And here is my code:

public static string GetAccessToken(IConfiguration _config)
    {
        string UserName = Environment.GetEnvironmentVariable("USER_NAME");
        string Password = Environment.GetEnvironmentVariable("PASSWORD");
        

        var client = new RestClient("https://connect2.xyz.com/auth/token");
       
        var request = new RestRequest();
        X509Certificate2 FullChainCertificate = new X509Certificate2("Path/to/Cert/cert.pfx", "test");
        client.Options.ClientCertificates = new X509CertificateCollection() { FullChainCertificate };
        client.Options.Proxy = new WebProxy("connect2.xyz.com");
        var restrequest = new RestRequest();
        restrequest.Method = Method.Get;
        restrequest.AddHeader("Accept", "*/*");
        restrequest.AddHeader("Cache-Control", "no-cache");
        restrequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
        restrequest.AddHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes($"{UserName}:{Password}")));
        restrequest.AddParameter("grant_type", "client_credentials");
        RestResponse response = client.Execute(restrequest);


        AccessTokenPointClickCare accessToken = JsonConvert.DeserializeObject<AccessTokenPointClickCare>(response.Content);
        string strToken = accessToken.access_token;

        return strToken;
    }

Now, as the error seems to show, it has to do with the certificates (apparently), but I don't know if something in the code is wrong, or if I'm missing something, etc...

It is worth noting that this code did run in someone else's pc with the same set-up, but of course with that person's own pfx, but for the rest, it is essentially the same, and not to mention that it does work on my postman.

Finally, as the title on this question, the only thing I can think it might also be affecting the request is the host. If I reference the postman, there is a field where I have to place the host name of the server https://connect2.xyz.com/auth/token

enter image description here

gustavexx
  • 25
  • 1
  • 5

1 Answers1

0

So made it work by changing to a new Windows 10. Researching in other Stackoverflow threads found the answer: .NET CORE 5 '''HandshakeFailure'" when making HTTPS request

So I conclude it has to do with the cyphers

gustavexx
  • 25
  • 1
  • 5
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 03 '22 at 18:02