Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
716 views
in Technique[技术] by (71.8m points)

authentication - Asp.Net core AddJwtBearer default caching of JWKS?

I have configured the AddJwtBearer with basic settings and the authority is an OpenID-connect identity server. It is working fine but what is the default caching implementation of the JWKS URL, its timeout, and how to configure the caching timeout?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I assume you ask asking for the caching duration.

The class that is in charge of the caching of the JWKS data is the ConfigurationManager class and You can find the source code for the class here.

The default caching time is 24 hours.

To set it in your API, you can control it in .NET 5 using:

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(opt => { ...

    //set refresh interval to 1 hour
    opt.AutomaticRefreshInterval = new TimeSpan(1, 0, 0);
});

Before .NET 5 this was readonly, but they made it editable in .NET 5.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...