Skip to content

fix(account): redirect native OAuth2 logins straight to the app callback - #13970

Merged
HarshMN2345 merged 3 commits into
mainfrom
fix/oauth-native-callback-redirect
Sep 29, 2026
Merged

HarshMN2345 merged 3 commits into
mainfrom
fix/oauth-native-callback-redirect

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Native SDKs (Flutter, Android, Apple) call createOAuth2Session without a success URL. Until now, the redirect endpoint then sent the login browser to the console's relay page (/auth/oauth2/success or /auth/oauth2/failure). That page read the query and ran window.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:

Before After
Success https://<console>/auth/oauth2/success?project=…&domain=…&key=…&secret=… appwrite-callback-{projectId}://?project=…&domain=…&key=…&secret=…
Failure 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.

  • appwrite/vibes#472 fixed a console auth guard that sent signed-out visitors of the relay to /sign-in. Until that fix, native users landed on the console login screen instead of returning to their app.
  • On Cloud the relay loads about 350 requests before it redirects. In an emulated mid-range phone (4x CPU, fast 4G) the handoff took 18.8s.
  • The session secret sits in the URL of a page that also loads third-party scripts.

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

  • Traced every redirect hop on a local API container, before and after the change, using the mock provider:
    • Default session login, success and provider error: now ends at appwrite-callback-{projectId}://?… instead of the console relay.
    • Token flow with success=appwrite-callback-{projectId}://: unchanged.
    • Web login with a custom success URL: unchanged.
  • Ran the full flow in emulated Pixel Chromium: the app callback is reached in 0.1s, whether the browser is signed out, signed in, or holds an expired console cookie.
  • AccountCustomClientTest --filter OAuth passes (12 tests).
    • New testOAuthDefaultSuccessRedirectsToApp: omits success and asserts the appwrite-callback-{projectId}:// redirect with project, key and secret.
    • testOAuthDefaultFailureRedirectIncludesProject now asserts the same redirect for failures.
    • Both read the query without parse_url(), which returns false for a scheme with no host.
    • Both fail against unpatched main, where the redirect goes to the console relay URL.

Related PRs and Issues

  • appwrite/vibes#472

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

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.
@ghost

ghost commented Sep 29, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The success regression test no longer detects missing native callback query fields.

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.

Verdict New comments Fixed Still open
✅ Approved 1 0 0
Finding Where
🟡 Keep checking the project in the native callback query tests/e2e/Services/Account/AccountCustomClientTest.php:3478
📂 Walkthrough · 2
File Change
app/controllers/api/account.php Redirects matching console OAuth2 relay URLs to the native app callback.
tests/e2e/Services/Account/AccountCustomClientTest.php Tests default success and failure callbacks; now verifies the success callback's cookie can authenticate an account request.

Reviewed the commits since 3710156 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

Comment thread app/controllers/api/account.php Resolved
Comment thread app/controllers/api/account.php Resolved
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Critical risk] Changes OAuth2 redirect flow for native app logins.

The PR appears safe to merge based on the reviewed changes and resolved prior findings.

Summary

The PR redirects console-hosted OAuth relay outcomes directly to the native app callback and adds an end-to-end check that the success callback credentials authenticate an account.

  • Custom web redirect URLs remain outside the new relay replacement.
  • The changes since the previous review reuse the OAuth test helper and verify the session handoff through /account.

Reviews (3) · Last reviewed commit: "test(account): assert the default OAuth2..."

Comment thread app/controllers/api/account.php Resolved
Comment thread app/controllers/api/account.php Resolved
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/oauth-native-callback-redirect (after).

Metric Before After Change
🚀 Requests/sec 170.11 185.84 🟢 +9.2%
⏱️ Latency P50 100.32 ms 92.9 ms 🟢 -7.4%
⏱️ Latency P95 240.48 ms 217.2 ms 🟢 -9.7%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 92.9 217.2 11,628 185.84 -23.28
Account 170.63 346.68 612 10.16 -39.19
TablesDB 90.3 169.61 6,324 103.05 -33.17
Storage 85.44 182.66 3,060 51.77 -19.33
Functions 133.97 271.49 1,632 28.28 -20.33

Top API waits (after)

API request Max wait (ms)
account.name.update 549.92
functions.variables.update 438.76
functions.variables.create 394.9
functions.create 394.11
tablesdb.rows.delete 375.79

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

Comment on lines +3478 to +3483
// 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'] ?? ''),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@HarshMN2345
HarshMN2345 merged commit f03ea7d into main Sep 29, 2026
55 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant