Repository navigation
Conversation
For OAuth v2 cookie sessions, POST /api/email and GET /api/email/verified called SaasUserAuth.refresh(), which decodes the (empty) Keycloak refresh token and raised DecodeError after the address had already changed. - The verification email is sent right after both address writes. - OAuth v2 sessions skip the Keycloak refresh; the cookie carries no email. - A failed legacy refresh returns 200 with reauth_required instead of 500. - /verified marks the address verified only when Keycloak reports it. Fixes #1532 Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Contributor
|
📁 PR Artifacts Notice This PR contains a
|
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
This branch has not been deployed
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.
This PR was created by an AI agent (OpenHands) on behalf of @neubig.
HUMAN:
AGENT:
Why
For an OAuth v2 cookie session,
POST /api/emailchanged the address in Keycloak and in theusersrow. It then calledSaasUserAuth.refresh(), which decodes the Keycloak refresh token. A v2 session has no Keycloak refresh token, so the call raisedjwt.exceptions.DecodeErrorand the route returned500 "An error occurred while updating the email". At that point the address had already changed, but no verification email had been sent.GET /api/email/verifiedhad the samerefresh()call and also crashed.Summary
server/routes/email.py:update_emailsends the verification email right after the two address writes, before any session work.usersrow.200 {"message": "Email changed", "reauth_required": true}instead of a 500 for a change that already happened.verified_emailmarks the address verified only if Keycloak reportsemailVerified. Then it skips the refresh for v2, or does a best-effort refresh for legacy. It always redirects to/settings/user. The check is needed because the route is a plain GET. Before this change, any signed-in session could call it to mark its own address verified (v2 sessions only avoided this because they crashed). Keycloak setsemailVerifiedwhen the user completes the verify-email action, before it redirects here._set_keycloak_cookie.Issue Number
Fixes #1532
How to Test
The new tests call the real routes through
httpx.ASGITransport, with a realSaasUserAuthbuilt from a signedopenhands_authcookie and the realUserStoreon the PostgreSQL test database. Only the Keycloak admin client is an in-memory fake (the external boundary).main: 4 failed (500/DecodeError: Not enough segments).The existing
test_email_routes.pytests were updated for the Keycloak check (15 passed).test_service_account_guard.py,test_auth_middleware.pyandtest_auth_routes.pyalso pass:137 passed.Video/Screenshots
BEFORE (main
0a0b475with only the new test file added):AFTER (this branch):
Type
Notes
.pr/1532/holds only the two screenshots. It is removed automatically when the PR is approved.reauth_requiredyet. It shows the normal success toast, which is now correct: the address changed and the verification email was sent. A follow-up can use the flag to prompt a fresh sign-in.SaasUserAuth.refresh()itself still assumes a Keycloak session. No other route calls it for v2 sessions.Enterprise server image for this PR: