Repository navigation
Conversation
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).

This is for the cleanup.
Description
Sets
tokenOptions.issfromkeyFileclient_emailwhen fetching GoogleToken credentials.Impact
Fixes
invalid_granttoken errors when authenticatingGoogleTokenusing akeyFile.Changes
this.tokenOptions.iss = this.tokenOptions.iss || credentials.clientEmailinTokenHandler.processCredentials()when loading credentials fromkeyFile.test.tokenHandler.tsverifyingissis populated fromkeyFileand existingissvalues are preserved.Testing
core/packages/google-auth-library-nodejs/test/gtoken/test.tokenHandler.ts.Alternatives
TokenHandler.processCredentials()unchanged would continue causingGoogleTokeninstances configured withkeyFile(without an explicitissoremail) to omit theissclaim in signed JWT assertions.Fixes #9469