Fix missing resource parameter on cached token restore#4292
Merged
amirejaz merged 2 commits intostacklok:mainfrom Mar 20, 2026
Merged
Conversation
When restoring from cached tokens, token refreshes were using the plain oauth2.Config.TokenSource, which drops the RFC 8707 resource parameter. Use NewResourceTokenSource (exported) on the cached path, matching the existing fresh OAuth flow behaviour.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4292 +/- ##
==========================================
- Coverage 68.95% 68.77% -0.19%
==========================================
Files 473 473
Lines 47854 47917 +63
==========================================
- Hits 33000 32957 -43
- Misses 12266 12298 +32
- Partials 2588 2662 +74 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
amirejaz
requested changes
Mar 20, 2026
amirejaz
approved these changes
Mar 20, 2026
Contributor
|
Approved, thanks for addressing the feedback. |
Sanskarzz
pushed a commit
to Sanskarzz/toolhive
that referenced
this pull request
Mar 23, 2026
* Fix missing resource parameter on cached token restore When restoring from cached tokens, token refreshes were using the plain oauth2.Config.TokenSource, which drops the RFC 8707 resource parameter. Use NewResourceTokenSource (exported) on the cached path, matching the existing fresh OAuth flow behaviour. * Move resource parameter logic into CreateTokenSourceFromCached
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.
When restoring from cached tokens, token refreshes were using the plain oauth2.Config.TokenSource, which drops the RFC 8707 resource parameter. Use NewResourceTokenSource (exported) on the cached path, matching the existing fresh OAuth flow behaviour.
Summary
When a session is restored from cached tokens (i.e. after a process restart), token refreshes were issued without the RFC 8707 resource parameter. This caused the authorization server to return access
tokens with a missing or incorrect aud claim, breaking authentication on any endpoint that strictly validates it. The fresh OAuth flow was already correct — NewResourceTokenSource was introduced in #3713
to handle this — but the cached restore path bypassed it entirely, always falling back to the plain oauth2.Config.TokenSource.
Type of change
Test plan
Stop + start the server with a cached session configured with a resource parameter. Confirmed the restored token source now sends resource on refresh and the server returns tokens with the correct aud
claim.
Special notes for reviewers
The root cause was subtle: CreateTokenSourceFromCached wraps oauth2.Config.TokenSource, which has no knowledge of RFC 8707. The fix mirrors exactly what flow.go:processToken already does — the only missing
piece was exposing NewResourceTokenSource for cross-package use.