title: Getting client certificate
body: <p>I need to implement Client Certificate authentication on some of the endpoints in my .NET 5 Web API. So I don't want to enable HTTPS across all endpoint as described <a href="https://docs.microsoft.com/en-us/aspnet/core/security/authentication/certauth?view=aspnetcore-5.0" rel="nofollow noreferrer">here in the MS docs</a>. I am using Kestrel on my local machine and not IIS express or IIS.</p>
  <p>I have tried the following three methods with no luck on either of them:</p>
  <pre><code>var clientCertHeaders = context.HttpContext.Request.Headers;
  </code></pre>
  <p>This one returns the normal headers for the request but no certificate.</p>
  <pre><code>var clientCert = context.HttpContext.Connection.ClientCertificate;
  var clientCertAsync = context.HttpContext.Connection.GetClientCertificateAsync().Result;
  </code></pre>
  <p>These two both return null.</p>
  <p>I've tried applying the following to my services:</p>
  <pre><code>services.AddCertificateForwarding(options =&gt;
      {
          options.CertificateHeader = &quot;X-SSL-CERT&quot;;
          options.HeaderConverter = (headerValue) =&gt;
          {
              X509Certificate2 clientCertificate = null;
  
              if(!string.IsNullOrWhiteSpace(headerValue))
              {
                  var bytes = Encoding.UTF8.GetBytes(headerValue);
                  clientCertificate = new X509Certificate2(bytes);
              }
  
              return clientCertificate;
          };
      });
  </code></pre>
  <p>Even with that enabled in my services I am not retrieving the client certificate.</p>
  <p>I am using Postman to make the requests to the API requests.</p>