Repository navigation
fix: Test linked git provider tokens on the Integrations page (OHE-3741) - #1006
Merged
Merged
Conversation
Add oauth_tokens.invalidated_at and POST /oauth/git-providers/{id}/check,
which calls the provider's API once with the stored token: a 401 or a
rejected refresh token (invalid_grant / GitHub bad_refresh_token) flags the
row, success clears it, and timeouts/5xx change nothing. GET
/oauth/git-providers now reports needs_reconnect.
The Integrations page runs the check for each linked provider on load, adds
a Test connection button, and shows Reconnect (the existing link flow) when
the token was rejected.
Co-authored-by: openhands <openhands@all-hands.dev>
Contributor
|
|
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Main already has migrations 198-200, so this PR's 198 created a second head. Rebase it onto 200. Co-authored-by: openhands <openhands@all-hands.dev>
…ion check A row is a git provider when its provider_type is in GIT_PROVIDER_TYPES, regardless of is_idp. The check endpoint 404'd for e.g. GitHub configured as the login IDP, even though the list endpoint shows it. Co-authored-by: openhands <openhands@all-hands.dev>
tofarr
marked this pull request as ready for review
October 27, 2026 16:12
…ng it The test pinned the head revision to '200', so it broke as soon as migration 201 landed on top of it. Co-authored-by: openhands <openhands@all-hands.dev>
hieptl
added a commit
that referenced
this pull request
Oct 27, 2026
…storage-api-and main now holds migration 201 (oauth_token.invalidated_at, #1006), so the Model Router migration moves from 201 to 202 chaining off 201. The agent-profile upgrade test takes main's _head_revision() lookup in place of the literal head pin.
Contributor
|
🚀 Released in 1.81.0. |
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.
HUMAN:
This helps us accommodate the case where a provider has revoked a token but the service is not yet aware.
AGENT:
Why
With
ENABLE_OAUTH_V2_LOGINon,/settings/integrationsshows a git provider as connected whenever anoauth_tokensrow exists, even after the provider has revoked the token. Normal traffic can't be relied on to notice.ProviderHandler.get_user()(behindgit-info) stops at the first provider that works, so a dead token for a second provider is never used. A 401 inside the sandbox never reaches the server. Testing the token from the Integrations page is the cheap, reliable way to keep that page accurate.Summary
oauth_tokens.invalidated_atcolumn (migration198) and new routePOST /oauth/git-providers/{id}/check(server/auth/git_token_check.py). The route calls the provider'sget_user()once with the stored token, refreshing first only if the token has expired.invalid_grant, or GitHub'sbad_refresh_token), sets the flag. Success clears it.unavailableand change nothing.GET /oauth/git-providersnow returnsneeds_reconnect.flowchart LR A[Card mounts / Test connection] --> B[POST /oauth/git-providers/:id/check] B --> C{token expired?} C -- yes --> D[refresh] D -- invalid_grant / bad_refresh_token --> F[set invalidated_at → invalid] D -- 5xx / timeout --> U[unavailable, no change] C -- no --> E[GitService.get_user] D -- ok --> E E -- 401 --> F E -- 200 --> V[clear invalidated_at → valid] E -- other error --> UIssue Number
OHE-3741 (partial: the
needs_reconnect/ Integrations part)How to Test
Automated (all passing locally):
uv run pytest tests/unit/server/auth/test_git_token_check.py tests/unit/server/auth/test_oauth_v2_refresh.py tests/unit/server/routes/test_oauth_v2_routes.py tests/unit/storage/test_oauth_stores.py. The token store and check tests run against real PostgreSQL; only the provider API is mocked.tests/unit/server/auth,tests/unit/storage,test_users_v1.pyand the middleware tests (787 passed).cd frontend && npx vitest run __tests__/routes/git-settings.test.tsx __tests__/components/features/settings/(380 passed), plusnpm run lintandnpm run build.Manual (not done yet, needs a real provider):
ENABLE_OAUTH_V2_LOGIN, link GitHub on/settings/integrations, then revoke the app's authorization on GitHub./settings/integrations. The GitHub card should show "Reconnect required" with a Reconnect button.Video/Screenshots
Screen.Recording.2026-10-27.at.4.11.34.PM.mov
Type
Notes
198adds one nullable column. The upgrade runs as part of the test database template; the downgrade wasn't run.SaasUserAuth._v2_get_provider_tokensand the middleware). That behaviour is unchanged here.git-infoor other normal use doesn't set the flag yet.RefreshTokenRejectedErrorsubclassesValueError, so existingexceptblocks around refresh behave exactly as before._idp_token_hostfromsaas_user_authso self-hosted GitLab, Bitbucket Data Center and Forgejo resolve the same host as normal token use.declaration.ts: also movesAUTH$GIT_PROVIDER_LOGIN_FAILED, because the repo'sprelint/buildregeneration produces that order and main's copy was out of date.This PR was created by an AI agent (OpenHands) on behalf of the user.
@tofarr can click here to continue refining the PR
Enterprise server image for this PR: