What the UserInfo endpoint is
The UserInfo endpoint returns claims about the user who signed in: their name, email, locale and whatever else the client was allowed to see. It is part of OpenID Connect Core 1.0, section 5.3. The client calls it with the access token it received after sign-in.
It exists because the ID token is meant to be small. The ID token proves who signed in and when. Profile details can live in the ID token, at UserInfo, or both, depending on how the provider is set up. UserInfo also gives you current values, read at the moment you ask.
From OAuth’s point of view, UserInfo is just a protected resource. The access token is a bearer token, sent as RFC 6750 describes, and the server answers with JSON.
How a UserInfo request works
The client sends GET or POST to the endpoint with the access token in the Authorization header. The token must come from an OpenID Connect request, which means the openid scope was part of it.
GET /realms/acme/protocol/openid-connect/userinfo HTTP/1.1
Host: auth.example.com
Authorization: Bearer SAMPLE_ACCESS_TOKENHTTP/1.1 200 OK
Content-Type: application/json
{
"sub": "1f8f4b3a-sample",
"name": "Alice Example",
"preferred_username": "alice",
"given_name": "Alice",
"family_name": "Example"
}The response always contains sub. Which other claims appear depends on the scopes the user granted, such as profile, email, address or phone, and on how the server maps them. If the client registered for signed or encrypted UserInfo responses, the body is a JWT with the content type application/jwt instead of plain JSON.
Ways to send the token
| Method | How | When |
|---|---|---|
| GET with header | Authorization: Bearer <token> | The default. Use this. |
| POST with header | Same header, empty body | When a client library prefers POST. |
| POST with form body | access_token=<token> in the body | Only when headers are impossible (RFC 6750 section 2.2). |
| DPoP-bound token | Authorization: DPoP <token> plus a DPoP proof header | When the token is bound to a key (RFC 9449). |
What this tool does
The tool builds the UserInfo request and shows it as a curl command and as the raw HTTP request. It does not send anything; the token stays in your browser.
- It builds Keycloak’s UserInfo endpoint from a server URL and realm, or uses any custom URL.
- It sends the token as GET with a header, POST with a header, or POST in a form body.
- For DPoP-bound tokens it uses the
DPoPscheme and adds the proof header you paste in. - It shows a made-up sample response and explains the
subcheck.
It does not create a DPoP proof; make one with the DPoP proof generator. It does not decode or validate the access token either; the JWT decoder reads its claims.
How to use the tool
- Enter your Keycloak server URL and realm, or switch to Custom URL and paste the
userinfo_endpointfrom the discovery document. - Paste an access token that was issued with the
openidscope. - Choose how to send it. Leave it on GET with a header unless you have a reason not to.
- If the token is DPoP-bound, switch the token type to DPoP and paste a fresh proof for this method and URL.
- Copy the curl command and run it, or read the HTTP view.
- Compare
subin the response withsubin the ID token before using any other claim.
UserInfo in Keycloak
In Keycloak the endpoint is https://<host>/realms/<realm>/protocol/openid-connect/userinfo. It is listed as userinfo_endpoint in the realm’s discovery document, which the OIDC discovery viewer can show you.
Which claims appear is decided by protocol mappers in the client scopes the token carries. Each mapper has its own switches for adding the claim to the ID token, the access token and UserInfo. If a claim is in the ID token but missing from UserInfo, or the other way round, check that mapper’s Add to userinfo setting.
Keycloak’s built-in profile and email client scopes map the standard OpenID Connect claims. The OIDC claims reference lists which scope gives which claim, and the scope builder helps you write the scope parameter.
When to call UserInfo
Web apps with a back end
After the token exchange, the server can read the user’s profile from the ID token and call UserInfo only for claims it does not find there. Call it again later if you need current values, for example to refresh a cached display name.
Single-page apps
A browser app can call UserInfo directly with its access token. In Keycloak, the client’s Web origins must allow the app’s origin so the browser may read the response. Keep the token in memory rather than in local storage.
Mobile and desktop apps
Native apps often call UserInfo once after sign-in to fill a profile screen. Keep the access token in the platform’s secure storage, and compare sub with the ID token as every client should.
APIs
An API that receives an access token can call UserInfo with it to learn about the user. Often it is simpler to put the needed claims in the access token itself, or to use introspection, which the introspection request builder builds.
Common errors and how to fix them
401 with invalid_token
RFC 6750 says the error comes back in the WWW-Authenticate response header, for example Bearer error="invalid_token". Common causes:
- The access token expired. Refresh it and try again.
- The token comes from another realm or server than the endpoint you call.
- The header is malformed: a missing
Bearerprefix, a doubled one, or quotes around the token. - The user’s session ended, for example after logout.
403 with insufficient_scope
The token is valid but was not issued for this use. Make sure the authorization request asked for openid, and for the scopes whose claims you expect.
Claims are missing
The scope was not requested or not granted, the user has no value for that attribute, or no mapper adds the claim to UserInfo. Decode the access token and check its scope claim first.
Security notes
- Check
sub. OpenID Connect Core 5.3.2 says thesubin the UserInfo response must equal thesubin the ID token, or the response must not be used. This protects against token substitution. - Send the token in the header, not in the URL. Tokens in query strings end up in logs and browser history.
- Do not use
emailorpreferred_usernameas the user’s key. They can change and can be reused. Useisstogether withsub. - Only trust
emailwhenemail_verifiedis true, if you use the email for anything that matters. - RFC 9700, the OAuth security best current practice, recommends sender-constrained tokens where possible. DPoP is one way to do that; a DPoP-bound token is sent with the
DPoPscheme and a fresh proof.
Best practices
- Read what you need from the ID token first; call UserInfo only for the rest.
- Ask for the smallest set of scopes that gives you the claims you use.
- Cache the result for the length of your own session rather than calling on every page.
- Handle 401 by refreshing the token once, then sending the user through sign-in.
If you would rather have someone else run the Keycloak behind this endpoint, see our pricing for managed realms on a dedicated cluster.