I have an asp.net core self hosted application within Kestrel. Part of the .UseKestrel options within my Program.cs Main() function is to use the ClientCertificateValidation() functionality to have my own function validate client certificates.
This validation functionality is working fine but my custom validation function needs to be able to add an identity role to the connection that has been validated. I know normally you could just use dependency injection to get HttpContext but since this is a function pointed to within UseKestrel.ClientCertificateValidation within my Program.cs Main() function there is no way to inject the HttpContext dependency that I know of.
Does anyone know some other way to make something like dependency injection work in this scenario or another way to access HttpContext from within my custom certificate validation function? thank you
High level snippet so you can understand what is nested where:
public static void Main(string[] args)
{
.UseKestrel(options =>
{
httpsoptions.ClientCertificateValidation = (cert,chain,errors) => certHelper.ValidateClientCert(cert,chain,errors, null);
}}
public bool ValidateClientCert(X509Certificate2 cert, X509Chain chain, SslPolicyErrors sslerrors, CertificateValidationConfig certvalidationconfig)
{
//How to get HttpContext in this function?
}