我正在配置一个使用OIDC认证的.netcore应用程序(由IdentityServer提供)。
我已经在我的StartUp中包含了以下代码
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookies",
AutomaticAuthenticate = true,
ExpireTimeSpan = TimeSpan.FromMinutes(60)
});
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
AuthenticationScheme = "oidc",
SignInScheme = "Cookies",
Authority = "https://myauthority",
ClientId = "myclient",
CallbackPath = "/",
ResponseType = "id_token token",
Scope = { "openid", "profile", "email" },
});
该应用程序托管在AWS上,运行在ECS中的Docker中。 它在应用程序负载均衡器后面运行,监听https。
我发现,由于我的应用程序本身未使用https(因为https由负载均衡器终止),OIDC中间件在重定向到OIDC服务器时生成了一个不正确的返回URL-它生成的URL以http://开头。
返回URL由AuthenticationHandler基类中的BuildRedirectUri方法生成。 它只是使用接收请求时的协议 - 似乎没有任何办法覆盖此设置。
protected string BuildRedirectUri(string targetPath)
{
return this.Request.Scheme + "://" + this.Request.Host + this.OriginalPathBase + targetPath;
}
鉴于似乎不可能配置中间件强制进行HTTP重定向,那么我还有哪些其他选项呢?
我应该编写一个“更高”的中间件组件来侦听重定向请求并修改协议吗?还是有更好的方法来解决这个问题?