fix: keep optional impersonation in URL builder query strings - #1912
Merged
Merged
Conversation
The optional-security migration made the securitySchemes filter drop any scheme that is accepted but not required, so example snippets stop configuring optional credentials. The same filter builds the query string of location and webAuth methods, and a URL builder has no request to carry headers, so dropping ImpersonateUserId there removed the credential rather than trimming an example. Console download, preview and avatar URLs were sent as the impersonator and returned 401. Give payload templates their own locationSchemes filter that keeps every scheme x-appwrite.auth lists; examples keep skipping the optional ones.
Contributor
|
The generation suite asserted on the emitted TypeScript, which mirrors the template rather than the behaviour. Open the built URL against the mock instead: the mock now accepts credentials from the query string, as the real API does for browser navigations, and echoes the impersonated user so the Web E2E fails when the parameter is missing.
Member
Author
|
@greptile review |
HarshMN2345
approved these changes
Sep 17, 2026
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.
Summary
After #1891, Console SDK URL builders (
getFileDownload,getFilePreview,getFileView, every avatar method, deployment downloads, invoice view/download) stopped appendingimpersonateuserid. The browser then fetched those URLs as the impersonator and the server correctly answered 401.The server-ce formatter now emits two security alternatives for a location method: the base auth, and the base auth plus the location keys. That makes
ImpersonateUserIdaccepted but not required. #1891 taughtgetOperationAuthSchemesto skip accepted-minus-required schemes so that examples do not configure optional credentials. The same method backs thesecuritySchemesTwig filter that location and webAuth templates use to build their query string, and a URL builder has no request to carry headers, so the skip removed the credential rather than trimming an example.Change
getOperationAuthSchemestakes anincludeOptionalflag. A newlocationSchemesfilter passestrue;securitySchemeskeeps the optional skip for examples.locationSchemes. The 17 docs example templates are untouched.downloadroute gains the second security alternative the real formatter emits, so the fixture reproduces the defect.Tests
Web E2E (Node and Chromium). The scripts build the
downloadURL twice, once without and once withsetImpersonateUserId('impersonated'), and open each URL withfetch. The mock endpoint now acceptsprojectandimpersonateuseridfrom the query string, as the real API does for a browser navigation, and echoes the impersonated user. Expected output gains two lines:Against the pre-fix generator the second line comes back without
:as:impersonatedand the test fails. With the fix both variants pass.Generation suite.
testExampleCredentialsFollowPlatformAuthalso checks the PHP client example for the same route still does not callsetImpersonateUserId, so the optional skip for examples is pinned alongside the query-string behaviour.Generated output, before vs after
Web SDK, client platform, from the test fixture. This is the only hunk in the whole tree:
Node SDK, server platform, same fixture: no difference in any file. Node performs a real request for location methods and sends the header, so it was never affected, and its docs examples still omit the optional credential.
Verification
WebNodeTestandWebChromiumTestpass locally against the mock server;WebNodeTestfails whensrc/SDK/SDK.phpand the templates are reset tomain.phpcsand Rector dry-run clean on the changed PHP files;djlintclean on the seven changed templates. The repo-widecomposer lintandcomposer refactor:checkfailures are pre-existing onmainand unchanged by this PR.Rollout
Release the generator, then regenerate and publish the Console SDK and bump it in Console. No producer or Cloud change is needed; the spec is correct as published.