Saltar al contenido
ecdsa.com
Microsoft.IdentityModel.JsonWebTokens / System.IdentityModel.Tokens.Jwt (.NET).NET

Mensaje de error

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

También se muestra 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"

El texto completo continúa con «Keys tried: …», recuentos de claves y marcadores `[PII of type … is hidden]` (establece `IdentityModelEventSource.ShowPII = true` en desarrollo para verlos). Comprobado con 6.36.0, 7.7.1 y 8.23.0: la 6.x lo formula como «IDX10503: Signature validation failed. Token does not have a kid. Keys tried: …»; la 7.x y la 8.x usan el texto de arriba y notifican un token sin `kid` como IDX10517 «The token's kid is missing».

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

Qué significa

El token identifica su clave de firma con un `kid`, y ninguna clave de `TokenValidationParameters` (`IssuerSigningKey(s)`) ni de la configuración descargada del JWKS de la autoridad tiene ese ID de clave. La firma ni siquiera se llegó a calcular: no había ninguna clave candidata. En ASP.NET Core, el cliente ve `WWW-Authenticate: Bearer error="invalid_token", error_description="The signature key was not found"`.

Por qué ocurre

Cómo solucionarlo

  1. 1.

    Dejar que el controlador obtenga las claves de la autoridad

    Con `Authority` establecido, `JwtBearer` descarga el JWKS del emisor mediante el descubrimiento de OpenID Connect, y lo actualiza periódicamente y también cuando un token indica una clave desconocida (`RefreshOnIssuerKeyNotFound`, activado por defecto).

    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.

    Mostrar los valores ocultos al depurar

    IdentityModel oculta por defecto los ID de clave y el contenido de los tokens en el texto de las excepciones. Habilita `ShowPII` solo en desarrollo para ver qué claves se probaron.

    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;
    }

Errores relacionados

Explorar toda la base de datos de errores de firma