Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

auth.getIdTokenClient() does not honour gcloud auth application-default login #1543

@mbyrne00

Description

@mbyrne00

Summary

When I test/run code locally using auth.getIdTokenClient("https://my-target-audience") will always yield the error below, despite setting application default credentials using gcloud auth application-default login. Other google libs are working fine using this.

Cannot fetch ID token in this environment, use GCE or set the GOOGLE_APPLICATION_CREDENTIALS environment variable t o a service account credentials JSON file.

  1. Is this a client library issue or a product issue?
    A client library issue.

  2. Did someone already solve this?
    No

  3. Do you have a support contract?
    No

Environment details

  • OS: MacOS
  • Node.js version: 18.14.0
  • npm version: 9.3.1
  • google-auth-library version: 8.7.0

Steps to reproduce

  1. Grant credentials with a privileged account using gcloud auth application-default login
  2. Execute the following code from somewhere in your codebase in an async function
    const auth = new GoogleAuth();
    await auth.getIdTokenClient(this.analysisBaseUrl)
    console.log("All good");
    
  3. 💥 - the following error is shown and the console log does not execute

Cannot fetch ID token in this environment, use GCE or set the GOOGLE_APPLICATION_CREDENTIALS environment variable t o a service account credentials JSON file.

If you export a JSON key and provide it via the environment variable GOOGLE_APPLICATION_CREDENTIALS then it will work. The other google libs, however, negate the need for this by supporting the application-default login and thus not needing privileged service account JSON keys stored locally.

I've also noticed others with this issue, for example when I came across this post: https://stackoverflow.com/questions/72685175/application-default-credentials-http-trigger-gcp-function-from-local-nodejs-appl

Metadata

Metadata

Assignees

Labels

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