Repository navigation
fix(account): keep the current session through the OAuth2 token flow - #13602
Merged
Merged
Conversation
The OAuth2 redirect handler deleted the caller's current session for both flows. That is right for createOAuth2Session, which replaces it with the session it creates and sets the cookie, so the browser stays signed in. createOAuth2Token creates no session there; the app exchanges the returned token through createSession later. Deleting the current session in that flow signed the caller out until the exchange, so a signed-in user connecting a provider landed on the success URL as a guest and any auth guard bounced them before the token could be used. Delete the current session only when the flow creates a replacement. In the token flow the identity is still attached to the signed-in account, the existing session stays valid, and createSession adds a session next to it. - Document the behavior on createOAuth2Token. - E2E: token flow while signed in keeps the session, the exchange adds a second one, and the session flow still replaces the current one. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Contributor
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
The helper only drives the mock provider round trip; the token and session assertions after it establish the behavior. Asserting the private appwrite: callback and redirect URLs coupled the test to routing details. Co-Authored-By: Claude Fable 5.1 <[email protected]>
2 of 4 tasks
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.
What does this PR do?
GET /v1/account/sessions/oauth2/:provider/redirectdeletes the caller's current session whenever a signed-in user completes an OAuth2 flow. ForcreateOAuth2Sessionthat is the intended "replace" behavior: the handler immediately creates the new session and sets its cookie, so the browser stays signed in.createOAuth2Tokenruns through the same handler but creates no session there. The app is expected to exchange the returneduserId+secretthroughcreateSessionafterwards. Deleting the current session in that flow leaves the caller signed out in between: a signed-in user who connects a provider lands on the success URL as a guest, and any auth guard on that page bounces them to sign-in before the token can be exchanged. We hit this in the Console while building one-click SMTP setup with Resend, and had to add a guest-tolerant callback page that restores the session by hand.This PR gives the token flow parity with the session flow regarding the caller's session:
createOAuth2Session).createSessionadds a session next to it.createOAuth2Tokendocs mention the behavior.Test Plan
New e2e
testCreateOAuth2TokenKeepsCurrentSessioninAccountCustomClientTest:secret+userIdfor the same user and sets no cookie.GET /account/sessions/currentwith the original cookie still returns 200 and the same session id. Before this change it returned 401.POST /account/sessions/tokencreates a second session;GET /account/sessionslists both.createOAuth2Sessionis unchanged.Existing OAuth2 e2e tests (
testCreateOAuth2AccountSession,testOAuth2TokenSessionProviderAccessToken, loopback and OIDC token tests) run the token flow without a session cookie and are unaffected.I did not run the e2e suite locally (the only local stack on this machine is bound to a different working copy), so please rely on CI for the run.
php -land Pint pass on the touched files.Related PRs and Issues
feat/smtp-resend-quick-setupworks around this with a guest-tolerant/auth/smtp/callbackroute that restores the session; with this fix the success URL can point straight back at the page that started the flow.Checklist
🤖 Generated with Claude Code