Repository navigation
Match access-token TTL to the II grant duration the user picks - #43
Merged
Merged
Conversation
The OAuth access token was hard-capped at 1h (TOKEN_TTL) regardless of the session duration chosen on Internet Identity's connect consent screen, and no refresh token is issued. So a user who selected e.g. "1 week" still had their client's token expire after ~1h and — with nothing to refresh against — had to re-run the full interactive authorization-code flow (surfaced as "reconnect"). The longer II grant was effectively unusable by the client. Make the token's lifetime track the grant instead of capping it at a fixed 1h: `token_ttl` (formerly `capped_token_ttl`) now returns the grant's full remaining lifetime when known, so the session duration the user picks (10 minutes up to 30 days) is exactly how long the client's token stays valid. The token and the grant now share the same lifetime and blast radius. A fixed default (1h) is kept only as a fallback for when the grant expiration is unknown at issue time (e.g. a dropped connect-completion POST); the grant remains the hard ceiling at II either way. This keeps refresh tokens / server-side persistence out of scope. Update the unit test, README Auth section, and the info-page copy accordingly. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01RCkvMCzbnnFouKCAnuCpCz
There was a problem hiding this comment.
Pull request overview
This PR fixes premature reconnects by aligning the OAuth access-token TTL with the Internet Identity (II) grant duration the user selects, instead of hard-capping tokens at 1 hour when no refresh token exists.
Changes:
- Removes the 1-hour cap when the II grant expiration is known, so access tokens last for the full remaining grant lifetime.
- Keeps the 1-hour
TOKEN_TTLas a fallback only when the grant expiration is unknown at issuance time. - Updates user-facing documentation/copy and adjusts the unit test to assert long grants mint long-lived tokens.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/auth.rs |
Updates token TTL calculation to track the II grant expiration (with fallback when unknown) and updates the associated unit test. |
src/main.rs |
Updates user-facing info-page copy to reflect session duration can be up to 30 days. |
README.md |
Updates auth documentation to describe token lifetime tracking the II grant and clarifies why refresh tokens remain out of scope. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
A user who set their MCP session to e.g. 1 week on Internet Identity's connect consent screen still had to reconnect after ~1 hour. Root cause: the OAuth access token was hard-capped at 1h (
TOKEN_TTL) regardless of the grant duration chosen, and no refresh token is issued. So the client's token always died at ≤1h and — with nothing to refresh against — had to re-run the full interactive authorization-code flow (surfaced as "reconnect"). The longer II grant was effectively unusable by the client.The chosen fix (no refresh tokens, no server-side persistence): make the access token's lifetime track the II grant instead of capping it at a fixed 1h.
Changes
src/auth.rscapped_token_ttl→token_ttl: when the grant expiration is known, return its full remaining lifetime (the old.min(TOKEN_TTL)cap is gone), so the session duration the user picked (10 min up to 30 days) is exactly how long the client's token stays valid. An already-expired grant still yields a zero TTL (token born invalid → steer to re-auth).TOKEN_TTL(1h) is retained only as a fallback for when the grant expiration is unknown at issue time (e.g. a dropped connect-completion POST). The II grant is the hard ceiling either way.token_ttl_tracks_grant_expiration) to assert a long grant now mints a correspondingly long token.README.md— Auth section now describes the token tracking the grant, and why refresh tokens stay out of scope (nothing to refresh against until the grant lapses).src/main.rs— info-page copy: "lasts ~60 minutes" → "lasts for the session duration you choose when connecting (up to 30 days)".Notes / trade-offs
GRANT_TTL_SECS), which only seeds the picker's initial selection; a user who doesn't change it gets a 1h grant → 1h token. Bumping that default is a separate UX choice, left out of this change.Testing
cargo test --bins— all 74 unit tests pass; crate compiles with no new warnings (only the pre-existingtool_routerdead-code warning).🤖 Generated with Claude Code
https://claude.ai/code/session_01RCkvMCzbnnFouKCAnuCpCz
Generated by Claude Code