Unable to use dynamic client certificate with HttpClientFactory
See original GitHub issueHello, I used HttpClient before:
var certificate = ...
var password = ...
using (var clientHandler = new HttpClientHandler())
{
clientHandler.ClientCertificates.Add(new X509Certificate2(certificate , password ));
using (var certificateClient = new HttpClient(clientHandler))
{
// ...
}
}
The certificate is dynamic and is obtained from the database.
unable to services.AddHttpClient
for all certificates in ConfigureServices
.
Can you tell me how it should be implemented?
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Dynamically add a client certificate to a HttpClient
I have an application that needs to call the same endpoint with different client certificates (We are calling an API on behalf of...
Read more >Using Certificate Authentication with IHttpClientFactory and ...
This article shows how an HttpClient instance could be setup to send a certificate to an API to use for certificate authentication.
Read more >Dynamic certificate update is failing in HTTPClient Handler ...
I have made an api in .net core 3.1 and created a custom HTTP Client Handler to manage dynamic certificates per http call...
Read more >Configure certificate authentication in ASP.NET Core
This check validates that the certificate presented by the client has the Client Authentication extended key use (EKU), or no EKUs at all....
Read more >How to use IHttpClientFactory in ASP.NET Core
NET Core 2.1, IHttpClientFactory provides a central place to name, configure, and create HttpClient instances and manages the pooling and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can use
ConfigurePrimaryHttpMessageHandler
to set up the message handler with a certificate:The callback is generally called when the HttpClient is being constructed, so it does not happen at the startup time but on-demand when the client is being used. This means that you can effectively configure the certificate at run-time.
It’s also possible to depend on the service provider there, so you could have some other dependency that provides you with the right certificate:
Did anyone figure this out? With the SocketsHttpHandler it’s possible to write logic to that runs per connection to determine which client certificate to use.