Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to add client cert in HttpClient created with HttpClientFactory #121

Open
Revsgaard opened this issue Nov 18, 2022 · 1 comment

Comments

@Revsgaard
Copy link
Member

It would be nice to have the possibility to add the certificate for the TLS connection in the HttpClientFactory. In the version I am using I was getting an error (no client cert in the request) and I had to add an HttpClient empty with a handler in the Startup.cs to override the HttpClientFactory configuration.

@Ghostbird
Copy link

Ghostbird commented Apr 25, 2024

This is already supported by the httpClientName parameter of ResolveAsync.

As far as I can see the examples don't demonstrate the use of a named HttpClient.

The standard way to register an HttpClient for mutual TLS is to do it like this:

services
.AddHttpClient("saml")
.ConfigurePrimaryHttpMessageHandler((servicesProvider) =>
{
  var handler = new HttpClientHandler();
  handler.ClientCertificates.AddRange(certificates);
  return handler;
});

Then you can pass the client name saml as httpClientName to ResolveAsync and it works. But maybe that's what you meant? Do you consider this to be a strange override of the configuration? As far as I know this is the normal and proper way you configure the http client factory. Note that you're not adding an "empty" as you call it. You're specifically registering an http client configuration for use with mutual TLS.

Consider this part of the documentation:

The default IHttpClientFactory implementation may cache the underlying HttpMessageHandler instances to improve performance.

Callers are also free to mutate the returned HttpClient instance's public properties as desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants