Visitar URL original
Add method to retrieve resource Project ID from GoogleCredentials · Issue #1614 · googleapis/google-auth-library-java · GitHub
Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.
This repository was archived by the owner on May 12, 2026. It is now read-only.

Add method to retrieve resource Project ID from GoogleCredentials #1614

Closed

Description

@psx95

Is your feature request related to a problem? Please describe.
GoogleCredentials currently does not provide access to the resource project ID.

It only has method to provide access to the currently used Quota Project ID, which may be different from the resource project ID.

Describe the solution you'd like
A method to retrieve the current resource project ID. Similar methods exists in classes derived from GoogleCredentials such as ServiceAccountCredentials.

Additional context
I'm using this library to retrieve ADCs to authenticate to Google services. Due to the absence of a method to retrieve resource Project ID, the user is required to explicitly set the resource project ID.

Activity

  1. added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on Jan 27, 2025
  2. lqiu96 commented on Jan 27, 2025

    @lqiu96
    Member

    Can you provide a more details or an example of where you would need to retrieve the Project ID? From a search, I see that there are currently only two *Credential* classes that offer this (GdchCredentials and ServiceAccountCredentials).

    Which *Credential* class are you using that requires this? Or is it just that user is required to explicitly set the resource project ID is an annoyance?

  3. psx95 commented on Jan 31, 2025

    @psx95
    ContributorAuthor

    Hi @lqiu96,
    Thank you for your response. I am using the GoogleCredentials class.

    No *Credential* class requires user project ID to function, at least for my use case.

    It is mostly a user annoyance and could lead to better UX if resolved.

    Additional Context on Use-Case

    I am retrieving the Application Default Credentials for an auth extension I am working on. Here is the code that retrieves the credentials.

    The credentials object I receive has no method to retrieve the user project ID. Absence of this method results in no reasonable default and forces the user to input the project ID.

    The end goal is to achieve something similar to this logic defined in a similar GCP Go auth extension.

  4. lqiu96 commented on Feb 5, 2025

    @lqiu96
    Member

    @sai-sunder-s Wanted to get your thoughts on this whenever you get a chance. I don't think this sounds unreasonable but I'm not entirely sure if all of ADC will be able to have a project_id (and if not, what would a reasonable default be (empty string, null?)). Do you know how this is implemented for Python or other auth languages?

    Would something like this be only scoped for ADC Credentials or maybe also 3PI Creds?

  5. psx95 commented on Feb 10, 2025

    @psx95
    ContributorAuthor

    I can tell that for Golang Google OAuth2 library, the credentials returned from ADC may not always contain project_id and the Golang library handles it using empty strings.

  6. psx95 commented on Aug 20, 2025

    @psx95
    ContributorAuthor

    Hi @lqiu96 and @sai-sunder-s , any updates or plans on implementing this ? I have a feature request for an authentication extension that could benefit from this addition.

    I noticed that google-auth library for Python also returns the project ID - it would be great if we could have it for Java as well.

  7. lqiu96 commented on Oct 8, 2025

    @lqiu96
    Member

    Taking another look at this. I don't have any concerns with exposing a getProjectId() method from GoogleCredentials. We can default to something like null or "".

    From what I see GdchCredentials and ServiceAccountCredentials can override this with the valid ProjectId.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p2Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions