Asp.Net JWKS的核心AddJwtBearer默认缓存?
Asp.Net core AddJwtBearer default caching of JWKS?
我已经用基本设置配置了 AddJwtBearer,权限是 OpenID-connect 身份服务器。它工作正常,但 JWKS URL 的默认缓存实现是什么,它的超时以及如何配置缓存超时?
services.AddAuthentication().AddJwtBearer(options =>
{
options.Authority = Configuration["Authority"];
options.Audience = Configuration["Audience"];
});
我假设你问的是缓存持续时间。
负责缓存 JWKS 数据的 class 是 ConfigurationManager class,您可以找到 class 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 中使其可编辑。
我已经用基本设置配置了 AddJwtBearer,权限是 OpenID-connect 身份服务器。它工作正常,但 JWKS URL 的默认缓存实现是什么,它的超时以及如何配置缓存超时?
services.AddAuthentication().AddJwtBearer(options =>
{
options.Authority = Configuration["Authority"];
options.Audience = Configuration["Audience"];
});
我假设你问的是缓存持续时间。
负责缓存 JWKS 数据的 class 是 ConfigurationManager class,您可以找到 class 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 中使其可编辑。