Issue with Long-Lived Token: "The signature key was not found" despite ValidateIssuerSigningKey = false #182
-
Dear Duende Support :-), IdentityServer with the highest license tier, version 7.0.8. As part of a specific implementation, we decided to issue long-lived access tokens (valid for more than 5 years). These tokens are generated via code, as shown below: var client = await _clientStore.FindClientByIdAsync(scimClient.ClientId);
if (client == null)
{
throw new Exception("Client not found");
}
var validatedRequest = new TokenCreationRequest
{
ValidatedRequest = new ValidatedRequest
{
Client = client,
ClientId = client.ClientId,
AccessTokenLifetime = client.AccessTokenLifetime,
},
ValidatedResources = new ResourceValidationResult
{
Resources = new Resources(
new List<IdentityResource>(),
new List<ApiResource>(),
client.AllowedScopes.Select(scope => new ApiScope(scope)).ToList())
},
};
var token = await _tokenService.CreateAccessTokenAsync(validatedRequest);
token.Audiences.Add(client.ClientId);
token.Issuer = _configuration.GetPublicOrigin();
foreach (var scope in client.AllowedScopes)
{
token.Claims.Add(new Claim("scope", scope));
}
var securityToken = await _tokenService.CreateSecurityTokenAsync(token);
return (securityToken, token.Lifetime, scimClient.ClientId); The token is then validated in a resource API as follows: services
.AddAuthentication()
.AddJwtBearer(tokenConfiguration.Name, options =>
{
options.Authority = tokenConfiguration.Authority;
options.Audience = tokenConfiguration.ClientId;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = tokenConfiguration.Authority,
ValidateLifetime = false,
ValidateAudience = true,
ValidAudience = tokenConfiguration.ClientId,
ValidateIssuerSigningKey = false,
};
}); As you can see, ValidateIssuerSigningKey is explicitly set to false. Despite this, we repeatedly receive the following error response:
This is the client configuration:
Our question is: How can this error occur if ValidateIssuerSigningKey is disabled? Is there something we may be missing in the token generation or validation pipeline that still requires the signature key? Thank you in advance for your support. Best regards, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
First of all I need to point out that issuing JWTs with a lifetime of 5 years is something I would never recommend. JWTs are self-contained tokens and it is very rare that someone has implemented a revocation mechanism for them. That means that if a token is leaked, the only way to prevent misuse of it is to change the token signing keys which will affect all existing tokens. If there is a need for long-lived tokens, our recommendation is to use reference tokens. We do have a sample on Personal Access Tokens that shows how to do that. The "The signature key was not found" error message indicates that when validating the signature of the JWT, the signing key was not found. The JWT header contains a key id ( To troubleshoot please:
The |
Beta Was this translation helpful? Give feedback.
-
Based on the discussion above, it seems that using reference tokens is the most suitable approach in this case, especially since they do not rely on key rotation. This avoids issues related to missing signing keys or JWKS configuration. Thanks again for the helpful input! |
Beta Was this translation helpful? Give feedback.
Based on the discussion above, it seems that using reference tokens is the most suitable approach in this case, especially since they do not rely on key rotation. This avoids issues related to missing signing keys or JWKS configuration.
Thanks again for the helpful input!