googleapis / googleapis/google-cloud-node
Add `eagerRefreshThresholdMillis` parameter to the `IdTokenClient` to prevent getting invalid token on `getRequestHeaders`
- Dominant language
- TypeScript
- Stars
- 3.2k
- Forks
- 712
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 99
Description
Hi,
**Is your feature request related to a problem?.**
Yes, we are using the library to make http calls to a GCP Cloud Run service with the `IdTokenClient`. But sometimes, we have a `401` because the token is expired.
After investigation, those `401` occure when the token is about to expire. The root cause is a clock delay on the system calling system.
**Describe the solution you'd like**
We want to be hable to pass a parameter, like `eagerRefreshThresholdMillis` in `OAuth2Client` , to force refresh token x millisecond before the end.
**Describe alternatives you've considered**
To mitigate the issue, we have overrided the `getRequestMetadataAsync` in `IdTokenClient` to take into account a custom `eagerRefreshThresholdMillis` at this [line](https://github.com/googleapis/google-auth-library-nodejs/blob/3035c9d4ab3e6fd6ca779d99cd3b6fbdaba8b853/src/auth/idtokenclient.ts#L55) .
**Additional context**
We create the client with `googleAuth.getIdTokenClient(targetAudience)` and get the token (auth headers) with `getRequestHeaders`
Contributor guide
Assessment
This issue has not been assessed yet.