Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

ASP.Net Core based Service Fabric Web API service with Client Certificate Authentication.

Notifications You must be signed in to change notification settings

SatyKrish/ServiceFabric.Samples.WebApi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ServiceFabric.Samples.WebApi

ASP.Net Core based Service Fabric Web API service with Client Certificate Authentication.

Implementation

This sample implements a Service Fabric stateless frontend web api service with support for client certificate authentication.

Client Certificate Authentication is implemented by defining a custom middleware that uses ITlsConnectionFeature to retrieve and validate client certificate passed in the http request.

CertificateAuthenticationMiddleware.cs

        public async Task Invoke(HttpContext httpContext)
        {
            var tlsConnectionFeature = httpContext.Features.Get<ITlsConnectionFeature>();
            var certificate = await tlsConnectionFeature.GetClientCertificateAsync(httpContext.RequestAborted);

            // Validate the certificate here
        }

And then inject this custom middleware in Startup.cs

Startup.cs

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseMiddleware<CertificateAuthenticationMiddleware>();
            app.UseMvc();
        }

Note

This implementation assumes Client Certificate will always be passed by the client along with Http Request. If you need client certificate negotiation, you will need additional setup.

About

ASP.Net Core based Service Fabric Web API service with Client Certificate Authentication.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published