There’s no explicit support for client certificates in the ServerEventsClient, but you can access the WebRequest used in each of the Requests the ServerEventsClient makes and add it to the Request Filter with something like:
To access the underlying Request object in all ServiceStack Hosts IRequest.OriginalRequest which you’d need to cast to HttpRequest in .NET Core, from their you can access the client certificate, e.g:
GlobalRequestFilters.Add((req,res,dto) => {
var netcoreReq = (HttpRequest)req.OriginalRequest;
var clientCert = netcoreReq.HttpContext.Connection.ClientCertificate;
});
This happens for both my ServerEventsClient and my JsonHttpClient. If I break at the point of adding the certificate it all looks good i.e. it has read my pfx file using the password and I can see the subject etc at the client side.
I’m not 100% it is required for this but I have tried setting <access sslFlags="SslNegotiateCert" /> in the applicationhost.config for IIS Express and I also published it to full IIS with SSL Settings --> Client certificates set to Accept but it makes no difference, the clientCert object is still null.
The certificate has been ordered through RapidSSL so isn’t self signed and the pfx has the private key within it.
Hi, the above issue was because I thought I could get away with not installing the certificate and just point the client to the pfx file but after installing it the code works fine.
To make this easier to configure I’ve also added AllRequestFilters which you can configure once that gets run for all SSE requests which should your configuration down to just:
var sseClient = new ServerEventsClient(baseUrl) {
AllRequestFilters = AddClientCertificate,
};