0Pricing
OAuth2 & OpenID Connect Deep Dive · Aula

O endpoint UserInfo

Aprenda como o endpoint UserInfo do OpenID Connect permite que clientes obtenham declarações verificadas adicionais sobre o usuário autenticado usando um token de acesso.

O endpoint UserInfo é 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.

Beyond the ID Token

The ID token proves who the user is, but to keep it small it may carry only a few claims. The UserInfo endpoint is an OAuth2-protected resource that returns additional claims about the currently authenticated user.

It Is a Protected Resource

UserInfo is not part of the token endpoint — it is a normal protected API. You call it with the access token obtained during the OIDC flow, presented as a Bearer token.

Discovering the Endpoint

Its URL is published in the provider's discovery document under userinfo_endpoint.

GET /.well-known/openid-configuration

{
  "userinfo_endpoint": "https://op.example.com/userinfo"
}

Making the Request

Send a GET (or POST) with the access token in the Authorization header.

GET /userinfo HTTP/1.1
Host: op.example.com
Authorization: Bearer eyJhbGciOiJSUzI1NiIs...

The Response

The response is a JSON object of claims. It must include the sub claim, which must equal the sub in the ID token to prevent token substitution.

{
  "sub": "248289761001",
  "name": "Jane Doe",
  "email": "jane@example.com",
  "email_verified": true,
  "picture": "https://example.com/jane.jpg"
}

Scopes Control Claims

Which claims are returned depends on the scopes granted during authorization:

  • profile — name, picture, locale, etc.
  • email — email, email_verified.
  • address — postal address.
  • phone — phone_number, phone_number_verified.

Verifying the sub

Always confirm the sub from UserInfo matches the sub in the validated ID token. Otherwise an attacker could swap an access token issued for a different user.

if (userInfo.sub !== idTokenClaims.sub) {
  throw new Error('sub mismatch - possible token substitution');
}

Signed and Encrypted Responses

By default UserInfo returns plain JSON. Providers can also return a signed JWT (set via userinfo_signed_response_alg) so the client can verify integrity, and even an encrypted JWT for confidentiality.

ID Token vs UserInfo

When to use which?

  • Put stable, identity-critical claims in the ID token (sub, auth_time).
  • Fetch large or changeable profile data from UserInfo as needed.

This keeps the ID token compact while still giving rich profile access.

Caching Considerations

UserInfo data can change (a user updates their name). Avoid caching it indefinitely; refresh it on login or when you need current values, balancing freshness against extra network calls.

Error Handling

If the access token is expired or invalid, UserInfo returns a 401 with a WWW-Authenticate: Bearer error="invalid_token" header. Handle this by refreshing the token or re-authenticating.

Quick Check

Check your understanding of the UserInfo endpoint.

Recap

The UserInfo endpoint returns additional user claims using the access token.

  • It is a protected resource, discovered via userinfo_endpoint.
  • Returned claims depend on granted scopes.
  • Always verify its sub matches the ID token's sub.
  • Responses can be plain JSON or signed/encrypted JWTs.

Perguntas Frequentes

A aula “O endpoint UserInfo” é grátis?

Sim — o texto completo de “O endpoint UserInfo” é 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 “O endpoint UserInfo”?

Aprenda como o endpoint UserInfo do OpenID Connect permite que clientes obtenham declarações verificadas adicionais sobre o usuário autenticado usando um token de acesso. 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 “O endpoint UserInfo”?

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. OIDC: Camada de Identidade sobre OAuth2
  2. Tokens de ID e Declarações
  3. Visão Geral dos Fluxos OIDC
  4. O endpoint UserInfo
← Voltar para OAuth2 & OpenID Connect Deep Dive