若在ASP.NET Core中使用代理服务器,则可能会遇到此问题。在这种情况下,您需要确保使用"UseForwardedHeaders"中间件,并在添加OpenIdConnect时将authority选项设置为当前主机地址,而不是代理服务器地址。示例代码如下所示:
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddMvc();
// Add authentication with OpenIdConnect
services.AddAuthentication(options => {
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options =>
{
options.Authority = "https://current-host-address/";
options.ClientId = "your-client-id";
options.ClientSecret = "your-client-secret";
options.CallbackPath = "/signin-oidc";
// ... other settings
});
// Use forwarded headers middleware to set the correct host address
app.UseForwardedHeaders();
}