fix: Recover GitHub installation lookup from invalid OAuth tokens - #5087
Open
mvanhorn wants to merge 2 commits into
Open
fix: Recover GitHub installation lookup from invalid OAuth tokens#5087mvanhorn wants to merge 2 commits into
mvanhorn wants to merge 2 commits into
Conversation
Author
|
Pushed 8c79dbe. The test asserted on a lowercase |
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.
Description
Extend the existing token lifecycle in
Lightning.VersionControlso an installations request rejected with401gets one recovery attempt when the stored grant has a usable refresh token: refresh and persist the OAuth token, rebuild the bearer client, and retry the installations request exactly once. If refresh is unavailable or fails, or the retry is also unauthorized, return the existingGithubError.invalid_oauth_token/2contract soGithubSyncComponentrenders its current profile/reconnect guidance; preserve the existing raw error behavior for non-authentication GitHub failures. Keep this logic in the production installation-fetch path rather than introducing a test-only seam, and record the user-visible fix in the changelog.The project GitHub Sync settings load a user's installations through
Lightning.VersionControl.fetch_user_installations/1, and the installation selector remains disabled when that asynchronous request fails. Locally expired access tokens are already refreshed, but a401returned by GitHub is reduced to an untyped response body, so the LiveComponent treats an authentication failure like a generic API outage. Users therefore receive refresh-or-contact-support guidance instead of an automatic recovery attempt or the existing invalid-token reconnect guidance.Closes #4972
Validation steps
This PR adds unit and LiveView tests covering the cases below. They are included in the diff but were not executed in my local environment, so CI is the first run.
401, its valid refresh token produces a replacement token, and the single retried installations request succeeds; asserts the replacement is persisted and installations are returned.401cannot be refreshed because the grant is non-refreshable or GitHub rejects the refresh; asserts the result is an:invalid_oauth_tokenGithubErrorwithout repeatedly calling the installations endpoint.401; asserts the retry stops after one attempt and returns the typed invalid-token error.500remains a generic GitHub API failure and does not trigger token refresh.Additional notes for the reviewer
The retry is deliberately capped at exactly one attempt so a persistently rejected grant cannot loop against the installations endpoint. Non-authentication failures are left on their existing path so this change does not alter behavior for GitHub outages.
AI Usage
AI was used for assistance.
Pre-submission checklist
:owner,:admin,:editor,:viewer) - not applicable: this change does not touch authorization policies.