【发布时间】:2019-04-05 07:19:08
【问题描述】:
我正在配置一个 .netcore 应用程序以使用 OIDC 身份验证(由 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 重定向,我还有哪些其他选择?
我是否应该编写一个“更高”的中间件组件来监听重定向请求并修改协议?或者有没有更好的方法来解决这个问题?
【问题讨论】:
-
你能解决这个问题吗?我遇到了同样的情况,正如您对@davidg 提供的答案所评论的那样,添加中间件似乎没有效果。
标签: c# identityserver3 identityserver4 openid-connect