googleapis / google-auth-library-nodejs

🔑 Google Auth Library for Node.js
Apache License 2.0
1.71k stars 374 forks source link

OAuth2Client.getIdToken() #1726

Closed mbrevda closed 7 months ago

mbrevda commented 8 months ago

it would be great if a OAuth2Client.getIdToken() method could be added. Currently, OAuth2Client.getAccessToken() exists, which allows getting an access token with automatic refresh if necessary. It would be handy if this were available for other tokens as well, such as the id token. Alternatively, a method that auto-refreshed and returned all credentials could be just as useful.

danielbankhead commented 8 months ago

This was historically done by design as not all classes extending from OAuth2Client had, or should have, idTokens. Here are a few that do today (via fetchIdToken):

https://github.com/googleapis/google-auth-library-nodejs/blob/1a7ba87d42661e5b51c6751ccbbc66e226d9e830/src/auth/computeclient.ts#L103-L122

https://github.com/googleapis/google-auth-library-nodejs/blob/1a7ba87d42661e5b51c6751ccbbc66e226d9e830/src/auth/impersonated.ts#L216-L236

https://github.com/googleapis/google-auth-library-nodejs/blob/1a7ba87d42661e5b51c6751ccbbc66e226d9e830/src/auth/jwtclient.ts#L189-L207

By chance if you are looking for this functionality in the UserRefreshClient, which extends OAuth2Client, that can be tracked here: