0Pricing
OAuth2 & OpenID Connect Deep Dive · Урок

Конечная точка UserInfo

Узнайте, как конечная точка OpenID Connect UserInfo позволяет клиентам получать дополнительные проверенные утверждения об аутентифицированном пользователе с помощью токена доступа.

«Конечная точка UserInfo» — бесплатный урок OAuth2 & OpenID Connect Deep Dive на CoddyKit. Это урок 4 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения OAuth2 & OpenID Connect Deep Dive, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс OAuth2 & OpenID Connect Deep Dive содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

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.

Часто задаваемые вопросы

Урок «Конечная точка UserInfo» бесплатный?

Да — полный текст урока «Конечная точка UserInfo» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс OAuth2 & OpenID Connect Deep Dive, подпишись на CoddyKit PRO. Курс OAuth2 & OpenID Connect Deep Dive содержит 4 уроков всего.

Чему я научусь в уроке «Конечная точка UserInfo»?

Узнайте, как конечная точка OpenID Connect UserInfo позволяет клиентам получать дополнительные проверенные утверждения об аутентифицированном пользователе с помощью токена доступа. Ты практикуешь OAuth2 & OpenID Connect Deep Dive с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать OAuth2 & OpenID Connect Deep Dive?

Предыдущий опыт не требуется. OAuth2 & OpenID Connect Deep Dive на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 4 из 4.

Сколько времени занимает урок «Конечная точка UserInfo»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке OAuth2 & OpenID Connect Deep Dive?

Да. Каждый урок OAuth2 & OpenID Connect Deep Dive включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. OIDC: уровень идентификации поверх OAuth2
  2. Токены ID и утверждения
  3. Обзор потоков OIDC
  4. Конечная точка UserInfo
← Назад к OAuth2 & OpenID Connect Deep Dive