我正在运行dotnet 2.2 Ocelot apigateway。我想要实现的目标是将自定义api密钥传递给网关,并授权令牌沿链进行请求。一切正常。但是,第二点是我希望它在Windows帐户应用程序池标识下运行,并将请求代理到Windows身份验证受保护的终结点中。这是可以实现的吗?
我的应用程序池在网关上设置为自定义域帐户,但是通过401未经授权,我通过网关对Windows身份验证的端点的请求被拒绝。而如果我只是将呼叫更改为不受Windows auth保护的端点,则网关会将结果返回给我。
有关此故障设置的任何指南都需要检查,或者这是否不可行?我希望请求将作为自定义身份帐户流动。
Startup.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();
}
Program.cs
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(
ic => ic.AddJsonFile(Path.Combine("configuration", "configuration.json")))
.UseStartup<Startup>();
configuration.jcs
"ReRoutes": [
{
"DownstreamPathTemplate": "/{url}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "somesamplehostname.com",
"Port": 80
}
],
"UpstreamPathTemplate": "/{url}",
"UpstreamHttpMethod": [ "Get" ],
"AuthenticationOptions": {
"AuthenticationProviderKey": "Windows"
}
}
]
答案 0 :(得分:0)
嘘,这是您需要做的:
添加Windows身份验证服务: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-3.0&tabs=visual-studio
通过将DefaultScheme =“≤NAME>”设置为刚刚初始化的服务的名称标识符;
并将其设置为Ocelot中的AuthenticationProviderKey参数。
那它应该像魅力一样工作