Google OAuth Error 401: invalid_client, the OAuth client was not found
401. That's an error. Error: invalid_client The OAuth client was not found.Short answer
Google returns invalid_client when the client the request names cannot be used: the client ID is not one from the project's Clients page, the client was deleted, or the client secret is wrong. Compare the ID in your credentials file with the console, restore a deleted client within 30 days, or rotate a lost secret.
Fix it fast
1Find out which cause you have
Read the client_id your app really sends, then find that exact ID on the Clients page of the Google Cloud project you expect. Replace the path with your credentials file.
grep -o '"client_id": *"[^"]*"' client_secret.json2Match what you see, then jump to its fix
- 1
The ID is missing on the project's Clients page, or the file came from another project, a test setup or an old downloadThe client ID is not from this project, or was mistypedFix - 2
The ID is on no list, or the message says deleted_clientThe OAuth client was deletedFix - 3
The ID matches an active client, yet Google still answers invalid_clientThe client secret is wrong or was lostFix
- 1
What does the error look like?
401. That's an error. Error: invalid_client The OAuth client was not found.Error 401: invalid_clientError 401: deleted_client The OAuth client was deleted.
Cause 1 of 3
The client ID is not from this project, or was mistyped
1Check
Google lists the client ID of each client on the Clients page of the Cloud Console. The ID in your file must match one of them, in the project you intend to use.
grep -o '"client_id": *"[^"]*"' client_secret.json2Fix
Download the credentials again from the right project and point the client at that file. Keep the file outside any public folder.
$client = new Google\Client();
$client->setAuthConfig('/path/outside/webroot/client_secret.json');3Verify
Start the sign-in flow again. Google should show the consent screen and not the 401 page.
php auth-start.phpConfirmed by developers.google.com
Cause 2 of 3
The OAuth client was deleted
1Check
Deleting a client stops sign-in and data access for it, and authorization requests with that ID return a deleted_client error. Look in the Deleted Credentials page of the console.
grep -o '"client_id": *"[^"]*"' client_secret.json2Fix
Restore the client from the Deleted Credentials page. Google says deleted clients are typically recoverable for at least 30 days; after 30 days they are permanently deleted, and you must create a new client and update the app.
// after creating a new client, replace the downloaded file
$client->setAuthConfig('/path/outside/webroot/new_client_secret.json');3Verify
Run the sign-in flow again with the restored or new client.
php auth-start.phpConfirmed by support.google.com
Cause 3 of 3
The client secret is wrong or was lost
1Check
Google's table lists invalid_client as an incorrect client secret. The secret is shown only once when the client is created, and later only its last four characters.
grep -c client_secret client_secret.json2Fix
Rotate the secret in the console to get a new one, download the new file and deploy it.
$client->setAuthConfig('/path/outside/webroot/client_secret.json');3Verify
Complete the whole sign-in once and confirm the token exchange works.
php auth-callback-test.phpConfirmed by support.google.com
How do I stop it coming back?
- Keep one client per environment and name it clearly, so nobody deletes the live one by mistake.
- Check the console's traffic overview before deleting a client.
- Store the credentials file outside the web root and keep it out of version control.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Security
Google sign-in stops with Error 400: redirect_uri_mismatch
redirect_uri_mismatch
Google compares the redirect_uri in your request with the authorized redirect URIs of that OAuth client, character by character.
3 causes, each with a fixBack end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
Apache returns 403 when a URL contains %3F
a request like /page%3Fname=test is refused while /page?name=test works
Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.
2 causes, each with a fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fix