Skip to content

fix(openapi): declare Location on OAuth2 redirect responses - #14192

Open
HarshMN2345 wants to merge 7 commits into
mainfrom
cursor/oauth2-location-header-9662
Open

HarshMN2345 wants to merge 7 commits into
mainfrom
cursor/oauth2-location-header-9662

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

GET /v1/account/sessions/oauth2/:provider (createOAuth2Session) and GET /v1/account/tokens/oauth2/:provider (createOAuth2Token) answer with a 301, but the OpenAPI spec described them as "No content" with a text/html binary body and no destination.

OpenAPI3 now declares every 301, 302 and 308 response as Redirect with a Location header and no content. 204 responses stay "No content". The only other 3xx routes, the preview-only VCS installation authorize routes, get the same shape.

php app/cli.php specs from main and from this branch differ in exactly the two OAuth2 responses (client and console specs):

"301": {
  "description": "Redirect",
  "headers": {
    "Location": {
      "description": "URL to redirect the client to.",
      "schema": { "type": "string", "format": "uri" }
    }
  }
}

Generator

sdk-generator 5.0.1 infers webAuth only from a 3xx binary body. On this spec that returns false for both OAuth2 methods, so client SDKs would call them as plain requests instead of opening the browser. No release through 5.5.2 reads the Location header. appwrite/sdk-generator#1983 does, and still accepts the old binary body.

This branch locks appwrite/sdk-generator to that pull request's commit e0bf097f751ab9b8070640a516dbdeae085fa464. With it, Web, Flutter, Android and React Native generated from this spec are byte-identical to main's, and Apple differs only in an unused accept header. Replace the dev constraint with the release tag once #1983 is published.

Test Plan

  • testRedirectResponsesDeclareLocationHeader covers 301, 302 and 308 with an HTML content type and asserts the whole response: Redirect plus the Location header, no content. It then parses that document with the locked generator and asserts the method type is webAuth.
  • FormatTest: 46 tests, 259 assertions, OK. Pint, PHPStan and Rector pass on the changed files.

Related PRs and Issues

Fixes #14155
Depends on appwrite/sdk-generator#1983

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?
Open in Web Open in Cursor 

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/oauth2-location-header-9662 (after).

Metric Before After Change
🚀 Requests/sec 221.31 222.44 ⚪ +0.5%
⏱️ Latency P50 77.94 ms 78.15 ms ⚪ +0.3%
⏱️ Latency P95 177.98 ms 182.52 ms ⚪ +2.6%
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 78.15 182.52 13,737 222.44 +4.54
Account 147.88 270.66 723 12.02 -48.4
TablesDB 74.55 127.69 7,471 122.12 -7.65
Storage 74.83 156.67 3,615 61.39 -2.45
Functions 118.61 232.32 1,928 33.54 +28.06

Top API waits (after)

API request Max wait (ms)
account.prefs.update 386.8
functions.create 382.57
functions.variables.update 367.89
account.name.update 359.99
tablesdb.rows.update 332.15

301, 302, and 308 responses were documented as "No content" with an HTML body. They now omit that body and declare a Location header so clients can see the redirect destination.

Fixes #14155
The 301, 302, and 308 branch also documents VCS installation redirects, including the GitHub App install URL. Call the response Redirect and describe Location as the redirect URL.
@cursor
cursor Bot force-pushed the cursor/oauth2-location-header-9662 branch from 73ec72b to adfd731 Compare October 7, 2026 09:26
@HarshMN2345
HarshMN2345 marked this pull request as ready for review October 7, 2026 09:46
@luxor-code-review

luxor-code-review Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR refines how the OpenAPI3 specification formatter represents redirect responses, plus corresponding unit tests.

Files Change
src/Appwrite/SDK/Specification/Format/OpenAPI3.php For 301/302/308 responses, drops the response body (content) and emits a Location header with a format: uri string schema instead of the previous no-content representation.
tests/unit/SDK/Specification/FormatTest.php Adds assertions covering the new redirect response shape, including round-trip parsing through the bundled OpenAPI parser.

The change is self-contained and consistent between spec generation and tests; no other subsystems are touched.

Reviewed commit: adfd731

@ghost

ghost commented Oct 7, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The dependency update addresses the previous compatibility finding, and no new defects were found in the incremental changes.

The OpenAPI formatter now declares 301, 302, and 308 responses as redirects with a URI-valued Location header and no content, while preserving 204 behavior. The generator dependency is pinned to the Location-aware revision, and parameterized tests cover both the response shape and webAuth classification.

Latest changes: The newest commits pin sdk-generator to the Location-aware revision in composer.json and composer.lock and add a webAuth classification assertion to the redirect tests.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 4
File Change
composer.json Pins sdk-generator to the Location-aware branch revision.
composer.lock Locks the matching generator commit and development stability flag.
src/Appwrite/SDK/Specification/Format/OpenAPI3.php Declares Location headers and omits content for redirects, preserving 204 responses.
tests/unit/SDK/Specification/FormatTest.php Tests redirect response shapes and generator webAuth classification for 301, 302, and 308.
✅ Fixed since the last review · 1
  • Update the locked generator before dropping redirect content · src/Appwrite/SDK/Specification/Format/OpenAPI3.php:553

Reviewed the commits since 9179e7e · 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 B · 1 blocking finding to address. Summary

Copy link
Copy Markdown
Member Author

@hansi-codes review

@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 B · See the inline comments. Summary

HarshMN2345 and others added 2 commits October 7, 2026 15:23
The 204 and 3xx branches each build their response in a single block, so
the redirect response is the description plus the Location header with
nothing left over from the generic content path. The redirect test asserts
that response directly, and the 204 test is back to its own claim.
sdk-generator 5.0 still classifies webAuth from a 3xx binary body. Declaring Location without that body makes OAuth2 methods ordinary requests. Keep the body until a generator release reads the header.

Copy link
Copy Markdown
Member Author

@hansi-codes review

@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 S · Looks good to merge. Summary

@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 S · Looks good to merge. Summary

This reverts commit b9d46a7.

Redirects drop the body as #14155 requires. The generator that reads the
Location header ships through appwrite/sdk-generator#1983 and is bumped
on this branch.

@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 B · 1 blocking finding to address. Summary

sdk-generator 5.0.1 only treats a 3xx binary body as webAuth. Lock the
generator to appwrite/sdk-generator#1983 (e0bf097), which also accepts a
Location header, and stop emitting that body on 301, 302 and 308.

@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 S · Looks good to merge. Summary

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost

ghost commented Oct 7, 2026

Copy link
Copy Markdown

Already reviewed ea20c88. No new commits since then, so I didn't post another review.

Regenerate composer.lock from main's lock with
composer update appwrite/sdk-generator, so the only lock change
against main is the pinned generator revision.

This branch has not been deployed

No deployments
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.

Declare the Location header on OAuth2 redirect responses in the OpenAPI spec

1 participant