在自定义身份验证下运行的 Ocelot 网关 dotnet 核心尝试使用应用程序池标识发出下游请求



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

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

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

启动.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"
}
}

]

所以这里是你需要做的:

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

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

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

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

最新更新