I have setup IdentityServer4. As I understand it, my webapi that needs protection, gets the public key from IdentityServer4 and uses this key to validate the signature key of the JWT. I can't seem to find any documentation that describes how often the public key is requested. Is it requested on every validation? Is it cached on the web api that needs validation?
Can I apply some kind of caching of the for the public key, or does the this happen automatically?
For the web api I use standard .NET Core identity to setup validation for the Bearer:
services.AddAuthentication("JWT")
.AddJwtBearer("JWT", options =>
{
options.Authority = "https://identityserver4.tld";
options.RequireHttpsMetadata = false;
options.Audience = "webapi";
});
It seems like I can use some of this code, from here: https://devblogs.microsoft.com/aspnet/jwt-validation-and-authorization-in-asp-net-core/:
var tokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
ValidateIssuer = true,
ValidIssuer = "http://localhost:5000/",
IssuerSigningKey = new X509SecurityKey(new X509Certificate2(certLocation)),
};
app.UseJwtBearerAuthentication(new JwtBearerOptions()
{
Audience = "http://localhost:5001/",
AutomaticAuthenticate = true,
TokenValidationParameters = tokenValidationParameters
});
This will give me the public key locally, but still: how often is the public key fetched when not using the above tokenValidationParameters?