Table of Contents

Class CertificateHttpClientBuilderExtensions

Namespace
Steeltoe.Security.Authorization.Certificate
Assembly
Steeltoe.Security.Authorization.Certificate.dll
public static class CertificateHttpClientBuilderExtensions
Inheritance
CertificateHttpClientBuilderExtensions
Inherited Members

Methods

AddAppInstanceIdentityCertificate(IHttpClientBuilder)

Binds certificate paths in configuration to CertificateOptions representing the application instance and attaches the certificate to outbound requests by injecting it as an HTTP header.

[Obsolete("Injecting a certificate into a header is no longer recommended because it may enable identity spoofing. This overload will be removed in a future release. Use AddAppInstanceIdentityCertificateForMutualTls instead.")]
public static IHttpClientBuilder AddAppInstanceIdentityCertificate(this IHttpClientBuilder builder)

Parameters

builder IHttpClientBuilder

The IHttpClientBuilder to configure an HttpClient for sending a client certificate.

Returns

IHttpClientBuilder

The incoming builder so that additional calls can be chained.

AddAppInstanceIdentityCertificate(IHttpClientBuilder, string)

Binds certificate paths in configuration to CertificateOptions representing the application instance and attaches the certificate to outbound requests by injecting it as an HTTP header.

[Obsolete("Configuring a custom header name is no longer recommended because it may enable identity spoofing. This overload will be removed in a future release. Use AddAppInstanceIdentityCertificateForMutualTls instead.")]
public static IHttpClientBuilder AddAppInstanceIdentityCertificate(this IHttpClientBuilder builder, string certificateHeaderName)

Parameters

builder IHttpClientBuilder

The IHttpClientBuilder to configure an HttpClient for sending a client certificate.

certificateHeaderName string

The name of the HTTP header used to pass the certificate.

Returns

IHttpClientBuilder

AddAppInstanceIdentityCertificateForMutualTls(IHttpClientBuilder)

Binds certificate paths in configuration to CertificateOptions representing the application instance and attaches the certificate to outbound requests using mTLS.

public static IHttpClientBuilder AddAppInstanceIdentityCertificateForMutualTls(this IHttpClientBuilder builder)

Parameters

builder IHttpClientBuilder

The IHttpClientBuilder to configure an HttpClient for sending a client certificate.

Returns

IHttpClientBuilder

The incoming builder so that additional calls can be chained.

Remarks

mTLS requires SocketsHttpHandler as the primary handler. If a SocketsHttpHandler has already been configured (for example, via ConfigurePrimaryHttpMessageHandler<THandler>(IHttpClientBuilder)), it is reused and the client certificate is applied to it. If no handler was explicitly configured, a new SocketsHttpHandler is created. On .NET 9 and later, configuring any other primary handler type causes an InvalidOperationException when the first request is made; on .NET 8, it is silently replaced. This configuration always runs after any calls to ConfigurePrimaryHttpMessageHandler<THandler>(IHttpClientBuilder), regardless of registration order.

AddClientCertificate(IHttpClientBuilder, string)

Binds certificate paths in configuration to CertificateOptions and attaches the certificate to outbound requests by injecting it as an HTTP header.

[Obsolete("Injecting a certificate into a header is no longer recommended because it may enable identity spoofing. This overload will be removed in a future release. Use AddClientCertificateForMutualTls instead.")]
public static IHttpClientBuilder AddClientCertificate(this IHttpClientBuilder builder, string certificateName)

Parameters

builder IHttpClientBuilder

The IHttpClientBuilder to configure an HttpClient for sending a client certificate.

certificateName string

The name of the certificate used in configuration.

Returns

IHttpClientBuilder

The incoming builder so that additional calls can be chained.

AddClientCertificate(IHttpClientBuilder, string, string)

Binds certificate paths in configuration to CertificateOptions and attaches the certificate to outbound requests by injecting it as an HTTP header.

[Obsolete("Configuring a custom header name is no longer recommended because it may enable identity spoofing. This overload will be removed in a future release. Use AddClientCertificateForMutualTls instead.")]
public static IHttpClientBuilder AddClientCertificate(this IHttpClientBuilder builder, string certificateName, string certificateHeaderName)

Parameters

builder IHttpClientBuilder

The IHttpClientBuilder to configure an HttpClient for sending a client certificate.

certificateName string

The name of the certificate used in configuration.

certificateHeaderName string

The name of the HTTP header used to pass the certificate.

Returns

IHttpClientBuilder

AddClientCertificateForMutualTls(IHttpClientBuilder, string)

Binds certificate paths in configuration to CertificateOptions and attaches the certificate to outbound requests using mTLS.

public static IHttpClientBuilder AddClientCertificateForMutualTls(this IHttpClientBuilder builder, string certificateName)

Parameters

builder IHttpClientBuilder

The IHttpClientBuilder to configure an HttpClient for sending a client certificate.

certificateName string

The name of the certificate used in configuration.

Returns

IHttpClientBuilder

The incoming builder so that additional calls can be chained.

Remarks

mTLS requires SocketsHttpHandler as the primary handler. If a SocketsHttpHandler has already been configured (for example, via ConfigurePrimaryHttpMessageHandler<THandler>(IHttpClientBuilder)), it is reused and the client certificate is applied to it. If no handler was explicitly configured, a new SocketsHttpHandler is created. On .NET 9 and later, configuring any other primary handler type causes an InvalidOperationException when the first request is made; on .NET 8, it is silently replaced. This configuration always runs after any calls to ConfigurePrimaryHttpMessageHandler<THandler>(IHttpClientBuilder), regardless of registration order.