I'm able to access my token and add it to the RestSharp RestClient
//Create rest client.
IRestClient client = new RestClient("https://localhost.fiddler:44300");
var webClientCertificate = GetWebClientCertificate();
//Don't ask why... I'm getting an abiguous ref here.
client.ClientCertificates = new System.Security.Cryptography.X509Certificates.X509Certificate2Collection(){webClientCertificate};
IRestRequest request = new RestRequest("api/get-secure-data", Method.GET);
var response = client.Execute(request);
GetWebClientCertificate:
public X509Certificate2 GetWebClientCertificate()
{
//Access certificate store
X509Store certificateStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certificateStore.Open(OpenFlags.ReadOnly);
var certificateCollection = certificateStore.Certificates.Find(X509FindType.FindBySubjectName, "web-client",false);
var webClientCertificate = certificateCollection[0];
certificateStore.Close();
return webClientCertificate;
}
I get the cert and I can see that it's added to the client.
Server Code
[HttpGet]
[Route("api/get-secure-data")]
[RequireHttps]
public IHttpActionResult GetSecureData()
{
try
{
X509Certificate2 cert = Request.GetClientCertificate(); //returns null
PublicKey clientKey = cert.PublicKey;
return Ok(clientKey);
}
catch (Exception exception)
{
return InternalServerError(exception);
}
}
fiddler shows no auth header, what am I missing?