caddy 后面的 duende 的 Identityserver 在 openid 配置中有 http

Identityserver from duende behind caddy has http in the openid config

我运行正在使用 caddy 反向代理后面的 duende 身份服务器,并且两者都 运行正在 docer 容器中。我还在另一个容器中 运行 一个 blazor 服务器应用程序,我想在其中进行身份验证。在本地这工作正常,但是当我 运行 它们在代理后面时,.well-known/openid-configuration 提供 http:// 端点,因此 blazor 应用程序无法进行身份验证,因为它不允许通过 http 进行身份验证。 http 在 caddy 和身份服务器之间。由于这是在机器上 运行ning 并且没有穿越邪恶的网络,所以我认为这可能没问题。我想我需要做的是,通过 https 而不是 http 为身份服务器和代理生成证书。但我也不想一直手动生成证书或留意它。启动中的 UseHttpsRedirect() 使我的服务对 caddy 不可用,只是简单地 运行 在没有证书的情况下在 443 上启用它也中断了 caddy 和 indentity 服务器之间的调用。我还发现了一个提示,我可以在选项中将 IssuerUri 设置为 https,但这不会影响其他端点,因此我仍然无法进行身份验证,因为在 openid 配置中仍然有 http 端点(发行者除外)

有人知道我如何做到这一点而不是手动创建证书吗?

球童文件:

identity.fading-flame.com {
    reverse_proxy http://identity-server-prod
}

IS 的启动

services.AddIdentityServer(options =>
                {
                    options.IssuerUri = $"https://{Environment.GetEnvironmentVariable("IDENTITY_BASE_URI")}";
                    options.EmitStaticAudienceClaim = true;
                })

或者像球童那样的东西? Identityserver4 openid-configuration omits host port running nginx reverse proxy

好的,我在 GH 上发现了一个与 nginx 类似的帖子,但答案仍然适用于 caddy。

https://github.com/IdentityServer/IdentityServer4/issues/324#issuecomment-324133883

基本上,在身份服务器中间件之前,我有这个:

    app.Use((context, next) =>
    {
        context.Request.Scheme = "https";
        return next();
    });
    
    app.UseIdentityServer();

然后 openid 配置 returns https 端点,一切都很好。对于 blazor 服务器应用程序,我仍然缺少的是同样的东西,因为我在那里也使用 auth 框架并且重定向 url 是 http 因为与球童相同的原因。所以在 blazor 应用程序中,这修复了身份服务器的回调,很确定它必须在身份验证之前,但我没有测试它:

    app.Use((context, next) =>
    {
        context.Request.Scheme = "https";
        return next();
    });
    
    app.UseAuthentication();

希望有一天这对某人有所帮助 ;)