Repository navigation
Conversation
Expiry is not the only way a token dies. GitHub revokes an installation token when the App is suspended, when its permissions change, on an explicit revocation, and it revokes every token for an installation when the private key is rotated. A cache keyed on expiry cannot see any of that. It keeps serving the dead credential, and every request 401s, until the hour is up. There was no recovery short of restarting the process. Invalidate discards the cached token so the next call mints a fresh one, exposed both as an Invalidator interface and as a package-level helper that saves callers a type assertion on the oauth2.TokenSource the constructors return. It reports false for a source with nothing to discard, so a caller can tell "cleared" from "nothing to clear" rather than having a no-op pass silently. The skew<=0 path previously returned oauth2.ReuseTokenSource directly, which exposes no way to clear its cache. It now returns a thin wrapper that replaces the delegate on Invalidate, so invalidation works whatever the skew. Refresh timing is unchanged, including oauth2's own ten-second early-expiry delta, and a test pins that boundary from both sides.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64 +/- ##
==========================================
+ Coverage 96.94% 97.08% +0.13%
==========================================
Files 4 4
Lines 295 309 +14
==========================================
+ Hits 286 300 +14
Misses 9 9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Expiry is not the only way a token dies. GitHub revokes an installation token when the App is suspended, when its permissions change, on an explicit revocation, and it revokes every token for an installation when the private key is rotated. A cache keyed on expiry cannot see any of that, so it keeps serving the dead credential and every request 401s until the hour is up. There is currently no recovery short of restarting the process.
Invalidatediscards the cached token so the next call mints a fresh one.Changes
Invalidatorinterface and a package-levelInvalidate(src) boolhelper, saving callers a type assertion on theoauth2.TokenSourcethe constructors returnInvalidatereportsfalsefor a source with nothing to discard, so a caller can distinguish "cleared" from "nothing to clear" rather than having a no-op pass silentlyskew <= 0path returns a thin wrapper instead ofoauth2.ReuseTokenSourcedirectly, since the latter exposes no way to clear its cache; invalidation now works whatever the skewdoc.go, the README andllms.txtRationale
Invalidateaffects only the source it is called on, because an installation token and the application JWT behind it are different credentials with different lifetimes and a 401 does not say which one failed. The wrapper on theskew <= 0path replaces its delegate rather than reaching inside it, sooauth2's refresh timing — including its own ten-second early-expiry delta — is untouched.Test_ReuseTokenSourceWithSkew_ZeroSkewKeepsOAuth2Timingpins that boundary from both sides, andTest_Invalidate_Concurrentexercises invalidation against concurrent readers under-race, since a revocation arrives while requests are in flight.Migration Notes
Purely additive; no existing behaviour changes. The source returned for
skew <= 0is no longer literally anoauth2.ReuseTokenSource, so code type-asserting on that concrete type would be affected — it still satisfiesoauth2.TokenSourceand refreshes identically.