【问题标题】:Identity Server 4 Client Works Even If Server Down即使服务器关闭,Identity Server 4 客户端也能正常工作
【发布时间】:2021-05-23 08:07:24
【问题描述】:

我有 2 个独立的服务 - 一些 asp.net 核心服务(如果是 FooService,我们称之为)和安装了身份服务器 4 的安全服务(我们称之为 IdentityService)

在 FooService 上,我使用 Identity Server 4 AccessTokenValidation:

                .AddIdentityServerAuthentication("IdentityService",
                options =>
                {
                    options.JwtValidationClockSkew = TimeSpan.Zero;
                    options.Authority = $"http://localhost:5000";
                    options.RequireHttpsMetadata = false;
                    options.SupportedTokens = SupportedTokens.Jwt;
                });

启动后,如果 IdentityServer 关闭,则无法验证 JWT,因为它在地址 options.Authority = $"http://localhost:5000 上找不到 IdnetityServer4 端点 - 这是正常行为。

但是可能存在这样一种情况,当 IdentityServer 仍然处于运行状态时,它创建了 JWT,而 FooService 验证了其中的一些 - 然后 IdentityServer 关闭了 - FooService 仍然可以与这些尚未过期的 JWT 一起使用。此外,它成功验证了 valid 令牌,但它首先出现在请求中。就像,身份服务器 4 客户端缓存身份验证方案或 smth。

我尝试使用一些设置和参数:

 options.SaveToken = false;
 options.BackChannelTimeouts = TimeSpan.FromSeconds(1);
 options.CacheDuration = TimeSpan.FromSeconds(1);
 options.EnableCaching = false;
 options.BackChannelTimeouts = TimeSpan.FromSeconds(1);
 options.DiscoveryDocumentRefreshInterval = TimeSpan.FromMinutes(5);

但它仍然适用于 IdentityServer 关闭。

当 IdentityServer 关闭时,有什么方法可以停止验证 JWT?喜欢强制它使用授权 url 验证令牌吗?谢谢!

【问题讨论】:

    标签: c# asp.net-core identityserver4


    【解决方案1】:

    通过配置管理器的 detault JwtBearer 将签名密钥缓存 24 小时。在 .NET 中,这可以通过以下方式进行配置:

    .AddMyJwtBearer(opt => { opt.AutomaticRefreshInterval = new TimeSpan(1, 0, 0, 0); //1天

     opt.BackchannelTimeout = new TimeSpan(0, 0, 10); //10 seconds 
     ...
    

    }

    另一种方法是缩短访问令牌的生命周期。

    如果配置管理器无法重新加载新的签名密钥,它将每 30 秒重试一次,并继续使用现有密钥,直到可以加载新密钥。

    就像我的一个培训课程中的这张幻灯片显示的那样:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-23
      • 2019-03-26
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      • 1970-01-01
      • 2015-01-01
      相关资源
      最近更新 更多