Adamant Solutions

OAuth2 invalid_client: perché fallisce l’autenticazione del client

L’endpoint token non è riuscito ad autenticare l’applicazione client (non l’utente). L’errore {"error":"invalid_client"} viene restituito di solito con HTTP 401, talvolta 400 (RFC 6749 sezione 5.2). Le cause comuni sono secret errato, modalità di invio sbagliata o tipo di client non corretto. Rispondi alle domande per individuare il problema.

Individua la causa

Tutte le cause e le soluzioni

Il tipo di client non corrisponde al metodo di autenticazione

  • 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.

Il secret è stato ruotato, è scaduto oppure il client è disabilitato

  • 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) o TLS reciproco

  • 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.

Il metodo di autenticazione non è quello atteso dal server

  • 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).

Caratteri speciali nell’ID o nel 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.

Ambiente, tenant o endpoint errato

  • 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.

Un secret incorporato in un’app pubblica non è segreto

  • 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.

Registrazione di un client pubblico

  • 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.

Domande frequenti

Qual è la differenza tra invalid_client e 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.

Perché ricevo 401 invece di 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.

Posso inserire il client secret in un’app mobile o single-page?

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

Informazioni sulla pagina

Le risposte non vengono inviate: le domande funzionano nel browser. Se incolli dati negli strumenti collegati, leggi le note sulla privacy e usa dati di test. Consulta l’ informativa sulla privacy.

Correlati: diagnostico errori OAuth2 · tester flusso OAuth2 · OAuth2 invalid_grant · tutte le guide agli errori

Hai ancora problemi o stai progettando il flusso della tua API?

Configuriamo e analizziamo OAuth2/OIDC e API gateway, inclusi WSO2 Identity Server e API Manager. Scopri i servizi WSO2 or the revisione di sicurezza.

Scrivici su LinkedIn