I am using ocelot as API gateway for my microservices with IdentityServer4 for authentication. In the ocelot config file I added "AuthenticationOptions" and set the api key. In the Startup I add the Identity server. In the identity server I use value from header to dynamically build the connection string. When I send the request to get token, headers are accessible in the identity service. But when I send next request with the token original headers are not available. Only "Host" header can be visible in the identity service.
Is there a way to keep the original header while routing the request to identity server?
Startup.cs (Add identity server)
services
.AddAuthentication()
.AddIdentityServerAuthentication("APIParts", options =>
{
options.Authority = "http://localhost:60168";
options.RequireHttpsMetadata = false;
options.ApiName = "Parts";
options.SupportedTokens = SupportedTokens.Both;
});
ocelot.json
ReRoutes": [
{
"DownstreamPathTemplate": "/connect/token",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 60168
}
],
"UpstreamPathTemplate": "/token",
"UpstreamHttpMethod": [ "Post" ]
},
{
"DownstreamPathTemplate": "/api/Parts/Inventory",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 65241
}
],
"UpstreamPathTemplate": "/api/Parts/Inventory",
"AuthenticationOptions": {
"AuthenticationProviderKey": "APIParts",
"AllowedScopes": []
}
}]