Beta

Create a tenant

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

Token requests fail with invalid_client

invalid_client says that the server would not accept a client's authentication, never why. This lesson follows the photo service's album export backend through two incidents with that same error, a changed authentication method and an instance left behind by a secret rotation, and tells them apart from the records each system kept.

The export backend cannot get a token

All names, domains and identifiers in these examples are fictional. You look after the photo service's album export backend, the component that builds a zip file when a customer downloads a whole album. It runs as two instances, export-a and export-b, and both get access tokens from the photo service's own authorization server at auth.photos.example with the client credentials grant. They share one confidential client registration, photos-export. At 09:34 on a Monday the monitoring alert fires: every token request from both instances has failed since 09:31, and album downloads are queuing up.

The backend logs the request it sends, with the credential redacted, and the response:

POST /token HTTP/1.1
Host: auth.photos.example
Authorization: Basic <redacted>
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&scope=photos.read

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="auth.photos.example"
Content-Type: application/json
Cache-Control: no-store
X-Request-ID: 8d3f61a2-4c07-4b9e-a1f5-27e9d0c6b413

{"error": "invalid_client", "error_description": "Client authentication failed."}

Client authentication is how an application proves which client is asking for tokens, as Client authentication methods explained. It is separate from any user's sign-in, and in this flow there is no user at all. When it fails, RFC 6749 section 5.2 says the server returns invalid_client, and when the client tried to authenticate with the Authorization header, the server must answer 401 with a WWW-Authenticate challenge for the same scheme. So the Basic realm header tells you the server saw your Basic credentials and refused them. It does not say why, and invalid_client covers several different reasons: an unknown client, such as a production client ID sent to a staging server, a wrong or retired secret, or an authentication method this client is not registered to use.

Separate the value from the method

Start with the value, without ever looking at it. Your secret store keeps each version of the client secret with a version number and a short fingerprint, the first characters of a SHA-256 hash of the value. The authorization server shows the same fingerprint for each secret it holds for the client. Comparing the two tells you whether the instances present the secret the server expects, and neither the secret nor anything that can be turned back into it ever leaves its store. Never paste a secret into a ticket or a chat to prove it matches.

secret store   photos-export/client-secret   version 6   sha256:4be1c09a   created 2026-09-02
auth server    photos-export                 secret     sha256:4be1c09a   status active   expires never
export-a       secret ref photos-export/client-secret@6
export-b       secret ref photos-export/client-secret@6

The value is current and both instances use it. That leaves the method. A client registration records how the client presents its secret as well as the secret itself, in OAuth's registration metadata as token_endpoint_auth_method. With client_secret_basic, the client sends its ID and secret in an HTTP Basic Authorization header. With client_secret_post, it sends them as client_id and client_secret fields in the form body. They carry the same secret, and a server that enforces the registered method refuses the other one, as one method per registration described. The client's change history shows that the registration moved four minutes before the alert:

time     2026-10-12T09:30:47Z
actor    callum.bianchi
action   oauth.client.update
client   photos-export
field    token_endpoint_auth_method
before   client_secret_basic
after    client_secret_post
note     "Match the method used by the new reporting script"

Your teammate Callum was setting up photos-reports, a new reporting script that sends its secret in the form body, and edited the wrong client. The server's audit record for the refused request names the mismatch directly:

time        2026-10-12T09:31:02.554Z
operation   oauth.token
outcome     rejected
reason      auth_method_not_registered
client      photos-export
presented   client_secret_basic
registered  client_secret_post
request_id  8d3f61a2-4c07-4b9e-a1f5-27e9d0c6b413

The repair is to set photos-export back to client_secret_basic and make Callum's change on photos-reports, where he meant it. Three other fixes would also clear the alert, and each is worse. Changing the backend to send the secret in the body would bend working code to fit an accidental edit. Allowing both methods on the client would accept a method nobody needs. Rotating the secret would create deployment work and new risk for a value that was never at fault.

Verify in both directions. A Basic request from each instance gets a token again. The same current secret sent in the form body is now refused, because that is not how this client is registered to authenticate:

POST /token HTTP/1.1
Host: auth.photos.example
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&scope=photos.read&client_id=photos-export&client_secret=<redacted>

HTTP/1.1 400 Bad Request
Content-Type: application/json
Cache-Control: no-store

{"error": "invalid_client", "error_description": "Client authentication failed."}

No Authorization header was sent, so there is no Basic challenge, and this server answers 400. RFC 6749 also allows a 401 here, so another server may differ. What stays the same is the error code, which is why the audit reason, not the status line, told the two causes apart.

When the secret has a plus sign or a slash

One more cause of invalid_client with HTTP Basic catches teams who write their own token requests. RFC 6749 section 2.3.1 says the client ID and secret are each form-urlencoded first, then joined with a colon and base64-encoded. Most generated secrets contain only letters and digits, where encoding changes nothing, so a client that skips the step works for months. Then a rotation produces a secret containing +, / or =. Encoded, a value such as ab+c/d= becomes ab%2Bc%2Fd%3D, and a server that decodes the form encoding reads an unencoded + as a space, just as it would in any form body.

Some servers skip the decoding step, so some client libraries skip the encoding too. When the two sides disagree, everything works while the secret has only letters and digits, and fails as soon as it does not. If invalid_client starts right after a rotation on every instance that received the new value, check this before anything else: the fingerprint will match, the method will match, and only the bytes inside the header differ.

Three weeks later, one instance fails

The secret is due for its quarterly rotation, and your team does it the usual way, with the overlap Rotating client credentials described. The authorization server creates a new secret, version 7, and keeps version 6 working for 24 hours so every instance can switch before the old value stops. The next morning at 10:00 the alert fires again, and this time it is different: export-b is fine and every token request from export-a gets the same 401 invalid_client as before. Restarting export-a changes nothing.

One instance working with the same registration rules out the method and the client ID. Both instances send Basic to the same server for the same client, and one succeeds. Whatever differs is in the failing instance, so compare what each one deploys.

Reconstruct the rotation

Don't rely on anyone's memory of the rotation. Build the timeline from the records each system kept: the authorization server's credential changes, the deployment history for each instance and the server's audit records for the failures.

2026-11-02 10:00:12  auth server  photos-export secret v7 created (sha256:91d7e2f0)
                                  v6 (sha256:4be1c09a) valid until 2026-11-03 10:00:00
2026-11-02 10:20:40  deploy       export-b  secret ref photos-export/client-secret@7  succeeded
2026-11-02 10:21:05  deploy       export-a  secret ref photos-export/client-secret@7  FAILED
                                  (config validation timed out, previous config kept)
2026-11-03 10:00:00  auth server  photos-export secret v6 overlap ended
2026-11-03 10:00:02  auth server  oauth.token rejected  client=photos-export
                                  reason=client_secret_retired  presented=sha256:4be1c09a

The deployment to export-a failed the day before, kept its previous configuration and raised nothing louder than a line in the pipeline log. For 24 hours that did not matter, because version 6 still worked. When the overlap ended, export-a became the instance that could not connect. Its failure carries the same protocol error as a mistyped secret, and only the records explain it: the audit record says the presented secret is the retired one, and its fingerprint matches version 6.

Finding an instance left behind during secret rotation.

The overlap exists to give deployments time to finish. It is not a promise that the old value keeps working for as long as someone needs it. Had anyone noticed the failed deployment during those 24 hours, extending the overlap while it was still running would have been a reasonable way to buy time. Once it has ended, bringing version 6 back would only hide the missed deployment and keep a credential alive that the team had decided to retire.

Verify recovery and the retired secret

Rerun the deployment for export-a with version 7 and watch it succeed this time. Its next token request returns 200, and the server's audit record shows it presenting sha256:91d7e2f0. Then confirm that version 6 is still refused: the server's records should show no successful request with that fingerprint after 10:00, and a single test request with it from a maintenance host gets invalid_client with the reason client_secret_retired.

If the secret had leaked rather than reached its scheduled rotation, the steps would be different: no overlap, immediate retirement and possibly revoking tokens already issued with it, as When a credential has leaked described.

Everything in this lesson concerns your own application's credential at your own authorization server, where you can read both sides. When the failing credential belongs to your application but is registered at another organization's provider, you can read only your side of the comparison, and the investigation has to work with what that provider shows you.

Worked example: the instance comparison and the handoff note

Set side by side, the two instances differ in one column only, the secret version each one deployed, and that column explains every outcome after it:

What each instance presented during the rotation
InstanceSecret version deployedDuring the overlapAfter the overlap endedAfter the repair
export-av6 (deployment of v7 failed)Token issued401 invalid_client, reason client_secret_retiredv7, token issued
export-bv7Token issuedToken issuedv7, token issued

The handoff note names fingerprints and versions, never the secret values:

Symptom:       From 2026-11-03 10:00 UTC, export-a token requests failed with 401 invalid_client.
               export-b unaffected. Album downloads served by export-a queued.
Failing stage: Client authentication at auth.photos.example. Registered method (client_secret_basic)
               and client ID correct on both instances.
Cause:         Secret rotation on 2026-11-02 with 24h overlap. export-b received v7. The export-a
               deployment of v7 failed (config validation timeout) and kept v6. v6 retired at 10:00.
               audit reason client_secret_retired, presented fingerprint sha256:4be1c09a (v6).
Repair:        Redeployed export-a with photos-export/client-secret@7.
Verification:  export-a token requests 200, presenting sha256:91d7e2f0 (v7).
               v6 test request: invalid_client, client_secret_retired. No v6 success after 10:00.
Not changed:   Registration, authentication method, v6 retirement. No secret values recorded here.
Follow-up:     Make a failed secret deployment fail the rotation instead of logging a warning.

The follow-up addresses why the incident happened at all: a deployment that failed quietly, which no change to the secret would have caught.

Check your understanding

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

After a secret rotation with a 24-hour overlap, one of two instances starts getting 401 invalid_client the moment the overlap ends. Both send Basic for the same client. What do you check first? 1 of 3

Choose one answer.

A backend sends its secret in a Basic header and gets 401 with WWW-Authenticate: Basic realm="auth.photos.example". Its fingerprint matches the server's active secret for the client. What should you compare next? 2 of 3

Choose one answer.

Right after a rotation, every instance with the new secret gets invalid_client over Basic. Fingerprints match and the method is unchanged. The new secret contains a +. What do you check? 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