-
Notifications
You must be signed in to change notification settings - Fork 604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-detect a project ID #1653
Comments
Is there a spec for where we're supposed to look for a project ID? I think that's ... kind of scary. |
We throw the error because a project ID wasn't specified. We get the auth client-- we can auth requests-- but we need the projectId for the construction of the URL to send the requests to. Is there an environment variable with the projectId that's set when |
It's definitely stored somewhere, but it's definitely not an environment variable:
I think it's a tiny bit scary to pull from a file. Totally fine to pull from an env variable. Can we look through how this might go wrong if we pull from a file somewhere? If there's nothing too nasty, we should add this to the list of stuff to do. |
It looks like it's in It would be nice if this was simply an env var-- is it possible to squeeze that feature into the SDK directly? If not, it doesn't bother me to read from the file, as long as my logic above is correct. In the worst case, it can't find it, and the program continues without the projectId, throwing the mesage that the user must set the |
@jonparrott Can you chime in on how google-cloud-python does it? |
I think google-cloud-python (well actually, github.com/google/oauth2client) looks for a file named On Mac would be located at |
So perhaps this needs to be solved in https://github.com/google/google-auth-library-nodejs |
That file is read from google-auth-library (https://github.com/google/google-auth-library-nodejs/blob/02f587472ecdc2582f8d5fc754996aa6ef9388a0/lib/auth/googleauth.js#L231), but that file doesn't have the projectId in it-- at least not for me. |
Nice! That looks like it's one step simpler than my approach in #1656, which reads the |
I think first, get to feature parity with google-cloud-python on implicitly determining the project ID. Then open another issue to investigate the |
I'd recommend doing it in the auth library if possible, as the new python auth library will work like this: import google.auth
credentials, project_id = google.auth.default() Here's the implementation (based on the google-cloud-python As for |
Sounds good, thanks for the link. I'm putting this functionality in its own module so that it can be used from the auth library, maybe: var googleAuth = new GoogleAuth();
googleAuth.getApplicationDefault(function(err, authClient) {
authClient.projectId === already detected & populated
}); |
The big benefit for doing it within the same code that does ADC is that the same machinery is used to get the credentials and the project. So, it could simplify the implementation to do both at once. (But it's totally up to you) |
I agree with @jonparrott, this should be added to https://github.com/google/google-auth-library-nodejs |
Re: default vs active I think it's for supporting multiple configurations by using But, the implementation can change, so how about to call |
I'm +1 on that code going into google-auth-library. Created an issue: googleapis/google-auth-library-nodejs#97 We'll keep this issue open here until that's implemented, then make the required changes here to honor it. |
Looks like googleapis/google-auth-library-nodejs#97 got closed by associated PR (googleapis/google-auth-library-nodejs#98) a few minutes ago. |
Yep, getting close! Still a few more steps #1656 |
I think my problem belongs to this thread, because I struggled with the authentication process as jmdobry described above as well. I am working with the tutorial sample code for the Speech API provided here: https://cloud.google.com/speech/docs/rest-tutorial (I am working with Node.js) I have modified some lines in that tutorial sample code in order to get around the above mentioned error:
.1. I took the following lines from
.2. Also I changed this line here in the tutorial sample code from / to:
.3. I changed this line here as well from / to :
.4. And I added the utils module to the node_modules file with
These changes let me pass to the next step – to the CLI down at the bottom of the tutorial sample code:
I tried every example, yet I get the following error :
Why is this TypeError happening? Can anyone help me, please. |
@thetittenquetscher You should move your question to the nodejs-docs-samples repository. Your error was caused by changing |
@jmdobryThe provided link helped me run the samples. Thank you. |
In case someone lands here looking for a solution when this happens in cloudshell, have a look to: https://stackoverflow.com/a/60153817/3198983 You'll basically have to run this line with your project id, which might be the name:
|
Problem
After running
gcloud beta auth application-default login
I should be able to use google-cloud-node to access Google Cloud Platform services, but I can't. I must set theGCLOUD_PROJECT
env var or explicitly pass a project ID to a client for google-cloud-node to work.Steps to reproduce
gcloud init
, you'll be prompted to set a default projectgcloud beta auth application-default login
and follow the OAuth 2.0 flow to logincd nodejs-docs-samples/storage
npm install
node buckets.js list
Observe the error:
buckets.js
to explicitly pass in a project IDnode buckets.js list
buckets.js
GCLOUD_PROJECT
env var to your project IDnode buckets.js list
Expected
cd nodejs-docs-samples/storage
gcloud beta auth application-default login
node buckets.js list
(No env vars are set, code does not pass project ID to client)The text was updated successfully, but these errors were encountered: