Tracing and troubleshooting exchanges
Part of a connection attempt passes through the browser and part runs directly between the printer's backend and 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., so no single place sees the whole exchange. Tracing it means joining records afterwards, without copying codes or tokens along the way.
Following one attempt
Ava writes to the printing company. She selected Connect photo account, approved the printer at the photo service, came back, and saw "We could not finish connecting your photo account." She tried again and it worked. Could someone find out what went wrong the first time?
Part of that attempt passed through Ava's browser and the photo service. Another part ran directly between the printer's backend and the photo service's tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. endpoint. No single place saw the whole exchange, so the answer depends on records that can be joined together afterwards.
When the printer creates a pending transaction, it also gives the attempt a local correlation ID, and every log entry about that attempt carries it, from the Connect click to the first APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests. call. The ID is not the state value, which travels through the browser and is better kept out of logs, and it is not anything taken from a session cookieA small value that a website asks the browser to store and send back with later matching requests. Cookies commonly carry a session identifier, so the site can recognize an ongoing sign-in without your password.. All values in these examples are fictional:
09:00:00.120 corr=demo-corr-51 connect.start session=ref-7f3 issuer=https://auth.photos.example
09:00:04.031 corr=demo-corr-52 connect.start session=ref-7f3 issuer=https://auth.photos.example
09:00:31.874 corr=demo-corr-51 callback result=code issuer=match
09:00:32.010 corr=demo-corr-51 token.request grant=authorization_code
09:00:32.240 corr=demo-corr-51 token.response status=400 error=invalid_grant request_id=demo-req-8812session=ref-7f3 is an internal reference to the printer sessionThe ongoing connection between later requests and an earlier sign-in, so you are not asked for your password on every click. It is often tracked with a cookie holding an unpredictable session identifier., not the cookie value. request_id is the identifier the photo service returned in a response header, the reference that leads to the photo service's own record of its decision.
The trace narrows the question. invalid_grant can mean an expired code, a reused code, a binding mismatch, or a failed 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. check, as Errors and denied access said. The token request followed the callback by a fraction of a second, so the code had not expired. This was the attempt's first and only token request, so the code was not reused. But two attempts started in the same session four seconds apart: Ava double-clicked Connect, or opened it in two tabs. If the printer kept one PKCE verifier per session rather than one per attempt, attempt 52 overwrote the verifier for attempt 51, and the photo service correctly rejected the mismatch. The photo service can confirm the reason from demo-req-8812. The fix is the separate per-attempt records described in Correlating requests and responses.
invalid_grant from the token endpoint
- An expired code
- Ruled out: a fraction of a second after the callback
- A reused code
- Ruled out: the attempt's first and only token request
- A failed PKCE check
- Remains: attempt 52 started in the same session four seconds apart
The photo service can confirm the reason from demo-req-8812
The fix is the separate per-attempt records.
Common failures and their causes
Most problems in an OAuthA framework that lets a person give an application limited access to their resources at another service, using tokens instead of sharing their password. OAuth is about access; OpenID Connect adds sign-in. integration announce themselves in a few recognizable ways:
| What you see | What it usually means |
|---|---|
| An error page at the photo service, and the browser never returns | The requested redirect URI does not exactly match a registered one: a trailing slash, http instead of https, a different path, or a test address sent with the production client ID. |
| The callback reports an unknown or expired attempt | The transaction expired, the session cookie was not sent on the return journey, or the attempt started on a different host name from the callback, such as www.printer.example, so the callback at printer.example never saw that session. |
invalid_grant from the token endpoint | The code expired or was already used, the redirect URI differs from the one in the authorization request, or the verifier does not match the challenge. |
invalid_client, often with status 401 | The credential does not match the registration, the client used a method it is not registered for, or the client ID and secret were not form-encoded before being combined for HTTP Basic. |
invalid_scope | The client asked for a scope that does not exist or that its registration does not allow. |
401 from the API with error="invalid_token" | The token has expired, names a different audience or issuer, or was signed with a key the API has not loaded. |
403 from the API with error="insufficient_scope" | The token is valid but lacks the scope this operation needs. |
| Failures on one server only, or only for tokens near expiry | A clock on one of the servers involved has drifted. |
Each row is a starting point, not a verdict. The authorization serverIn OAuth, the service that handles a person's sign-in and approval and decides which tokens to issue to a client. It may belong to the same company as the API, but its job is separate. deliberately says little in its errors, so the client's own records of what it sent, minus the secrets, are usually what separates one cause from another. The table supplies the candidates for an OAuth exchange; the method of choosing between them, from the last stage that succeeded to the one safe observation that tells two causes apart, is taught in Finding the failing stage.
Reading a rejected token
When the API rejects a token, the token often helps explain why. Suppose the printer's calls start failing with invalid_token, and an engineer decodes one of the rejected tokens on their own machine to compare it with the API's configuration:
Header:
{ "alg": "ES256", "kid": "photos-2026-09", "typ": "at+jwt" }
Claims:
{
"iss": "https://auth.photos.example",
"sub": "user-2048",
"aud": "https://api.photos.example",
"client_id": "photo-printer",
"scope": "photos.read",
"iat": 1790845200,
"exp": 1790845800,
"jti": "demo-token-id-7"
}The claims rule out most of the table. iss and aud match the production API, and kid names a key the API already has. iat and exp say the token was issued at 09:00:00 UTC on 1 October 2026 and expires at 09:10:00. The API's log, found by the token's jti, shows the rejection at what the API believed was 09:10:31, while the printer recorded sending the request at 09:00:31, and it names the expiry check as the one that failed. The token was fine. One API server's clock was ten minutes fast.
Decoding only pointed the engineer at the right check; the API's own validation result confirmed it, because values that look right can belong to an altered token. The fix is time synchronization on that server, followed by a repeat with a fresh token. Increasing the clock tolerance until requests pass would hide the cause and weaken every time check.
Decoding locally needs nothing more than this:
// For reading while debugging. It verifies nothing.
function decodeJwtForDebugging(jwt: string) {
const [header, claims] = jwt.split('.').slice(0, 2).map(part =>
JSON.parse(Buffer.from(part, 'base64url').toString('utf8')));
return { header, claims };
}As Protecting credentials and messages put it, reading is not validating. Decoded claims say what the token asserts. Only the API's validation says whether to believe them, but for comparing a token with a configuration, reading is exactly what is needed.
Looking without leaking
The browser's developer tools show the redirect half of the exchange. Turn on the network panel's option to preserve the log, because each redirect loads a new page and would otherwise clear the list. 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. request, the redirect back, and the callback then appear in order, with their parameters.
Everything in that panel is real. The callback address contains a working code until it is used, and the page's requests carry session cookies. Exported network recordings, often saved as HAR files, contain all of it, so they need redacting before they are attached to a support ticket. Reproducing a problem with test accounts and the test client, rather than inside Ava's own session, keeps a careless paste from becoming an incident.
Tokens deserve the same care. Pasting an access tokenA token that a client presents to an API to use access it has been granted, usually limited in what it allows and how long it lasts. It authorizes API calls; it does not tell the client who signed in. into a public token-decoding website hands a working credential to a third party and to whatever that site records. The local function above does the same job without sending anything anywhere. Logs follow the same rule as the trace above: they record the stage, the correlation ID, the client, error codes, and identifiers such as jti and kid, and never the code, verifier, secret, or token.
When access tokens are opaque, there is nothing to decode: the token is a random reference to a record at the authorization server. The engineer asks the API's introspectionA way for an API to ask the authorization server what a token means: whether it is still active and what access it carries. APIs need it when a token is a random string that only the authorization server can interpret. endpoint, with the API's own credentials, what the token stands for, and reads the API's request diagnostics. Whatever the format, the token being examined must come from the failing connection, for the right issuerThe party that creates and signs a token, assertion, or certificate, named in a token's iss claim. A recipient must check that the issuer is exactly the one it expected and trusts., client and account. A token from another connection looks just as plausible and sends the investigation the wrong way.
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
- Trace a failed connection by correlation ID and request IDReproduce the double-click failure in your own client, follow it through your trace and the tenant's request ID, match three more failures to their causes, and find a server error by reference ID.