-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Labels
Description
Is your feature request related to a problem? Please describe.
If your dev servers have locally generated certificates, SSL validation would fail. It is possible to fix by modifying the ApiClient.cs and overriding its handling.
Describe the solution you'd like
Add the possibility to override the handling for the SSL errors
Describe alternatives you've considered
Using a public virtual method to do so; I've edited the mustache file to do it on my end, as the client is generated often and editing it each time is painful.
Additional context
This is what I ended up doing for now, better alternatives are welcome :)
var clientOptions = new RestClientOptions(baseUrl)
{
ClientCertificates = configuration.ClientCertificates,
CookieContainer = cookies,
MaxTimeout = configuration.Timeout,
Proxy = configuration.Proxy,
UserAgent = configuration.UserAgent,
RemoteCertificateValidationCallback = RemoteCertificateValidationCallback
}; /// <summary>
/// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication.
/// </summary>
/// <param name="sender">An object that contains state information for this validation.</param>
/// <param name="certificate">The certificate used to authenticate the remote party.</param>
/// <param name="chain">The chain of certificate authorities associated with the remote certificate.</param>
/// <param name="sslpolicyerrors">One or more errors associated with the remote certificate.</param>
/// <returns>A Boolean value that determines whether the specified certificate is accepted for authentication.</returns>
public virtual bool RemoteCertificateValidationCallback(object sender, X509Certificate? certificate, X509Chain? chain, SslPolicyErrors sslpolicyerrors)
{
return sslpolicyerrors == SslPolicyErrors.None;
}Then on my inherited ApiClient, I can do :
public class LocalApiClient : ApiClient
{
public override bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors)
{
#if DEBUG
return ignoreSslErrors || sslpolicyerrors == SslPolicyErrors.None;
#else
return sslpolicyerrors == SslPolicyErrors.None;
#endif
}
}Or any other more advanced SSL/certificate validation if needed.
Reactions are currently unavailable