Must the API application make calls to ID server application if both are owned by my team?
Sorry if it is a stupid question, I'm kind of new to the topic, but I would actually want to make sure the API does NOT make calls to ID server or they happen rarely. Is this feasible?
If the API app has the public key configured locally and it can check the token signature with this key, why is a request to the ID server needed? I mean if it is not a public third party API that needs to obtain the public key but a private app where I can configure the signing certificate.
So I guess what I am trying to ask is:
-
Is it possible to configure everything needed to validate the token in the API and tell the API "trust this", so calls to the configuration endpoint are not performed.
-
Given the fact that the API and ID server applications are "owned" by my team, is there any reason not to do this, in terms of security risks?
The reasons to ask for this are related to performance and also I would like to get rid of the error "Unable to obtain configuration from: '..../.well-known/openid-configuration'. which occurs in the API for example during deployment downtime of ID server.
On API level I am using Microsoft.AspNetCore.Authentication.JwtBearer, no IdentityServer4 middleware and here is my configuration:
app.UseJwtBearerAuthentication(new JwtBearerOptions
{
Audience = Configuration[ConfigurationKeys.UrlsIdentityServer] + "/resources",
Authority = Configuration[ConfigurationKeys.UrlsIdentityServer],
RequireHttpsMetadata = !IsDevelopment(),
TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = Configuration[ConfigurationKeys.UrlsIdentityServer],
RequireSignedTokens = true,
ValidateIssuerSigningKey = true,
IssuerSigningKey = new X509SecurityKey(cert),
ValidateAudience = true,
ValidAudience = Configuration[ConfigurationKeys.UrlsIdentityServer] + "/resources",
RequireExpirationTime = true,
ValidateLifetime = true,
RoleClaimType = "role"
}
});
I am passing my self-signed certificate, the same I am using on ID server level, to the IssuerSigningKey = new X509SecurityKey(cert).
OK this puts some light on it: https://github.com/aspnet/Security/blob/99aa3bd35dd5fbe46a93eef8a2c8ab1f9fe8d05b/src/Microsoft.AspNetCore.Authentication.JwtBearer/JwtBearerHandler.cs
In short: The property Configuration of JwtBearerOptions can be used for static configuration.
Since there are quite a lot options to configure - it is worth investigating how ofthen the dynamic configuration endpoint can be called based on configuration. For example, I noticed I can switch of the 'RefreshOnIssuerKeyNotFound' property of JwtBearerOptions since I am not using rollover keys. This will reduce some calls to the ID server due to invalid tokens. Also, I have the feeling that the JwtBearerHandler might be initialized as singleton, meaning that the configuration will be obtained only on API restart (on the first request actually) which is pretty OK even if it is an external call, but I have to investigate further. If anyone knows more about how often and in which cases is the server called, as well as arguments against static config please share.
The JWT middleware downloads a copy of the discovery document at startup time and then by default every 24h. if signature validation fails, they schedule a new download.
You can configure everything statically - but lose all the benefits of automatic configuration.
Thanks for clearing this out! "You can configure everything statically - but lose all the benefits of automatic configuration." this makes sense.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.