OIDC UserInfo: retrieve extra user claims safely
Learn when to call UserInfo, how to send an access token, validate the response subject, and handle omitted claims or errors without weakening identity checks.
OIDC UserInfo: retrieve extra user claims safely
The OpenID Connect UserInfo endpoint is an OAuth-protected API for retrieving standard user claims after authentication. The RP sends the access token as a Bearer token and must require the response sub to exactly match the verified ID Token’s sub. If they differ, reject the entire response. UserInfo is optional; it does not replace ID Token validation.
ID Token and UserInfo have different roles
The ID Token lets the RP validate the authentication result. UserInfo is an optional resource endpoint for additional claims such as name or email. Do not send an ID Token to UserInfo or treat access-token claims alone as proof of login. Request scopes such as profile, email, address, or phone only when needed. The user may decline or the OP may omit claims; only sub is required in a successful UserInfo response.
Request flow
Read `userinfo_endpoint` from the trusted OP’s Discovery metadata. Do not use a URL supplied by an arbitrary user.
Securely retain the access token issued during authentication; do not substitute the ID Token or client secret.
Use TLS and send a GET request (OIDC Core also supports POST). Put the token in `Authorization: Bearer <token>`; do not put it in the URL query string, where it can leak into logs.
Check the response status and format. For JSON, validate that `sub` exactly matches the verified ID Token subject before using any other claim.
Minimize and limit retention of retrieved personal claims. Do not log tokens or sensitive response contents.
If the client registration requested signed or encrypted UserInfo responses, process the response according to that registered mode and keys. For signed JWT responses, validate the signature and require iss to match the OP issuer and aud to include or equal the RP client ID.
Safe response handling
**Optional profile claim is absent:** this can be valid due to user choice or OP policy. Make the feature optional; define separately whether your product requires the information.
**401 or `invalid_token`:** check access-token expiry, issuer/audience, and scope; use the normal token-refresh flow if appropriate.
**Missing or mismatched `sub`:** use none of the response. Investigate token/provider linkage and log only a request ID and non-sensitive error code.
**Unexpected JSON/JWT format:** compare with the registered response mode and provider documentation; do not treat parsing failures as identity data.
For account linking, use the verified pair (iss, sub) as the stable external identifier. Do not automatically merge accounts using only email or display name.
References
[OpenID Connect Core 1.0, errata set 2, §5.3](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo)
[RFC 6750 — Bearer Token Usage](https://www.rfc-editor.org/rfc/rfc6750.html)
[OpenID Connect Discovery 1.0, errata set 2](https://openid.net/specs/openid-connect-discovery-1_0.html)