Errors and denied access
A connection can stop at the authorizationDeciding whether a requested action is permitted, such as whether a signed-in account may delete a particular photo. Authentication says which account is asking; authorization decides what it can do. endpoint, at the token endpointThe authorization server address where clients exchange an authorization code, refresh token, or other grant for tokens, in a direct request rather than through a browser redirect., or somewhere between them with no answer at all. What the printer knows, and what it should tell Ava, depends on where it stopped.
A token request is rejected
A failure at the token endpoint comes back on the printer's own back-channel request, in the JSONA text format for structured information, written as named values inside curly braces. APIs, tokens, and discovery documents all use it. response, as Exchanging a code for tokens showed:
HTTP/1.1 400 Bad Request
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache
{
"error": "invalid_grant"
}invalid_grant says the code cannot be used, without saying why. It covers an expired code, a code already used, a code issued to another client, a redirect_uri that does not match, and a PKCEProof Key for Code Exchange, pronounced pixie: the client creates a secret for each authorization attempt, sends only a hash of it at the start, and proves it holds the secret when redeeming the code, so a stolen authorization code is useless to anyone else. verifier that does not match the challenge. Keeping the reason general is deliberate: the server does not tell a caller which detail of a stolen code it got wrong. invalid_client means client authenticationChecking evidence that someone, or some application, controls an account, such as a password or a passkey. It establishes which account is being used, not what that account may do. failed, and invalid_request means the request itself was malformed. Each calls for a different response from the printer, so it reads error, not just the status codeThe three-digit number at the start of an HTTP response that says how the request went, such as 200 for success, 302 for a redirect, or 401 when authentication is needed..
Ava needs a clear next step: the connection did not finish, and she can try again. The printer's developers need enough to investigate without collecting credentials. The printer records the stage that failed, the safe error value and a correlation ID: an identifier attached to this attempt, so its log lines can be found together and matched with the server's records. Some servers return their own identifier for each request in a response header, which the printer can log beside its own. It never copies full callback URLs, Authorization headers, codes, verifiers or tokens into logs.
Error reference
RFC 6749 gives each endpoint a small, fixed set of error codes. Knowing them all lets a client tell a mistake it should fix from a refusal it should explain.
At the authorization endpoint, an error travels back through the browser to the redirect URI as the error parameter, together with the client's state and, from a server that supports it, iss, like the denial above:
| Code | What it means | What the printer can do |
|---|---|---|
invalid_request | A required parameter is missing, a value is invalid, a parameter appears more than once, or the request is otherwise malformed. | Treat it as a bug in how it builds the request. Sending the same request again fails again. |
unauthorized_client | This client is not allowed to ask for a code this way. | Fix its registration or the flow it uses. |
access_denied | The resource owner or the server's policy refused. | Say the account was not connected, and offer to continue without it or try again. |
unsupported_response_type | The server does not issue the requested kind of response, such as a token in the redirect. | Fix its configuration and ask for response_type=code. |
invalid_scope | A requested scope is unknown, malformed, or otherwise invalid. | Correct the scopes it asks for. |
server_error | Something failed on the server. A redirect cannot carry an HTTP 500, so the code takes its place. | Offer to try again later. |
temporarily_unavailable | The server is overloaded or down for maintenance, standing in for an HTTP 503. | Offer to try again later, without retrying in a loop. |
Two problems never arrive this way, as the first section explained: an unknown or missing client_id, and a missing or unregistered redirect URI. The server shows those on its own page. That is why the printer should let someone who comes back without a callback simply start again, rather than wait for one.
At the token endpoint, the error comes back in the JSON body of the direct response, like the invalid_grant example:
| Code | What it means | What the printer can do |
|---|---|---|
invalid_request | A required parameter is missing, a value is unsupported, a parameter is repeated, the client used more than one authentication method, or the request is otherwise malformed. | Treat it as a bug in how it builds the request. |
invalid_client | Client authentication failed: an unknown client, no authentication where it was required, or an unsupported method. | Check the deployed credential and method. A replaced secret is a common cause. |
invalid_grant | The code or refresh token is invalid, expired, revoked, already used, issued to another client, or does not match the redirect URI, or the PKCE check failed. | Start a fresh authorization attempt. Never resend the same code. |
unauthorized_client | The authenticated client is not allowed to use this grant type. | Fix its registration. |
unsupported_grant_type | The server does not support this grant type at all. | Fix its configuration and use a grant the server supports. |
invalid_scope | A requested scope is unknown, malformed, or more than the resource owner granted. | Ask only for scopes within the grant. |
All of these come with HTTPThe Hypertext Transfer Protocol, the rules browsers, apps, and servers use to send requests and responses on the web. status 400, with one exception. When client authentication fails and the client sent its credentials in the Authorization header, as the printer does with HTTP Basic, the server must answer 401 with a WWW-Authenticate header naming that scheme, as Sending requests with curl described for any 401. It may use 401 for other failed client authentication too.
Either endpoint may add two optional fields. error_description is text meant to help a developer understand the failure. The server writes it in its own words, and anyone who can send a browser to the callback can write one too, so the printer never shows it to Ava as its own message and never inserts it into a page as markup, which would open the door to the injected scripts of Cross-site scripting and token storage. It keeps the description for diagnostics and shows its own message. error_uri points to a page about the error. It can go in a developer's notes, but the printer does not send Ava's browser there.
The printer decides what to do from error alone, and only a few codes call for more than a clear message and an alert to its developers. access_denied is a decision to respect and explain. invalid_grant means starting a fresh attempt. server_error and temporarily_unavailable invite a later retry. The rest describe mistakes in the client's request, registration or credentials, which no amount of retrying will fix.
When the outcome is uncertain
Suppose the printer sends its token request and the connection drops before any response arrives. The photo service might have refused the request. It might also have accepted it, marked the code as used and issued a token whose response was lost on the way back.
A timeout therefore means only that the printer has no confirmed result. It does not prove that the server did nothing.
Sending the same code again does not resolve that. A code presented a second time looks like a stolen copy being used, so the server must refuse it and should, where it can, revokeCancelling a credential, token, certificate, or authenticator before it would expire, so that it is no longer accepted. Whether every copy stops working at once depends on how services check it. any tokens already issued from it. If the first request did succeed, the retry gets invalid_grant, the same answer a failed first request would have produced, and it may cause the server to revoke the very token whose response was lost. The retry tells the printer nothing and can cost it the token.
So the printer reports that it could not finish the connection and offers Ava a fresh attempt, with a new state, verifier and code. It does not quietly drop PKCE, change the return address, or keep sending her back for approval in a loop.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Handle denial, rejection and a lost response, then run the complete exchangeTell an authorization denial from a token endpoint rejection, find a failed request by its request ID, see why resending a code is not recovery, and finish with the sequential checked exchange.