You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding HttpClient examples to send the certificate (cert_auth.md) (dotnet#16354)
* Adding HttpClient examples to send the certificate
* removing this as this is an Azure example
* Using FromBase64String for Azure example
* removing this as it is not need for Azure
* updating PR, Azure needs no forwarding, default covered by middleware, example for a custom proxy added
* Added missing comma
* adding a note about CertificateForwardingMiddleware which is required for Azure certificate forwarding
Copy file name to clipboardExpand all lines: aspnetcore/security/authentication/certauth.md
+73-31Lines changed: 73 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -231,19 +231,26 @@ See the [host and deploy documentation](xref:host-and-deploy/proxy-load-balancer
231
231
232
232
### Use certificate authentication in Azure Web Apps
233
233
234
+
No forwarding configuration is required for Azure. This is already setup in the certificate forwarding middleware.
235
+
236
+
> [!NOTE]
237
+
> This requires that the CertificateForwardingMiddleware is present.
238
+
239
+
### Use certificate authentication in custom web proxies
240
+
234
241
The `AddCertificateForwarding` method is used to specify:
235
242
236
243
* The client header name.
237
244
* How the certificate is to be loaded (using the `HeaderConverter` property).
238
245
239
-
In Azure Web Apps, the certificate is passed as a custom request header named `X-ARR-ClientCert`. To use it, configure certificate forwarding in `Startup.ConfigureServices`:
246
+
In custom web proxies, the certificate is passed as a custom request header, for example `X-SSL-CERT`. To use it, configure certificate forwarding in `Startup.ConfigureServices`:
#### Implement an HttpClient using a certificate and the HttpClientHandler
325
332
326
-
The web API client uses an `HttpClient`, which was created using an `IHttpClientFactory` instance. This doesn't provide a way to define a handler for the `HttpClient`, so use an `HttpRequestMessage` to add the certificate to the `X-ARR-ClientCert`request header. The certificate is added as a string using the `GetRawCertDataString` method.
333
+
The HttpClientHandler could be added directly in the constructor of the HttpClient class. Care should be taken when creating instances of the HttpClient. The HttpClient will then send the certificate with each request.
In the following example, a client certificate is added to a HttpClientHandler using the ClientCertificates property from the handler. This handler can then be used in a named instance of a HttpClient using the ConfigurePrimaryHttpMessageHandler method. This is setup in the Startup class in the
The IHttpClientFactory can then be used to get the named instance with the handler and the certificate. The CreateClient method with the name of the client defined in the Startup class is used to get the instance. The HTTP request can be sent using the client as required.
0 commit comments