Repository navigation
Description
Summary
Non-expiring upstream tokens (Slack user tokens, GitHub user tokens) are incorrectly marked as expiring in 1 hour, causing the refresh path to fire unnecessarily and — when the provider returns the same non-expiring token — creating churn or failures on subsequent lookups.
Root cause
pkg/authserver/upstream/oauth2.go:224-228 fabricates a 1-hour expiry whenever the upstream token response has no expires_in:
expiresAt := token.Expiry
if expiresAt.IsZero() {
// Default to 1 hour if not specified
expiresAt = time.Now().Add(defaultTokenExpiration)
}convertOAuth2Token is called from both the initial code exchange (ExchangeCode, line ~455) and subsequent refreshes (RefreshTokens, line ~495), so the fabricated expiry taints every leg.
Downstream code at pkg/auth/upstreamtoken/service.go:104-108 explicitly special-cases a zero ExpiresAt as "never expires, don't refresh":
if tokens.ExpiresAt.IsZero() || !tokens.IsExpired(time.Now()) {
result[providerName] = tokens.AccessToken
continue
}This correct branch is defeated by the fabricated 1h value.
Affected providers
Any upstream that does not return expires_in:
- Slack user tokens (non-rotating, do not expire)
- GitHub user access tokens without expiration
- Any OAuth 2.0 provider configured to issue long-lived tokens
Proposed fix
Two changes are required — removing only the oauth2.go fabrication is insufficient because the storage layer also applies a default TTL.
-
pkg/authserver/upstream/oauth2.go:224-228— delete theif expiresAt.IsZero()block and letExpiresAtremain zero. Also remove the unuseddefaultTokenExpirationconstant at line 93-94. -
Storage layer default TTL —
pkg/authserver/storage/memory.go:705-712andpkg/authserver/storage/redis.go:888-896currently apply a default TTL to upstream token records whenExpiresAtis zero. For records explicitly marked as non-expiring, they should be stored with no TTL (memory) or a configured long TTL (Redis). Alternatively, carry a separateNeverExpires boolfield onUpstreamTokensto disambiguate.
Related
Compounds with #5047 to produce the observed symptom of "all upstream providers require re-authorization every ~24 hours." This issue (fake expiry) triggers the re-authorization cascade; the linked issue (session-keyed storage + callback token clobber) ensures the cascade is fatal.
Reproduction
- Configure ToolHive with a Slack OAuth upstream.
- Complete initial authorization. Observe Slack token is stored.
- Wait 1 hour.
- Trigger a downstream request that reads the Slack token.
- Observe the refresher is invoked even though Slack issued a non-expiring token.
Activity
Remove fabricated 1h expiry for non-expiring upstream tokens
Fix non-expiring upstream token handling and storage TTL bugs (#5092)