2

我正在运行 dotnet 2.2 Ocelot apigateway。我想要实现的是将自定义 api 密钥传递给网关并授权令牌沿链继续请求。这工作正常。但是,第二部分是我希望它在 Windows 帐户应用程序池标识下运行,并将请求代理到受 Windows 身份验证保护的端点。这是可以实现的吗?

我的应用程序池在网关上设置为自定义域帐户,但是我通过网关对 Windows 身份验证端点的请求被 401 未经授权的拒绝。而如果我只是将调用更改为非 Windows 身份验证保护的端点,网关会将结果返回给我。

关于这种故障点设置的任何指导要检查,或者这是否不是一种可行的方法?我希望请求将作为自定义身份帐户流动。

启动.cs

public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication(IISDefaults.AuthenticationScheme);


        services.Configure<IISServerOptions>(options =>
        {
            options.AutomaticAuthentication = true;
        });

        services.AddOcelot();
    }

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseAuthentication().UseOcelot().Wait();          
    }

程序.cs

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration(
                      ic => ic.AddJsonFile(Path.Combine("configuration", "configuration.json")))
                .UseStartup<Startup>();

配置.jcs

"ReRoutes": [
{
  "DownstreamPathTemplate": "/{url}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "somesamplehostname.com",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/{url}",
  "UpstreamHttpMethod": [ "Get" ],
  "AuthenticationOptions": {
    "AuthenticationProviderKey": "Windows"
  }
}

]

4

1 回答 1

0

这里是你需要做的:

添加 Windows 身份验证服务: https ://docs.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-3.0&tabs=visual-studio

通过设置 DefaultScheme = "≤NAME>" 为刚刚初始化的服务设置名称标识符;

并将其设置为 Ocelot 中的 AuthenticationProviderKey 参数。

那么它应该像一个魅力一样工作

于 2019-11-04T07:21:45.767 回答