Google Cloud Given an OAuth Client ID, how to find the corresponding Google Cloud project

Given an OAuth client ID such as 1234567890-9iuxy238472ny4qmfad0ppg77s61vabo14j0s.apps.googleusercontent.com, how can we find out which Google Cloud project the OAuth client belongs to?

If we look closely at OAuth client IDs, we notice that they follow a common pattern:

NUMBER-GIBBERISH.apps.googleusercontent.com

This pattern isn’t a coincidence: NUMBER is the project number of the Google Cloud project that the OAuth client belongs to, and GIBBERISH identifies the individual Client ID within this project. So the client ID 1234567890-9iuxy238472ny4qmfad0ppg77s61vabo14j0s.apps.googleusercontent.com belongs to project 1234567890.

Armed with this project number, we can use the project picker in the Google Cloud console to find the corresponding project ID:

Project picker

Alternatively, we can use the project.list API to perform a lookup by project number like so:

$ NUMBER=1234567890
curl \
 -H "Authorization: Bearer $(gcloud auth print-access-token)" \
 "https://cloudresourcemanager.googleapis.com/v1/projects?filter=projectNumber%3A$NUMBER"

{
  "projects": [
    {
      "projectNumber": "1234567890",
      "projectId": "my-project-oauth-unverified",
      "lifecycleState": "ACTIVE",
      …
    }
  ]
}

Of course, looking up project details requires that we have access to the project, otherwise we won’t get a result.

Any opinions expressed on this blog are Johannes' own. Refer to the respective vendor’s product documentation for authoritative information.
« Back to home