Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Google OAuth Error 401: invalid_client, the OAuth client was not found

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

  • Applies to google/apiclient 2.x, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.json
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2The ID is on no list, or the message says deleted_clientThe OAuth client was deletedFix
    3. 3The ID matches an active client, yet Google still answers invalid_clientThe client secret is wrong or was lostFix

What does the error look like?

  • 401. That's an error. Error: invalid_client The OAuth client was not found.
  • Error 401: invalid_client
  • Error 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.json

2Fix

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

Confirmed by developers.google.com

Did this fix it?

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

2Fix

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

Confirmed by support.google.com

Did this fix it?

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

2Fix

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

Confirmed by support.google.com

Did this fix it?

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

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.