【问题标题】:Asp.Net core AddJwtBearer default caching of JWKS?JWKS的Asp.Net核心AddJwtBearer默认缓存?
【发布时间】:2021-04-11 12:35:52
【问题描述】:

我已经使用基本设置配置了 AddJwtBearer,并且授权是 OpenID-connect 身份服务器。它工作正常,但是 JWKS URL 的默认缓存实现是什么,它的超时,以及如何配置缓存超时?

services.AddAuthentication().AddJwtBearer(options =>
{
    options.Authority = Configuration["Authority"];
    options.Audience = Configuration["Audience"];
});

【问题讨论】:

    标签: authentication caching .net-core jwt openid-connect


    【解决方案1】:

    我假设您要求询问缓存持续时间。

    负责JWKS数据缓存的类是ConfigurationManager类,可以找到here类的源代码。

    默认缓存时间为 24 小时。

    要在您的 API 中设置它,您可以在 .NET 5 中使用类似于以下的代码对其进行控制:

    services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer(opt =>
        {
          ...
    
          //set refresh interval to 1 hour
          opt.AutomaticRefreshInterval = new TimeSpan(1, 0, 0);
        });
    

    在 .NET 5 之前这是只读的,但他们在 .NET 5 中使其可编辑。

    【讨论】:

      猜你喜欢
      • 2017-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      • 2020-08-07
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多