fix(google-auth-library): [cleanup] set iss from keyFile clientEmail by feywind · Pull Request #9676 · googleapis/google-cloud-node · GitHub
Skip to content

fix(google-auth-library): [cleanup] set iss from keyFile clientEmail - #9676

Draft
feywind wants to merge 2 commits into
googleapis:mainfrom
feywind:cleanup/gh9469-gtoken-keyfile-iss
Draft

feywind wants to merge 2 commits into
googleapis:mainfrom
feywind:cleanup/gh9469-gtoken-keyfile-iss

Conversation

@feywind

@feywind feywind commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

This is for the cleanup.

Description

Sets tokenOptions.iss from keyFile client_email when fetching GoogleToken credentials.

Impact

Fixes invalid_grant token errors when authenticating GoogleToken using a keyFile.

Changes

  • Set this.tokenOptions.iss = this.tokenOptions.iss || credentials.clientEmail in TokenHandler.processCredentials() when loading credentials from keyFile.
  • Add unit test coverage in test.tokenHandler.ts verifying iss is populated from keyFile and existing iss values are preserved.

Testing

  • Added unit test assertions in core/packages/google-auth-library-nodejs/test/gtoken/test.tokenHandler.ts.

Alternatives

  • Leaving TokenHandler.processCredentials() unchanged would continue causing GoogleToken instances configured with keyFile (without an explicit iss or email) to omit the iss claim in signed JWT assertions.

Fixes #9469

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the TokenHandler to ensure that tokenOptions.iss is set to credentials.clientEmail if it is not already defined, and adds corresponding unit tests to verify this behavior. The feedback suggests using the nullish coalescing operator (??) instead of the logical OR operator (||) to avoid unintentionally overwriting an empty string value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the nullish coalescing operator (??) is safer than the logical OR operator (||) here. If this.tokenOptions.iss is explicitly set to an empty string "", using || would unintentionally overwrite it with credentials.clientEmail, whereas ?? correctly preserves any defined string value (including empty strings).

Suggested change

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

google-auth-library: JWT with a JSON keyFile signs without iss since 10.6.1 (invalid_grant: account not found)

1 participant