Pular para o conteúdo
ecdsa.com
Microsoft.IdentityModel.JsonWebTokens / System.IdentityModel.Tokens.Jwt (.NET).NET

Mensagem de erro

IDX10503: Signature validation failed. The token's kid is: '2026-10', but did not match any keys in TokenValidationParameters or Configuration.

Também aparece como

  • IDX10503: Signature validation failed. Token does not have a kid. Keys tried:
  • IDX10517: Signature validation failed. The token's kid is missing.
  • Bearer error="invalid_token", error_description="The signature key was not found"

O texto completo continua com “Keys tried: …”, contagens de chaves e marcadores `[PII of type … is hidden]` (defina `IdentityModelEventSource.ShowPII = true` em desenvolvimento para vê-los). Verificado nas versões 6.36.0, 7.7.1 e 8.23.0: a 6.x escreve “IDX10503: Signature validation failed. Token does not have a kid. Keys tried: …”; a 7.x e a 8.x usam o texto acima e informam um token sem `kid` como IDX10517 “The token's kid is missing”.

Microsoft.IdentityModel.JsonWebTokens / System.IdentityModel.Tokens.Jwt (.NET) — SecurityTokenSignatureKeyNotFoundException

O que significa

O token identifica a chave de assinatura com um `kid`, e nenhuma chave em `TokenValidationParameters` (`IssuerSigningKey(s)`) ou na configuração baixada do JWKS da autoridade tem esse ID de chave. A assinatura nem chegou a ser calculada — não havia chave candidata. No ASP.NET Core, o cliente vê `WWW-Authenticate: Bearer error="invalid_token", error_description="The signature key was not found"`.

Por que acontece

Como corrigir

  1. 1.

    Deixar o handler buscar as chaves na autoridade

    Com `Authority` definido, o `JwtBearer` baixa o JWKS do emissor pela descoberta do OpenID Connect e o atualiza periodicamente, além de sempre que um token indica uma chave desconhecida (`RefreshOnIssuerKeyNotFound`, ativado por padrão).

    csharp
    builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer(options =>
        {
            // Keys come from {Authority}/.well-known/openid-configuration -> jwks_uri and are refreshed automatically.
            options.Authority = "https://login.example.com/";
            options.Audience = "api://orders";
        });
  2. 2.

    Revelar os valores ocultos durante a depuração

    O IdentityModel oculta por padrão os IDs de chave e o conteúdo dos tokens no texto das exceções. Ative `ShowPII` apenas em desenvolvimento para ver quais chaves foram testadas.

    csharp
    // Development only: show the hidden values ([PII of type ... is hidden]) in IDX messages.
    if (builder.Environment.IsDevelopment())
    {
        Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;
    }

Erros relacionados

Ver toda a base de erros de assinatura