Search code examples
c#identityserver4

How can I override the method 'ConfigureAuthentication' IdentityServer4


The main ConfigureAuthentication is in StartupDomainServiceBase.cs in a separate container. I´m working with Webhooks so my token is in the body from the request (it is usually in header). So I tried my best and added options.TokenRetriever = CustomTokenRetriever.FromBody to the main Authentication function, but this affects the other containers that are reading the token from header. So I have to set this configuration only in the Startup.cs from the Container where my Project is. How can I do that?

Startup.cs inherits from StartupDomainService , and so as I can see, they override some methods from there in order to costumize them. (for example ConfigurCustomServices or ConfigureAuthorization). But when I tried to override ConfigureAuthentication it says that it can´t be done because its sealed, but the other methods are also sealed... I don´t get it...

Has someone an idea or a suggestion? It would be very helpful.

(btw. im working with c#, Visual Studio, Docker Container, nginx serv)


Solution

  • Perhaps add a custom middleware in the ASP.NET Core pipeline, that can inspect the incoming requests and if a token is found in the body, then it is added as a header in the HttpContext, so that the authentication system is happy?

    Alternative you can add a proxy in front of your service (like Yarp) that does this transformation for you.