OAuth2 & OpenID Connect Deep Dive · Lección

Validación de claims estándar de tokens de ID

Aprenda los pasos de validación obligatorios para los claims iss, aud, exp, iat y nonce de un token de ID de OpenID Connect.

Lección 4 de 413 pasos

Validación de claims estándar de tokens de ID es una lección gratuita de OAuth2 & OpenID Connect Deep Dive en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de OAuth2 & OpenID Connect Deep Dive, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de OAuth2 & OpenID Connect Deep Dive incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

Signature Is Not Enough

Verifying an ID token's signature proves it came from the provider, but you must also validate its claims to ensure it was meant for you, right now, and is still valid. A valid signature on a token meant for another app is still dangerous.

Validate iss (Issuer)

The iss claim must exactly equal the issuer identifier of your trusted provider, as published in its discovery document. Reject anything else.

if (claims.iss !== 'https://op.example.com') reject();

Validate aud (Audience)

The aud claim must contain your client_id. If aud is an array with multiple values, an azp (authorized party) claim must be present and equal your client_id.

const auds = Array.isArray(claims.aud) ? claims.aud : [claims.aud];
if (!auds.includes(MY_CLIENT_ID)) reject();

Validate exp (Expiration)

The exp claim is a Unix timestamp. The current time must be before exp. Reject expired tokens; allow a small clock skew (a few minutes) at most.

const now = Math.floor(Date.now() / 1000);
if (now >= claims.exp) reject('expired');

Validate iat (Issued At)

The iat claim says when the token was issued. You can reject tokens that are unreasonably old, and use iat to enforce freshness policies.

if (now - claims.iat > MAX_AGE_SECONDS) reject('too old');

Validate nonce

If you sent a nonce in the authentication request, the token's nonce must equal the value you stored. This blocks replay.

if (claims.nonce !== session.nonce) reject('nonce mismatch');

Check azp When Present

The azp (authorized party) claim identifies which client the token was issued to when there are multiple audiences. If present, it must match your client_id.

auth_time and max_age

If you requested max_age or auth_time is essential, verify the auth_time claim shows the user authenticated recently enough; otherwise force re-authentication.

Order of Operations

A safe sequence:

  • Decode and verify the signature (correct alg + key).
  • Validate iss, aud/azp.
  • Validate exp, iat (and auth_time if needed).
  • Validate nonce.

Only after all pass do you trust the identity.

A Combined Check

Bringing the claim validations together:

function validateClaims(c, cfg, now) {
  if (c.iss !== cfg.issuer) throw 'bad iss';
  const auds = [].concat(c.aud);
  if (!auds.includes(cfg.clientId)) throw 'bad aud';
  if (now >= c.exp) throw 'expired';
  if (c.nonce !== cfg.nonce) throw 'bad nonce';
  return true;
}

Use a Vetted Library

Hand-rolling JWT validation invites subtle bugs (alg confusion, skew handling). Prefer a well-maintained OIDC/JWT library and only configure the policy; let it enforce signature and claim checks.

Quick Check

Check your claim-validation knowledge.

Recap

Validating ID token claims goes beyond the signature:

  • iss must match the trusted issuer; aud must include your client_id.
  • exp/iat enforce validity and freshness (allow small skew).
  • nonce blocks replay; check azp with multiple audiences.
  • Prefer a vetted library over hand-rolled checks.
Gratis para empezar

Aprende OAuth2 & OpenID Connect Deep Dive con un tutor de IA — gratis

Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.

Cursos
12
Lecciones
48

Preguntas frecuentes

¿La lección «Validación de claims estándar de tokens de ID» es gratis?

Sí — el texto completo de «Validación de claims estándar de tokens de ID» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de OAuth2 & OpenID Connect Deep Dive, actualiza a CoddyKit PRO. El curso de OAuth2 & OpenID Connect Deep Dive incluye 4 lecciones en total.

¿Qué aprenderé en «Validación de claims estándar de tokens de ID»?

Aprenda los pasos de validación obligatorios para los claims iss, aud, exp, iat y nonce de un token de ID de OpenID Connect. Practicas OAuth2 & OpenID Connect Deep Dive con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar OAuth2 & OpenID Connect Deep Dive?

No se requiere experiencia previa. OAuth2 & OpenID Connect Deep Dive en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Validación de claims estándar de tokens de ID»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de OAuth2 & OpenID Connect Deep Dive?

Sí. Cada lección de OAuth2 & OpenID Connect Deep Dive incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Estructura y firma del ID Token
  2. JWS y conjuntos de JWK
  3. Revocación e introspección de tokens
  4. Validación de claims estándar de tokens de ID
← Volver a OAuth2 & OpenID Connect Deep Dive