Skip to content

Auto-detect a project ID #1653

@jmdobry

Description

@jmdobry

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 the GCLOUD_PROJECT env var or explicitly pass a project ID to a client for google-cloud-node to work.

Steps to reproduce

  1. Install the Google Cloud SDK, git, Node.js and NPM
  2. Run gcloud init, you'll be prompted to set a default project
  3. Run gcloud beta auth application-default login and follow the OAuth 2.0 flow to login
  4. Clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
  5. Run cd nodejs-docs-samples/storage
  6. Run npm install
  7. Run node buckets.js list

Observe the error:

Error: Sorry, we cannot connect to Google Cloud Services without a project ID. You may
specify one with an environment variable named "GCLOUD_PROJECT". See
https://googlecloudplatform.github.io/google-cloud-node/#//docs/guides/authentication
for a detailed guide on creating an authenticated connection.
  1. Modify buckets.js to explicitly pass in a project ID
  2. Run node buckets.js list
  3. It works
  4. Undo your changes to buckets.js
  5. Set the GCLOUD_PROJECT env var to your project ID
  6. Run node buckets.js list
  7. It works

Expected

  1. Open terminal
  2. Run cd nodejs-docs-samples/storage
  3. Run gcloud beta auth application-default login
  4. Run node buckets.js list (No env vars are set, code does not pass project ID to client)
  5. It works

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions