How OAuth reports errors
OAuth 2.0 errors are short, fixed codes such as invalid_grant or invalid_client. RFC 6749 defines the first set, and later specifications add their own. The code tells your program what kind of problem it is. An optional error_description gives a human-readable reason, and an optional error_uri points to a page about it.
Where the error appears depends on the endpoint. The same code can mean slightly different things in different places, so it helps to know which request produced it.
From the authorization endpoint
Errors in the browser flow come back as parameters on the redirect to your app, usually in the query string. RFC 6749 section 4.1.2.1 defines them. If the server cannot trust the redirect URI or the client id, it does not redirect at all and shows an error page instead.
https://app.example.com/callback?error=login_required&error_description=Login+required&state=Zq3v8sample7KpW2From the token endpoint
Errors from back-channel requests come as a JSON body, usually with HTTP 400, or 401 for a failed client authentication. RFC 6749 section 5.2 defines them.
HTTP/1.1 400 Bad Request
Content-Type: application/json
{
"error": "invalid_grant",
"error_description": "Code not valid"
}From an API
An API that rejects a bearer token answers 401 or 403 with a WWW-Authenticate header, as RFC 6750 section 3 describes. The header carries error="invalid_token" or error="insufficient_scope".
What this tool does
The lookup holds the error codes from RFC 6749, RFC 6750, OpenID Connect Core 1.0, RFC 8628 (device flow), RFC 7009 (revocation), RFC 8693 (token exchange), RFC 8707 (resource indicators), RFC 9449 (DPoP), RFC 9396 (rich authorization requests) and RFC 7591 (dynamic client registration). For each code it shows the meaning, where it is returned, the section that defines it and the usual causes.
You can type a code or part of one, or paste a whole JSON error or callback URL. The tool reads error and error_description out of what you paste. If the description is one of the messages Keycloak often returns, it shows that message and its usual cause too.
It does not contact any server or read your logs. A code tells you the category of the problem; the server’s logs tell you the exact cause.
How to use it
- Copy the error your app received: the JSON body, the callback URL or just the code.
- Paste it into the box.
- Read the meaning and the list of usual causes.
- If a Keycloak message appears, read its cause; it is usually more specific.
- Fix the cause, then repeat the whole flow from the start. Codes and device codes cannot be reused after an error.
The errors you will meet most
invalid_grant
The grant itself is bad. For the code flow, the code was already used, has expired, or was issued to another client. The redirect_uri in the token request must also equal the one in the authorization request, and the PKCE code_verifier must match the challenge. For a refresh, the refresh token expired or its session ended.
invalid_client
Client authentication failed. Check the client id, the realm, the secret and the authentication method. A client set up for a signed JWT will reject a secret, and the other way round.
unauthorized_client
The client authenticated but may not use this grant. In Keycloak, the flow is switched off on the client: Standard flow, Direct access grants, Service accounts roles or the device grant.
invalid_scope
A requested scope does not exist or is not available to the client. Scopes are separated by spaces, not commas.
login_required and interaction_required
These come from a silent request with prompt=none. The user has no session, or must do something first. Send the user through a normal sign-in.
PKCE errors
When a client requires PKCE and the authorization request has no challenge, the server answers invalid_request on the redirect. When the challenge was sent but the token request has no verifier, or the wrong one, the token endpoint answers invalid_grant. The usual cause is a verifier lost between the redirect and the callback, for example when it was kept in memory and the page reloaded.
DPoP errors
invalid_dpop_proof means the proof is missing, badly signed or does not match the request: check htm, htu, the clock and, for API calls, ath. use_dpop_nonce means the server wants a nonce; repeat the request with the value from the DPoP-Nonce response header (RFC 9449).
Device flow polling codes
authorization_pending is normal while the user is still signing in. slow_down means add 5 seconds to the polling interval. access_denied means the user declined, and expired_token means the device code ran out; start again.
Messages Keycloak often returns
Keycloak’s error_description texts often name the cause directly. These are the ones we see most:
| Description | Usual cause |
|---|---|
| Invalid parameter: redirect_uri | The redirect URI matches none of the client’s Valid redirect URIs. Shown on an error page. |
| Code not valid | The code was used before, has expired, or belongs to another client. |
| Session not active | The user session behind the code or refresh token ended. |
| Token is not active | The refresh token has expired. |
| Invalid client or Invalid client credentials | Unknown client id in this realm, or a wrong secret. |
| Client not allowed for direct access grants | A password grant for a client with Direct access grants off. |
| Client not enabled to retrieve service account | A client credentials grant for a client with Service accounts roles off. |
| Missing parameter: code_challenge_method | The client requires PKCE and the request had none. |
| Account is not fully set up | The user has a required action pending, which a password grant cannot complete. |
Errors by app type
Single-page and mobile apps
Expect invalid_grant when a code is redeemed twice, for example when a page reloads on the callback, or when the stored PKCE verifier was lost. Clear the code from the address bar once you have used it.
Back ends
Expect invalid_client after a secret rotation, and invalid_grant on refresh when sessions time out. Handle the second by sending the user to sign in again.
Services and devices
Client credentials calls fail with unauthorized_client when service accounts are off. Device flow clients must handle the four polling codes without treating authorization_pending as a failure.
Debugging an OAuth error step by step
- Note which endpoint returned the error: authorization, token, UserInfo or your API.
- Read both
erroranderror_description. - Compare the request with what the server expects. Our request builders show the exact parameters each flow needs.
- Check the server’s logs for the request time. Keycloak records failed logins and token requests as error events with a reason. Turn on saving user events in the realm to see them in the admin console.
- Start the flow again with fresh values once the cause is fixed.
Security notes
Show users a friendly message, not the raw error description. Descriptions can reveal details about your setup.
Never retry a code exchange with a different redirect_uri or verifier to make an error go away. Those checks are the protection. RFC 9700 relies on them to stop stolen or injected codes.
Treat an error redirect like any other: check state before acting on it, so an attacker cannot push fake errors into a user’s session.
Best practices
- Branch on the
errorcode in your program, not on the description text, which can change between versions. - Log the code, description and endpoint, but never tokens, codes or secrets.
- Handle
invalid_granton refresh by signing the user in again. - For device flow polling, honor
intervalandslow_down. - Keep client secrets in one place, so a rotation does not leave a stale copy behind.