auth: expose AccessToken expiration
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- rust
- Domain
- authentication, backend-api-design
Research direction
Start by reading src/auth/src/token.rs and src/auth/src/credentials.rs, especially the token expiry tracking and conversion linked in the issue. Review #7391 and the semver concern described here to understand the proposed API shape. Done means callers can obtain the token and its optional expiration without adding a breaking field to AccessToken; add or update focused auth tests for known and unknown expirations.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
I have a short-lived CLI that needs an access token on every run. It keeps the token in a private file between runs (much like gcloud's own token cache), so it needs to know when the token expires.
AccessToken only exposes token. The SDK tracks the expiry internally but drops it in the conversion, so the CLI can't get the lifetime from the SDK. Today it gets tokens from gcloud auth print-access-token and looks up the lifetime with the tokeninfo endpoint after each fetch.
Describe the solution you'd like
A way to get the expiration along with the token, or None when it isn't known. This was part of the original sketch in #2929, and #7391 implements it as a field. An Instant is fine for my use; I'd convert it to wall-clock time when saving.
One semver note: AccessToken has only public fields and isn't #[non_exhaustive], so adding any field, even a private one behind an accessor, breaks struct-literal construction (for example in mocks of AccessTokenCredentialsProvider). cargo-semver-checks reports that as major (constructible_struct_adds_private_field). A new method that returns a #[non_exhaustive] type with the token and its expiry would leave AccessToken unchanged.
The other Google auth libraries already expose this:
- Go:
auth.Token.Expiry - Java:
AccessToken.getExpirationTime() - Python:
Credentials.expiry
Describe alternatives you've considered
- Looking up tokeninfo after each fetch (current workaround): an extra request per token.
- Assuming a one-hour lifetime: unsafe, since lifetimes vary by credential type.
- Fetching a fresh token in every process: works, but adds a token request to every run.
Additional context
On #7391 there was a question of whether this needs to be exposed at all. This is a case where the SDK's in-process cache can't help: the process exits before the token could be reused.
- Dominant language
- Rust
- Stars
- 972
- Forks
- 163
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 202
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from googleapis/google-cloud-rust
-
api: storage
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
googleapis/google-cloud-rust#7344 ·
Maintainers usually reply within 1 day
-
BytesValue in Any rejects unpadded and URL-safe base64Possibly taken @akasakariko claimed this 15 days ago. Openpriority: p2 type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
googleapis/google-cloud-rust#6714 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
type: bug
Difficulty 2/5 Half a day Newbie friendliness 75/100
googleapis/google-cloud-rust#6710 ·
Maintainers usually reply within 1 day
-
type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
googleapis/google-cloud-rust#6709 ·
Maintainers usually reply within 1 day
-
type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
googleapis/google-cloud-rust#6707 ·
Maintainers usually reply within 1 day
All issues in googleapis/google-cloud-rust
Similar issues
-
bug UI
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
wardian-app/Wardian#1746 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
jlcodes99/cockpit-tools#3125 ·
Maintainers usually reply within 2 days
-
bug user-sprint
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Vondor/KassenSturz#967 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
area:build bug effort:low P5 source:agent
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day