0Pricing
OAuth2 & OpenID Connect Deep Dive · Aula

Validando declarações padrão de tokens de ID

Aprenda as etapas obrigatórias para validar as declarações iss, aud, exp, iat e nonce de um token de ID do OpenID Connect.

Validando declarações padrão de tokens de ID é uma aula grátis de OAuth2 & OpenID Connect Deep Dive no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de OAuth2 & OpenID Connect Deep Dive, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de OAuth2 & OpenID Connect Deep Dive inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em 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.

Perguntas Frequentes

A aula “Validando declarações padrão de tokens de ID” é grátis?

Sim — o texto completo de “Validando declarações padrão de tokens de ID” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de OAuth2 & OpenID Connect Deep Dive, atualize para CoddyKit PRO. O curso de OAuth2 & OpenID Connect Deep Dive inclui 4 aulas no total.

O que vou aprender em “Validando declarações padrão de tokens de ID”?

Aprenda as etapas obrigatórias para validar as declarações iss, aud, exp, iat e nonce de um token de ID do OpenID Connect. Você pratica OAuth2 & OpenID Connect Deep Dive com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar OAuth2 & OpenID Connect Deep Dive?

Nenhuma experiência prévia é necessária. OAuth2 & OpenID Connect Deep Dive no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Validando declarações padrão de tokens de ID”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de OAuth2 & OpenID Connect Deep Dive?

Sim. Cada aula de OAuth2 & OpenID Connect Deep Dive inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Estrutura e Assinatura do Token de ID
  2. JWS e Conjuntos de JWK
  3. Revogação e Introspecção de Tokens
  4. Validando declarações padrão de tokens de ID
← Voltar para OAuth2 & OpenID Connect Deep Dive