Add method to retrieve resource Project ID from GoogleCredentials
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.
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?
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.
@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?
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.
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.
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.