小编dcp*_*986的帖子

请求标头未转发到IdentityServer4

我使用ocelot作为我的微服务的API网关,并使用IdentityServer4进行身份验证。在ocelot配置文件中,我添加了“ AuthenticationOptions”并设置了api密钥。在启动中,添加身份服务器。在身份服务器中,我使用标头中的值来动态构建连接字符串。当我发送获取令牌的请求时,可以在身份服务中访问标头。但是当我发送带有令牌的下一个请求时,原始标头不可用。在身份服务中只能看到“主机”标头。

在将请求路由到身份服务器时,是否可以保留原始标头?

Startup.cs(添加身份服务器)

services
    .AddAuthentication()
    .AddIdentityServerAuthentication("APIParts", options =>
    {
        options.Authority = "http://localhost:60168";
        options.RequireHttpsMetadata = false;
        options.ApiName = "Parts";
        options.SupportedTokens = SupportedTokens.Both;
    });
Run Code Online (Sandbox Code Playgroud)

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": []
  }
}]
Run Code Online (Sandbox Code Playgroud)

c# .net-core identityserver4 ocelot

8
推荐指数
1
解决办法
231
查看次数

标签 统计

.net-core ×1

c# ×1

identityserver4 ×1

ocelot ×1