Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Errors and denied access

A connection can stop at the authorization endpoint, at the token endpoint, or somewhere between them with no answer at all. What the printer knows, and what it should tell Ava, depends on where it stopped.

An authorization request is denied

Ava reaches the photo service's approval page and decides not to connect the printer after all. That is a valid outcome, not a fault. The printer should let her carry on with her photo book, without pretending the connection worked and without sending her straight back to approve it again.

The photo service reports the denial the same way it would have returned a code: by redirecting Ava's browser to the printer's registered callback. In place of code, the response carries an error parameter:

https://printer.example/oauth/callback
  ?error=access_denied
  &state=demo-attempt-7
  &iss=https%3A%2F%2Fauth.photos.example

An error arriving at the callback is still a response that anyone could have sent, so the printer checks it exactly as it would a success. state must find a pending attempt in Ava's session, and iss must name the expected issuer. Only then does the printer claim the attempt and report the result. Skipping those checks for errors would let another site end her connection attempts at will.

access_denied means the request was refused, either by Ava or by the photo service's own policy, perhaps because an administrator does not allow the printer. So the printer should not always translate it into "You chose Cancel". A suitable message is: "The photo account was not connected. You can continue without it or try again." No token request follows, because no code was issued.

One kind of failure never comes back to the printer at all. If the client_id is unknown, or the redirect_uri is missing or not registered, the photo service has no trustworthy address to send Ava's browser to. Redirecting even an error to an unregistered address would make the photo service an open redirect, sending browsers wherever a link names, as Correlating requests and responses described. So the service shows the error on its own page instead. Ava stays at the photo service, and the printer receives no callback.

A token request is rejected

A failure at the token endpoint comes back on the printer's own back-channel request, in the JSON 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 PKCE 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 authentication 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 code.

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:

Authorization endpoint errors, returned to the callback
CodeWhat it meansWhat the printer can do
invalid_requestA 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_clientThis client is not allowed to ask for a code this way.Fix its registration or the flow it uses.
access_deniedThe 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_typeThe 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_scopeA requested scope is unknown, malformed, or otherwise invalid.Correct the scopes it asks for.
server_errorSomething failed on the server. A redirect cannot carry an HTTP 500, so the code takes its place.Offer to try again later.
temporarily_unavailableThe 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:

Token endpoint errors, returned on the direct response
CodeWhat it meansWhat the printer can do
invalid_requestA 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_clientClient 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_grantThe 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_clientThe authenticated client is not allowed to use this grant type.Fix its registration.
unsupported_grant_typeThe server does not support this grant type at all.Fix its configuration and use a grant the server supports.
invalid_scopeA requested scope is unknown, malformed, or more than the resource owner granted.Ask only for scopes within the grant.

All of these come with HTTP 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, revoke 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.

Where the exchange stops determines what the printer knows. A denied request produces no code. A rejected token request reports a failure. A lost response leaves the outcome unconfirmed.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

The printer's authorization request names a redirect URI that is not registered. Should the photo service send its error to that address? 1 of 3

Choose one answer.

The printer's token request times out before any response arrives. What does the printer know? 2 of 3

Choose one answer.

Ava's callback brings back error=access_denied, with a state and iss that match her pending attempt. What should the printer tell her? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity