Adamant Solutions

OAuth2 "invalid_client": why client authentication fails

The token endpoint could not authenticate the client application (not the user). It is returned as {"error":"invalid_client"}, usually with HTTP 401 and sometimes 400 (RFC 6749 section 5.2). The usual causes are a wrong secret, a wrong way of sending it, or the wrong kind of client. Answer the questions to find which.

Find your cause

All the causes and fixes

The client type does not match how it authenticates

  • A confidential client must authenticate at the token endpoint; a public client must be registered as public (no secret) and use PKCE. A mismatch gives invalid_client.
  • Check the client registration in the authorization server console: client type, "require secret", and the allowed authentication method.

The secret was rotated, expired or the client disabled

  • Many providers expire client secrets (for example after a set number of months) or allow only the newest of several.
  • Generate a new secret, deploy it, and check that every instance and environment reads the new value.
  • Confirm that the client is still enabled and not removed.

Client assertion (private_key_jwt) or mutual TLS

  • For a client assertion check iss and sub (both the client ID), aud (the token endpoint URL or issuer, as the server requires), exp, a unique jti and the key registered for the client. Decode it with the JWT inspector.
  • client_assertion_type must be urn:ietf:params:oauth:client-assertion-type:jwt-bearer.
  • For mutual TLS the certificate presented must match the one registered (subject or thumbprint), and the proxy must forward it.

The authentication method is not the one the server expects

  • The server expects client_secret_basic (Basic header) but receives the secret in the body, or the reverse. Look at token_endpoint_auth_methods_supported in the discovery document.
  • Configure your library to use the supported method explicitly.
  • Send the Basic header as base64(client_id:client_secret), with each part URL-encoded first (RFC 6749 section 2.3.1).

Special characters in the ID or secret

  • RFC 6749 says the ID and secret are encoded with application/x-www-form-urlencoded before being put into the Basic header. Many libraries skip this and many servers do not decode, so behaviour differs.
  • A secret with +, /, = or : is a common trap. If possible regenerate a secret with only letters and digits.
  • Remove stray spaces, quotes or line breaks added by env files or copy and paste.

Wrong environment, tenant or endpoint

  • The client ID is registered in another tenant, realm or environment than the token endpoint you call. Production credentials do not work on a test server.
  • Check the issuer URL and the client ID together in the same console.
  • Look at the authorization server log: most servers record the exact reason for invalid_client there.

A secret in a public app is not a secret

  • Browser and mobile apps cannot keep a secret: anyone can extract it. Register them as public clients and use the authorization code flow with PKCE (see the OAuth2 tester).
  • If the server insists on a secret for a public client, route the token request through your own backend.

Public client registration

  • Register the client with token endpoint authentication "none" (public) if the server supports it, and send only the client_id with the PKCE code_verifier.
  • Some servers need a setting such as "public client" or "allow PKCE without secret" in the client configuration.

Frequently asked questions

What is the difference between invalid_client and invalid_grant?

invalid_client means the application itself could not be authenticated. invalid_grant means the application was fine but the code, refresh token or credentials it presented are not acceptable.

Why do I get 401 instead of 400?

RFC 6749 says the server may return 401 with a WWW-Authenticate header when the client tried to authenticate through the Authorization header; otherwise it uses 400. Both mean the same failure.

Can I put the client secret in a mobile or single-page app?

No. Anyone can read it from the app. Use a public client with PKCE, or send the token request through your backend.

About this page

Nothing you select here is sent anywhere: the questions run in your browser. If you paste anything into the related tools, read their privacy notes and use test data. See the privacy notice.

Related: OAuth2 error doctor · OAuth2 flow tester · OAuth2 invalid_grant · All error guides

Still stuck, or designing the flow for your API?

We configure and review OAuth2/OIDC and API gateways, including WSO2 Identity Server and API Manager. See the WSO2 services or the security review.

Message us on LinkedIn