Repository navigation
fix(account): redirect native OAuth2 logins straight to the app callback - #13970
Conversation
When a native OAuth2 session uses the default success or failure URL,
the redirect endpoint now sends the browser directly to
appwrite-callback-{projectId}:// with the same query the console relay
page used to forward (project, domain, key, secret, or error). Native
login no longer depends on a console page loading and running
JavaScript before it hands control back to the app.
Custom success and failure URLs, and the token flow, are unchanged.
🔵 Tier A · Mergeable after minor fixes
The OAuth2 redirect endpoint sends matching console success and failure relay URLs directly to the project-specific native app callback, while leaving custom URLs on their existing paths. E2E tests cover the default failure redirect and a successful mock-provider login through to the app callback. Latest changes: The newest commit reuses the mock OAuth flow helper for the default success test and replaces its query-field assertions with a request authenticated using the returned session cookie.
📂 Walkthrough · 2
Reviewed the commits since |
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
| // Native SDKs store the handoff as their session cookie | ||
| $response = $this->client->call(Client::METHOD_GET, '/account', [ | ||
| 'origin' => 'http://localhost', | ||
| 'content-type' => 'application/json', | ||
| 'x-appwrite-project' => $projectId, | ||
| 'cookie' => ($query['key'] ?? '') . '=' . ($query['secret'] ?? ''), |
There was a problem hiding this comment.
Keep checking the project in the native callback query
The account request proves the cookie works, but it still succeeds if the redirect stops including project (or domain) in its query. Those fields are part of the native callback contract this test covers; retain assertions for them alongside the authentication check.
🟡 Minor · testing · Reply if this doesn't apply.
What does this PR do?
Native SDKs (Flutter, Android, Apple) call
createOAuth2Sessionwithout a success URL. Until now, the redirect endpoint then sent the login browser to the console's relay page (/auth/oauth2/successor/auth/oauth2/failure). That page read the query and ranwindow.location.href = "appwrite-callback-{projectId}://?…"to return to the app.With this change, when the success or failure URL is that console relay (same host and path, as already checked), the redirect endpoint sends a 301 straight to
appwrite-callback-{projectId}://with the query the relay used to forward:https://<console>/auth/oauth2/success?project=…&domain=…&key=…&secret=…appwrite-callback-{projectId}://?project=…&domain=…&key=…&secret=…https://<console>/auth/oauth2/failure?error=…&project=…appwrite-callback-{projectId}://?error=…&project=…The SDKs receive the same callback URL they got from the relay, so they need no changes. Custom success and failure URLs (web apps) are unchanged. The token flow is also unchanged; with an
appwrite-callback-…://success URL it already redirects straight into the app.Why: native login currently depends on a console page loading and running JavaScript before it hands control back to the app.
/sign-in. Until that fix, native users landed on the console login screen instead of returning to their app.A relay URL passed explicitly on the console host is handled the same way. The relay page only forwards its query string to
appwrite-callback-{projectId}://, so the user lands in the same place, just without the page in between. The same path on any other host is left alone.Test Plan
appwrite-callback-{projectId}://?…instead of the console relay.success=appwrite-callback-{projectId}://: unchanged.AccountCustomClientTest --filter OAuthpasses (12 tests).testOAuthDefaultSuccessRedirectsToApp: omitssuccessand asserts theappwrite-callback-{projectId}://redirect withproject,keyandsecret.testOAuthDefaultFailureRedirectIncludesProjectnow asserts the same redirect for failures.parse_url(), which returnsfalsefor a scheme with no host.main, where the redirect goes to the console relay URL.Related PRs and Issues
Checklist