Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

Google token request fails with unauthorized_client

Errorunauthorized_client

Short answer

For a service account using domain-wide delegation, unauthorized_client means Google Workspace has not approved that client and those scopes. Authorize the service account's numeric client ID with the exact scopes in the Admin console, and never add it by email address or through a group.

  • Applies to Google Workspace Admin console, Google OAuth 2.0 service account flow
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the error_description in the response. The two texts below point to different causes.

    # look at the JSON body of the failed token request: error and error_description
  2. 2Match what you see, then jump to its fix

    1. 1error_description: Unauthorized client or scope in requestThe service account is not authorized for the user and scopes in the Admin consoleFix
    2. 2error_description starts with: Client is unauthorized to retrieve access tokens using this methodThe client was added by email address or as a groupFix

What does the error look like?

  • unauthorized_client
  • Unauthorized client or scope in request
  • Client is unauthorized to retrieve access tokens using this method

Cause 1 of 2

The service account is not authorized for the user and scopes in the Admin console

1Check

This appears when you use domain-wide delegation and the service account is not authorized for the user named in the sub claim. Open the Domain-wide delegation page in the Admin console and look for the client ID and scopes.

# Admin console: Security > API controls > Domain-wide delegation

2Fix

Add the service account's client ID with exactly the scopes your code requests, then wait. Changes can take a few minutes and up to 24 hours.

# Admin console: Add new, enter Client ID and the OAuth scopes (comma-separated)

3Verify

Request a token again for that sub user.

# the token response contains access_token, not error

Confirmed by developers.google.com

Did this fix it?

Cause 2 of 2

The client was added by email address or as a group

1Check

Google says this happens when the service account was added in the Admin console by its email address instead of its numeric client ID, or when a Google Group was used.

# compare the Admin console entry with the service account's numeric client ID

2Fix

Remove the entry and add it again with the numeric ID. If a group was used, replace it with the individual service or user account.

# Admin console: delete the entry, then add the numeric Client ID again

3Verify

Request the token again.

# no unauthorized_client in the response

Confirmed by developers.google.com

Did this fix it?

How do I stop it coming back?

  • Keep a record of each service account's numeric client ID and the exact scopes it needs.
  • Add scopes in the Admin console in the same step you add them in code.
  • Allow up to a day for delegation changes before you start debugging.

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.

Related fixes

Next step

Want this handled for good?

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