asp.net标头转发不适用于外部身份提供程序



我在Balzor服务器端应用程序中使用带有AzureAD的asp.net Identity作为外部Identity提供者。在开发环境(localhost(中,登录工作正常。当我将应用程序部署到Nginx后面的docker映像中的内部部署服务器时,它不会。Microsoft发送错误消息AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application。我已将正确的回复URL添加到Azure门户。据我所知,请求使用http,而应该使用https,这导致了错误。

由于Nginx处理安全传输,因此需要转发标头,因此我配置了Nginx并在Startup.ConfigureServices:中启用了标头转发

services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
options.ForwardLimit = 1;
options.KnownProxies.Add(IPAddress.Parse("123.xxx.xxx.xxx"));
});

并且在Startup.Configure:的一开始

app.UseForwardedHeaders();
app.UseHsts();
// should not be necessary but I tried with and without
//app.UseHttpsRedirection();

当我启用日志记录时,我想我看到了从Nginx:转发的正确标头

...
Header: X-Forwarded-For: 123.xxx.xxx.xxx
Header: X-Forwarded-Proto: https
...

在我看来,ExternalLogin.Post中的ChallengeResult()似乎没有使用转发的标头,而是发送http://my.domain.ch/signin-oidc而不是https://作为回复URL,这导致了错误。

我没有主意了,我还能试什么,有什么建议吗?

经过一番挖掘,我发现了错误:我确实添加了错误的代理IP。由于我的asp.net应用程序托管在docker上,我不得不添加docker映像的IP地址作为代理,而不是托管nginx和docker的服务器的IP。事实上,我添加了docker 使用的默认网络

options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("172.17.0.0"), 16));

相关内容

最新更新