From 27bfb8d4207d6abb32cfc9f95da6d9306729f5fa Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 29 May 2026 11:47:40 +0530 Subject: [PATCH 01/20] feat: embed impersonateUserId in location-type SDK method URLs - Swagger2 format class now adds ImpersonateUserId to x-appwrite.auth for location-type methods on platforms that support it (console), bypassing the authCount slice since this is a URL-embedding concern not an auth count. - Backend accepts both ?impersonateuserid (lowercase, emitted by the SDK template's caseLower filter) and ?impersonateUserId (camelCase, backwards compat) in request.php and realtime/connection.php. --- app/init/realtime/connection.php | 6 +++--- app/init/resources/request.php | 6 +++--- src/Appwrite/SDK/Specification/Format/Swagger2.php | 9 +++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/init/realtime/connection.php b/app/init/realtime/connection.php index a090635bb5..87f7c78ab0 100644 --- a/app/init/realtime/connection.php +++ b/app/init/realtime/connection.php @@ -329,9 +329,9 @@ return function (Container $container): void { // Query params mirror the header fallback pattern used by ?project= and ?devKey=, // allowing Console to embed impersonation in direct file/image URLs where headers cannot be set. - $impersonateUserId = $request->getHeader('x-appwrite-impersonate-user-id', (string)$request->getParam('impersonateUserId', '')); - $impersonateEmail = $request->getHeader('x-appwrite-impersonate-user-email', (string)$request->getParam('impersonateEmail', '')); - $impersonatePhone = $request->getHeader('x-appwrite-impersonate-user-phone', (string)$request->getParam('impersonatePhone', '')); + $impersonateUserId = $request->getHeader('x-appwrite-impersonate-user-id', (string)($request->getParam('impersonateuserid', '') ?: $request->getParam('impersonateUserId', ''))); + $impersonateEmail = $request->getHeader('x-appwrite-impersonate-user-email', (string)($request->getParam('impersonateuseremail', '') ?: $request->getParam('impersonateEmail', ''))); + $impersonatePhone = $request->getHeader('x-appwrite-impersonate-user-phone', (string)($request->getParam('impersonateuserphone', '') ?: $request->getParam('impersonatePhone', ''))); if (!$user->isEmpty() && $user->getAttribute('impersonator', false)) { $userDb = ($mode === APP_MODE_ADMIN || $project->getId() === 'console') ? $dbForPlatform : $dbForProject; diff --git a/app/init/resources/request.php b/app/init/resources/request.php index 416c294140..ccc5ebf648 100644 --- a/app/init/resources/request.php +++ b/app/init/resources/request.php @@ -491,9 +491,9 @@ return function (Container $context): void { // Impersonation: if current user has impersonator capability and headers/params are set, act as another user // Query params mirror the header fallback pattern used by ?project= and ?devKey=, // allowing Console to embed impersonation in direct file/image URLs where headers cannot be set. - $impersonateUserId = $request->getHeader('x-appwrite-impersonate-user-id', (string)$request->getParam('impersonateUserId', '')); - $impersonateEmail = $request->getHeader('x-appwrite-impersonate-user-email', (string)$request->getParam('impersonateEmail', '')); - $impersonatePhone = $request->getHeader('x-appwrite-impersonate-user-phone', (string)$request->getParam('impersonatePhone', '')); + $impersonateUserId = $request->getHeader('x-appwrite-impersonate-user-id', (string)($request->getParam('impersonateuserid', '') ?: $request->getParam('impersonateUserId', ''))); + $impersonateEmail = $request->getHeader('x-appwrite-impersonate-user-email', (string)($request->getParam('impersonateuseremail', '') ?: $request->getParam('impersonateEmail', ''))); + $impersonatePhone = $request->getHeader('x-appwrite-impersonate-user-phone', (string)($request->getParam('impersonateuserphone', '') ?: $request->getParam('impersonatePhone', ''))); if (!$user->isEmpty() && $user->getAttribute('impersonator', false)) { $userDb = (APP_MODE_ADMIN === $mode || $project->getId() === 'console') ? $dbForPlatform : $dbForProject; $targetUser = null; diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 20b1fb9b94..40aa1bf830 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -374,6 +374,15 @@ class Swagger2 extends Format } $temp['x-appwrite']['auth'] = \array_slice($securities, 0, $this->authCount); + + // For location-type methods, embed ImpersonateUserId in the URL auth so the SDK + // automatically appends ?impersonateuserid= to generated URLs. Browsers cannot + // carry custom headers on resource requests (img src, href), so impersonation + // must fall back to a query parameter for file view/preview/download. + if ($sdk->getType() === MethodType::LOCATION && \array_key_exists('ImpersonateUserId', $this->keys)) { + $temp['x-appwrite']['auth']['ImpersonateUserId'] = []; + } + $temp['security'][] = $securities; } From 337d03e86167629543a4f6dc59b02fa0c2debc9f Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 4 Jun 2026 13:29:33 +0530 Subject: [PATCH 02/20] test: add E2E coverage for impersonateUserId query param variants Tests header-based impersonation (unchanged), lowercase ?impersonateuserid= (SDK caseLower output), camelCase ?impersonateUserId= (backward compat), and that header takes priority when both are present. --- .../Services/Users/UsersConsoleClientTest.php | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/tests/e2e/Services/Users/UsersConsoleClientTest.php b/tests/e2e/Services/Users/UsersConsoleClientTest.php index 24e0f6868b..6f848390c5 100644 --- a/tests/e2e/Services/Users/UsersConsoleClientTest.php +++ b/tests/e2e/Services/Users/UsersConsoleClientTest.php @@ -81,4 +81,107 @@ class UsersConsoleClientTest extends Scope $this->assertEquals($userId, $set['body']['$id']); $this->assertNotEmpty($set['body']['password']); } + + /** + * Test that impersonation works via: + * - X-Appwrite-Impersonate-User-Id header (existing behavior, unchanged) + * - ?impersonateuserid= query param (lowercase, emitted by the SDK caseLower filter) + * - ?impersonateUserId= query param (camelCase, backward compat) + * + * The query param variants are the key addition of this PR — they allow Console + * to embed impersonation in file/image URLs where browsers cannot set custom headers. + */ + public function testImpersonateUserIdQueryParam(): void + { + $projectId = $this->getProject()['$id']; + $headers = array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()); + + // Create actor (impersonator) + $actorId = ID::unique(); + $actor = $this->client->call(Client::METHOD_POST, '/users', $headers, [ + 'userId' => $actorId, + 'email' => 'impersonator-queryparam-' . $actorId . '@example.com', + 'password' => 'password123', + 'name' => 'Impersonator', + ]); + $this->assertEquals(201, $actor['headers']['status-code']); + + // Create target + $targetId = ID::unique(); + $target = $this->client->call(Client::METHOD_POST, '/users', $headers, [ + 'userId' => $targetId, + 'email' => 'target-queryparam-' . $targetId . '@example.com', + 'password' => 'password123', + 'name' => 'Target', + ]); + $this->assertEquals(201, $target['headers']['status-code']); + + // Grant impersonator capability + $grant = $this->client->call(Client::METHOD_PATCH, '/users/' . $actorId . '/impersonator', $headers, [ + 'impersonator' => true, + ]); + $this->assertEquals(200, $grant['headers']['status-code']); + + // Create server-side session for actor + $session = $this->client->call(Client::METHOD_POST, '/users/' . $actorId . '/sessions', $headers); + $this->assertEquals(201, $session['headers']['status-code']); + $sessionSecret = $session['body']['secret']; + + $sessionHeaders = [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-session' => $sessionSecret, + ]; + + // Header-based impersonation — existing behavior, must still work + $byHeader = $this->client->call(Client::METHOD_GET, '/account', array_merge($sessionHeaders, [ + 'x-appwrite-impersonate-user-id' => $targetId, + ])); + $this->assertEquals(200, $byHeader['headers']['status-code']); + $this->assertEquals($targetId, $byHeader['body']['$id']); + $this->assertEquals($actorId, $byHeader['body']['impersonatorUserId']); + + // ?impersonateuserid= (lowercase) — emitted by SDK caseLower filter on LOCATION methods + $byLowerParam = $this->client->call(Client::METHOD_GET, '/account', $sessionHeaders, [ + 'impersonateuserid' => $targetId, + ]); + $this->assertEquals(200, $byLowerParam['headers']['status-code']); + $this->assertEquals($targetId, $byLowerParam['body']['$id']); + $this->assertEquals($actorId, $byLowerParam['body']['impersonatorUserId']); + + // ?impersonateUserId= (camelCase) — backward compat + $byCamelParam = $this->client->call(Client::METHOD_GET, '/account', $sessionHeaders, [ + 'impersonateUserId' => $targetId, + ]); + $this->assertEquals(200, $byCamelParam['headers']['status-code']); + $this->assertEquals($targetId, $byCamelParam['body']['$id']); + $this->assertEquals($actorId, $byCamelParam['body']['impersonatorUserId']); + + // Header takes priority over query param when both are present + $actorId2 = ID::unique(); + $actor2 = $this->client->call(Client::METHOD_POST, '/users', $headers, [ + 'userId' => $actorId2, + 'email' => 'impersonator2-' . $actorId2 . '@example.com', + 'password' => 'password123', + 'name' => 'Impersonator2', + ]); + $this->assertEquals(201, $actor2['headers']['status-code']); + + $this->client->call(Client::METHOD_PATCH, '/users/' . $actorId . '/impersonator', $headers, [ + 'impersonator' => true, + ]); + + $priority = $this->client->call( + Client::METHOD_GET, + '/account', + array_merge($sessionHeaders, ['x-appwrite-impersonate-user-id' => $targetId]), + ['impersonateuserid' => $actorId2] + ); + $this->assertEquals(200, $priority['headers']['status-code']); + $this->assertEquals($targetId, $priority['body']['$id'], 'header must take priority over query param'); + } } From 11ee2c3ea209c52a40d83bed40259c248e44cb7a Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 4 Jun 2026 13:31:01 +0530 Subject: [PATCH 03/20] refactor: simplify priority test, remove redundant user and PATCH call --- .../Services/Users/UsersConsoleClientTest.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/tests/e2e/Services/Users/UsersConsoleClientTest.php b/tests/e2e/Services/Users/UsersConsoleClientTest.php index 6f848390c5..67846c49dd 100644 --- a/tests/e2e/Services/Users/UsersConsoleClientTest.php +++ b/tests/e2e/Services/Users/UsersConsoleClientTest.php @@ -161,25 +161,14 @@ class UsersConsoleClientTest extends Scope $this->assertEquals($targetId, $byCamelParam['body']['$id']); $this->assertEquals($actorId, $byCamelParam['body']['impersonatorUserId']); - // Header takes priority over query param when both are present - $actorId2 = ID::unique(); - $actor2 = $this->client->call(Client::METHOD_POST, '/users', $headers, [ - 'userId' => $actorId2, - 'email' => 'impersonator2-' . $actorId2 . '@example.com', - 'password' => 'password123', - 'name' => 'Impersonator2', - ]); - $this->assertEquals(201, $actor2['headers']['status-code']); - - $this->client->call(Client::METHOD_PATCH, '/users/' . $actorId . '/impersonator', $headers, [ - 'impersonator' => true, - ]); - + // Header takes priority over query param when both are present. + // Pass actorId as the decoy in ?impersonateuserid= and targetId in the header — + // the response must be targetId, not actorId. $priority = $this->client->call( Client::METHOD_GET, '/account', array_merge($sessionHeaders, ['x-appwrite-impersonate-user-id' => $targetId]), - ['impersonateuserid' => $actorId2] + ['impersonateuserid' => $actorId] ); $this->assertEquals(200, $priority['headers']['status-code']); $this->assertEquals($targetId, $priority['body']['$id'], 'header must take priority over query param'); From c6e79ad0dc83f08986ca879e58519d202ef66223 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 4 Jun 2026 13:38:14 +0530 Subject: [PATCH 04/20] fix: remove dead lowercase email/phone params, align Swagger security array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Drop impersonateuseremail/impersonateuserphone lowercase fallbacks — only impersonateuserid has a spec entry for LOCATION methods so the others were dead code expanding the accepted query surface - Add ImpersonateUserId to $securities so the standard Swagger security array matches x-appwrite.auth for LOCATION methods --- app/init/realtime/connection.php | 4 ++-- app/init/resources/request.php | 4 ++-- src/Appwrite/SDK/Specification/Format/Swagger2.php | 9 +++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/init/realtime/connection.php b/app/init/realtime/connection.php index 87f7c78ab0..db0b209a4e 100644 --- a/app/init/realtime/connection.php +++ b/app/init/realtime/connection.php @@ -330,8 +330,8 @@ return function (Container $container): void { // Query params mirror the header fallback pattern used by ?project= and ?devKey=, // allowing Console to embed impersonation in direct file/image URLs where headers cannot be set. $impersonateUserId = $request->getHeader('x-appwrite-impersonate-user-id', (string)($request->getParam('impersonateuserid', '') ?: $request->getParam('impersonateUserId', ''))); - $impersonateEmail = $request->getHeader('x-appwrite-impersonate-user-email', (string)($request->getParam('impersonateuseremail', '') ?: $request->getParam('impersonateEmail', ''))); - $impersonatePhone = $request->getHeader('x-appwrite-impersonate-user-phone', (string)($request->getParam('impersonateuserphone', '') ?: $request->getParam('impersonatePhone', ''))); + $impersonateEmail = $request->getHeader('x-appwrite-impersonate-user-email', (string)$request->getParam('impersonateEmail', '')); + $impersonatePhone = $request->getHeader('x-appwrite-impersonate-user-phone', (string)$request->getParam('impersonatePhone', '')); if (!$user->isEmpty() && $user->getAttribute('impersonator', false)) { $userDb = ($mode === APP_MODE_ADMIN || $project->getId() === 'console') ? $dbForPlatform : $dbForProject; diff --git a/app/init/resources/request.php b/app/init/resources/request.php index ccc5ebf648..59f6a90c13 100644 --- a/app/init/resources/request.php +++ b/app/init/resources/request.php @@ -492,8 +492,8 @@ return function (Container $context): void { // Query params mirror the header fallback pattern used by ?project= and ?devKey=, // allowing Console to embed impersonation in direct file/image URLs where headers cannot be set. $impersonateUserId = $request->getHeader('x-appwrite-impersonate-user-id', (string)($request->getParam('impersonateuserid', '') ?: $request->getParam('impersonateUserId', ''))); - $impersonateEmail = $request->getHeader('x-appwrite-impersonate-user-email', (string)($request->getParam('impersonateuseremail', '') ?: $request->getParam('impersonateEmail', ''))); - $impersonatePhone = $request->getHeader('x-appwrite-impersonate-user-phone', (string)($request->getParam('impersonateuserphone', '') ?: $request->getParam('impersonatePhone', ''))); + $impersonateEmail = $request->getHeader('x-appwrite-impersonate-user-email', (string)$request->getParam('impersonateEmail', '')); + $impersonatePhone = $request->getHeader('x-appwrite-impersonate-user-phone', (string)$request->getParam('impersonatePhone', '')); if (!$user->isEmpty() && $user->getAttribute('impersonator', false)) { $userDb = (APP_MODE_ADMIN === $mode || $project->getId() === 'console') ? $dbForPlatform : $dbForProject; $targetUser = null; diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 40aa1bf830..5774185332 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -375,11 +375,12 @@ class Swagger2 extends Format $temp['x-appwrite']['auth'] = \array_slice($securities, 0, $this->authCount); - // For location-type methods, embed ImpersonateUserId in the URL auth so the SDK - // automatically appends ?impersonateuserid= to generated URLs. Browsers cannot - // carry custom headers on resource requests (img src, href), so impersonation - // must fall back to a query parameter for file view/preview/download. + // For location-type methods, embed ImpersonateUserId in both x-appwrite.auth + // and the standard Swagger security array so the SDK appends ?impersonateuserid= + // to generated URLs. Browsers cannot carry custom headers on resource requests + // (img src, href), so impersonation must fall back to a query param. if ($sdk->getType() === MethodType::LOCATION && \array_key_exists('ImpersonateUserId', $this->keys)) { + $securities['ImpersonateUserId'] = []; $temp['x-appwrite']['auth']['ImpersonateUserId'] = []; } From 67d3cf442ed0ec222ae954c60abda3e6f4a7c358 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 4 Jun 2026 14:53:53 +0530 Subject: [PATCH 05/20] feat: support impersonation via URL query params for all three variants - Accept ?impersonateuserid=, ?impersonateemail=, ?impersonatephone= (lowercase) and their camelCase equivalents as query param fallbacks for the impersonation headers, mirroring the ?project= / ?devKey= pattern - Swagger2 spec injects all three impersonation keys into x-appwrite.auth and the standard security array for LOCATION-type methods - Remove unused ApiVectorsDB trait left behind after VectorsDB test deletion - Add E2E tests: query param variants (userId/email/phone), header priority, and storage file preview/view via ?impersonateuserid= --- app/init/realtime/connection.php | 4 +- app/init/resources/request.php | 4 +- .../SDK/Specification/Format/Swagger2.php | 18 +-- tests/e2e/Scopes/ApiVectorsDB.php | 110 ------------------ .../Storage/StorageConsoleClientTest.php | 80 +++++++++++++ .../Services/Users/UsersConsoleClientTest.php | 61 +++++----- 6 files changed, 121 insertions(+), 156 deletions(-) delete mode 100644 tests/e2e/Scopes/ApiVectorsDB.php diff --git a/app/init/realtime/connection.php b/app/init/realtime/connection.php index db0b209a4e..ea00b7f356 100644 --- a/app/init/realtime/connection.php +++ b/app/init/realtime/connection.php @@ -330,8 +330,8 @@ return function (Container $container): void { // Query params mirror the header fallback pattern used by ?project= and ?devKey=, // allowing Console to embed impersonation in direct file/image URLs where headers cannot be set. $impersonateUserId = $request->getHeader('x-appwrite-impersonate-user-id', (string)($request->getParam('impersonateuserid', '') ?: $request->getParam('impersonateUserId', ''))); - $impersonateEmail = $request->getHeader('x-appwrite-impersonate-user-email', (string)$request->getParam('impersonateEmail', '')); - $impersonatePhone = $request->getHeader('x-appwrite-impersonate-user-phone', (string)$request->getParam('impersonatePhone', '')); + $impersonateEmail = $request->getHeader('x-appwrite-impersonate-user-email', (string)($request->getParam('impersonateemail', '') ?: $request->getParam('impersonateEmail', ''))); + $impersonatePhone = $request->getHeader('x-appwrite-impersonate-user-phone', (string)($request->getParam('impersonatephone', '') ?: $request->getParam('impersonatePhone', ''))); if (!$user->isEmpty() && $user->getAttribute('impersonator', false)) { $userDb = ($mode === APP_MODE_ADMIN || $project->getId() === 'console') ? $dbForPlatform : $dbForProject; diff --git a/app/init/resources/request.php b/app/init/resources/request.php index 59f6a90c13..f7a98e0f8f 100644 --- a/app/init/resources/request.php +++ b/app/init/resources/request.php @@ -492,8 +492,8 @@ return function (Container $context): void { // Query params mirror the header fallback pattern used by ?project= and ?devKey=, // allowing Console to embed impersonation in direct file/image URLs where headers cannot be set. $impersonateUserId = $request->getHeader('x-appwrite-impersonate-user-id', (string)($request->getParam('impersonateuserid', '') ?: $request->getParam('impersonateUserId', ''))); - $impersonateEmail = $request->getHeader('x-appwrite-impersonate-user-email', (string)$request->getParam('impersonateEmail', '')); - $impersonatePhone = $request->getHeader('x-appwrite-impersonate-user-phone', (string)$request->getParam('impersonatePhone', '')); + $impersonateEmail = $request->getHeader('x-appwrite-impersonate-user-email', (string)($request->getParam('impersonateemail', '') ?: $request->getParam('impersonateEmail', ''))); + $impersonatePhone = $request->getHeader('x-appwrite-impersonate-user-phone', (string)($request->getParam('impersonatephone', '') ?: $request->getParam('impersonatePhone', ''))); if (!$user->isEmpty() && $user->getAttribute('impersonator', false)) { $userDb = (APP_MODE_ADMIN === $mode || $project->getId() === 'console') ? $dbForPlatform : $dbForProject; $targetUser = null; diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 5774185332..53156eb976 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -375,13 +375,17 @@ class Swagger2 extends Format $temp['x-appwrite']['auth'] = \array_slice($securities, 0, $this->authCount); - // For location-type methods, embed ImpersonateUserId in both x-appwrite.auth - // and the standard Swagger security array so the SDK appends ?impersonateuserid= - // to generated URLs. Browsers cannot carry custom headers on resource requests - // (img src, href), so impersonation must fall back to a query param. - if ($sdk->getType() === MethodType::LOCATION && \array_key_exists('ImpersonateUserId', $this->keys)) { - $securities['ImpersonateUserId'] = []; - $temp['x-appwrite']['auth']['ImpersonateUserId'] = []; + // For location-type methods, embed all impersonation keys in both x-appwrite.auth + // and the standard Swagger security array so the SDK appends the corresponding + // query params to generated URLs. Browsers cannot carry custom headers on resource + // requests (img src, href), so impersonation must fall back to query params. + if ($sdk->getType() === MethodType::LOCATION) { + foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { + if (\array_key_exists($key, $this->keys)) { + $securities[$key] = []; + $temp['x-appwrite']['auth'][$key] = []; + } + } } $temp['security'][] = $securities; diff --git a/tests/e2e/Scopes/ApiVectorsDB.php b/tests/e2e/Scopes/ApiVectorsDB.php deleted file mode 100644 index 09494d3c10..0000000000 --- a/tests/e2e/Scopes/ApiVectorsDB.php +++ /dev/null @@ -1,110 +0,0 @@ -getHeaders())); $this->assertEquals(204, $response['headers']['status-code']); } + + public function testFilePreviewWithImpersonation(): void + { + $projectId = $this->getProject()['$id']; + $adminHeaders = array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()); + + $targetId = ID::unique(); + $target = $this->client->call(Client::METHOD_POST, '/users', $adminHeaders, [ + 'userId' => $targetId, + 'email' => 'impersonation-storage-target-' . $targetId . '@example.com', + 'password' => 'password123', + 'name' => 'Storage Target', + ]); + $this->assertEquals(201, $target['headers']['status-code']); + + $actorId = ID::unique(); + $this->client->call(Client::METHOD_POST, '/users', $adminHeaders, [ + 'userId' => $actorId, + 'email' => 'impersonation-storage-actor-' . $actorId . '@example.com', + 'password' => 'password123', + 'name' => 'Storage Actor', + ]); + $this->client->call(Client::METHOD_PATCH, '/users/' . $actorId . '/impersonator', $adminHeaders, [ + 'impersonator' => true, + ]); + + $bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', $adminHeaders, [ + 'bucketId' => ID::unique(), + 'name' => 'Impersonation Test Bucket', + 'fileSecurity' => true, + 'permissions' => [ + Permission::read(Role::any()), + Permission::create(Role::any()), + ], + ]); + $this->assertEquals(201, $bucket['headers']['status-code']); + $bucketId = $bucket['body']['$id']; + + $file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge( + $adminHeaders, + ['content-type' => 'multipart/form-data'] + ), [ + 'fileId' => ID::unique(), + 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'), + 'permissions' => [ + Permission::read(Role::user($targetId)), + ], + ]); + $this->assertEquals(201, $file['headers']['status-code']); + $fileId = $file['body']['$id']; + + $session = $this->client->call(Client::METHOD_POST, '/users/' . $actorId . '/sessions', $adminHeaders); + $this->assertEquals(201, $session['headers']['status-code']); + + $sessionHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-session' => $session['body']['secret'], + ]; + + $denied = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', $sessionHeaders); + $this->assertEquals(401, $denied['headers']['status-code']); + + $preview = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', $sessionHeaders, [ + 'impersonateuserid' => $targetId, + ]); + $this->assertEquals(200, $preview['headers']['status-code']); + $this->assertEquals('image/png', $preview['headers']['content-type']); + $this->assertNotEmpty($preview['body']); + + $view = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/view', $sessionHeaders, [ + 'impersonateuserid' => $targetId, + ]); + $this->assertEquals(200, $view['headers']['status-code']); + } } diff --git a/tests/e2e/Services/Users/UsersConsoleClientTest.php b/tests/e2e/Services/Users/UsersConsoleClientTest.php index 67846c49dd..042ca6f124 100644 --- a/tests/e2e/Services/Users/UsersConsoleClientTest.php +++ b/tests/e2e/Services/Users/UsersConsoleClientTest.php @@ -82,16 +82,7 @@ class UsersConsoleClientTest extends Scope $this->assertNotEmpty($set['body']['password']); } - /** - * Test that impersonation works via: - * - X-Appwrite-Impersonate-User-Id header (existing behavior, unchanged) - * - ?impersonateuserid= query param (lowercase, emitted by the SDK caseLower filter) - * - ?impersonateUserId= query param (camelCase, backward compat) - * - * The query param variants are the key addition of this PR — they allow Console - * to embed impersonation in file/image URLs where browsers cannot set custom headers. - */ - public function testImpersonateUserIdQueryParam(): void + public function testImpersonateQueryParams(): void { $projectId = $this->getProject()['$id']; $headers = array_merge([ @@ -99,7 +90,6 @@ class UsersConsoleClientTest extends Scope 'x-appwrite-project' => $projectId, ], $this->getHeaders()); - // Create actor (impersonator) $actorId = ID::unique(); $actor = $this->client->call(Client::METHOD_POST, '/users', $headers, [ 'userId' => $actorId, @@ -109,35 +99,36 @@ class UsersConsoleClientTest extends Scope ]); $this->assertEquals(201, $actor['headers']['status-code']); - // Create target $targetId = ID::unique(); + $targetEmail = 'target-queryparam-' . $targetId . '@example.com'; + $targetPhone = '+1' . rand(2000000000, 2999999999); + $target = $this->client->call(Client::METHOD_POST, '/users', $headers, [ 'userId' => $targetId, - 'email' => 'target-queryparam-' . $targetId . '@example.com', + 'email' => $targetEmail, 'password' => 'password123', 'name' => 'Target', ]); $this->assertEquals(201, $target['headers']['status-code']); - // Grant impersonator capability - $grant = $this->client->call(Client::METHOD_PATCH, '/users/' . $actorId . '/impersonator', $headers, [ + $this->client->call(Client::METHOD_PATCH, '/users/' . $targetId . '/phone', $headers, [ + 'number' => $targetPhone, + ]); + + $this->client->call(Client::METHOD_PATCH, '/users/' . $actorId . '/impersonator', $headers, [ 'impersonator' => true, ]); - $this->assertEquals(200, $grant['headers']['status-code']); - // Create server-side session for actor $session = $this->client->call(Client::METHOD_POST, '/users/' . $actorId . '/sessions', $headers); $this->assertEquals(201, $session['headers']['status-code']); - $sessionSecret = $session['body']['secret']; $sessionHeaders = [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-session' => $sessionSecret, + 'x-appwrite-session' => $session['body']['secret'], ]; - // Header-based impersonation — existing behavior, must still work $byHeader = $this->client->call(Client::METHOD_GET, '/account', array_merge($sessionHeaders, [ 'x-appwrite-impersonate-user-id' => $targetId, ])); @@ -145,25 +136,25 @@ class UsersConsoleClientTest extends Scope $this->assertEquals($targetId, $byHeader['body']['$id']); $this->assertEquals($actorId, $byHeader['body']['impersonatorUserId']); - // ?impersonateuserid= (lowercase) — emitted by SDK caseLower filter on LOCATION methods - $byLowerParam = $this->client->call(Client::METHOD_GET, '/account', $sessionHeaders, [ + $byUserId = $this->client->call(Client::METHOD_GET, '/account', $sessionHeaders, [ 'impersonateuserid' => $targetId, ]); - $this->assertEquals(200, $byLowerParam['headers']['status-code']); - $this->assertEquals($targetId, $byLowerParam['body']['$id']); - $this->assertEquals($actorId, $byLowerParam['body']['impersonatorUserId']); + $this->assertEquals(200, $byUserId['headers']['status-code']); + $this->assertEquals($targetId, $byUserId['body']['$id']); - // ?impersonateUserId= (camelCase) — backward compat - $byCamelParam = $this->client->call(Client::METHOD_GET, '/account', $sessionHeaders, [ - 'impersonateUserId' => $targetId, + $byEmail = $this->client->call(Client::METHOD_GET, '/account', $sessionHeaders, [ + 'impersonateemail' => $targetEmail, ]); - $this->assertEquals(200, $byCamelParam['headers']['status-code']); - $this->assertEquals($targetId, $byCamelParam['body']['$id']); - $this->assertEquals($actorId, $byCamelParam['body']['impersonatorUserId']); + $this->assertEquals(200, $byEmail['headers']['status-code']); + $this->assertEquals($targetId, $byEmail['body']['$id']); - // Header takes priority over query param when both are present. - // Pass actorId as the decoy in ?impersonateuserid= and targetId in the header — - // the response must be targetId, not actorId. + $byPhone = $this->client->call(Client::METHOD_GET, '/account', $sessionHeaders, [ + 'impersonatephone' => $targetPhone, + ]); + $this->assertEquals(200, $byPhone['headers']['status-code']); + $this->assertEquals($targetId, $byPhone['body']['$id']); + + // header takes priority over query param $priority = $this->client->call( Client::METHOD_GET, '/account', @@ -171,6 +162,6 @@ class UsersConsoleClientTest extends Scope ['impersonateuserid' => $actorId] ); $this->assertEquals(200, $priority['headers']['status-code']); - $this->assertEquals($targetId, $priority['body']['$id'], 'header must take priority over query param'); + $this->assertEquals($targetId, $priority['body']['$id']); } } From bc20e41e8339fc605d8ceb4890c5a913bead1dc4 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 4 Jun 2026 17:16:09 +0530 Subject: [PATCH 06/20] fix: remove bucket read permission so file-level 401 fires correctly --- tests/e2e/Services/Storage/StorageConsoleClientTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/Services/Storage/StorageConsoleClientTest.php b/tests/e2e/Services/Storage/StorageConsoleClientTest.php index 8b20ce5c24..a0e6c84a97 100644 --- a/tests/e2e/Services/Storage/StorageConsoleClientTest.php +++ b/tests/e2e/Services/Storage/StorageConsoleClientTest.php @@ -232,7 +232,6 @@ class StorageConsoleClientTest extends Scope 'name' => 'Impersonation Test Bucket', 'fileSecurity' => true, 'permissions' => [ - Permission::read(Role::any()), Permission::create(Role::any()), ], ]); From 390c1e6a4e8d60f5a3b22aeea92dacfd5b117d8c Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 4 Jun 2026 17:19:02 +0530 Subject: [PATCH 07/20] revert: restore ApiVectorsDB trait present on 1.9.x --- tests/e2e/Scopes/ApiVectorsDB.php | 110 ++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 tests/e2e/Scopes/ApiVectorsDB.php diff --git a/tests/e2e/Scopes/ApiVectorsDB.php b/tests/e2e/Scopes/ApiVectorsDB.php new file mode 100644 index 0000000000..09494d3c10 --- /dev/null +++ b/tests/e2e/Scopes/ApiVectorsDB.php @@ -0,0 +1,110 @@ + Date: Thu, 4 Jun 2026 17:26:22 +0530 Subject: [PATCH 08/20] fix: accept 401 or 404 for denied file access without impersonation --- tests/e2e/Services/Storage/StorageConsoleClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Storage/StorageConsoleClientTest.php b/tests/e2e/Services/Storage/StorageConsoleClientTest.php index a0e6c84a97..0f5d763425 100644 --- a/tests/e2e/Services/Storage/StorageConsoleClientTest.php +++ b/tests/e2e/Services/Storage/StorageConsoleClientTest.php @@ -261,7 +261,7 @@ class StorageConsoleClientTest extends Scope ]; $denied = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', $sessionHeaders); - $this->assertEquals(401, $denied['headers']['status-code']); + $this->assertContains($denied['headers']['status-code'], [401, 404]); $preview = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', $sessionHeaders, [ 'impersonateuserid' => $targetId, From bfc8f82e37e73d089c06134e6cef0c03850cf5d9 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 4 Jun 2026 17:27:28 +0530 Subject: [PATCH 09/20] fix: restore bucket read permission for consistent 401 on file access --- tests/e2e/Services/Storage/StorageConsoleClientTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Services/Storage/StorageConsoleClientTest.php b/tests/e2e/Services/Storage/StorageConsoleClientTest.php index 0f5d763425..8b20ce5c24 100644 --- a/tests/e2e/Services/Storage/StorageConsoleClientTest.php +++ b/tests/e2e/Services/Storage/StorageConsoleClientTest.php @@ -232,6 +232,7 @@ class StorageConsoleClientTest extends Scope 'name' => 'Impersonation Test Bucket', 'fileSecurity' => true, 'permissions' => [ + Permission::read(Role::any()), Permission::create(Role::any()), ], ]); @@ -261,7 +262,7 @@ class StorageConsoleClientTest extends Scope ]; $denied = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', $sessionHeaders); - $this->assertContains($denied['headers']['status-code'], [401, 404]); + $this->assertEquals(401, $denied['headers']['status-code']); $preview = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', $sessionHeaders, [ 'impersonateuserid' => $targetId, From d32139bfd9f32b961d0948c4fb32d2be4b2611b0 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 4 Jun 2026 17:42:41 +0530 Subject: [PATCH 10/20] fix: restrict bucket read to target user so actor gets 401 without impersonation --- tests/e2e/Services/Storage/StorageConsoleClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Storage/StorageConsoleClientTest.php b/tests/e2e/Services/Storage/StorageConsoleClientTest.php index 8b20ce5c24..ee9d43923e 100644 --- a/tests/e2e/Services/Storage/StorageConsoleClientTest.php +++ b/tests/e2e/Services/Storage/StorageConsoleClientTest.php @@ -232,7 +232,7 @@ class StorageConsoleClientTest extends Scope 'name' => 'Impersonation Test Bucket', 'fileSecurity' => true, 'permissions' => [ - Permission::read(Role::any()), + Permission::read(Role::user($targetId)), Permission::create(Role::any()), ], ]); From 0f0e27f39b7eb89040fa47920573a53e9a327685 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 4 Jun 2026 17:50:04 +0530 Subject: [PATCH 11/20] fix: expect 404 for actor without bucket access --- tests/e2e/Services/Storage/StorageConsoleClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Storage/StorageConsoleClientTest.php b/tests/e2e/Services/Storage/StorageConsoleClientTest.php index ee9d43923e..6f9b9e9085 100644 --- a/tests/e2e/Services/Storage/StorageConsoleClientTest.php +++ b/tests/e2e/Services/Storage/StorageConsoleClientTest.php @@ -262,7 +262,7 @@ class StorageConsoleClientTest extends Scope ]; $denied = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', $sessionHeaders); - $this->assertEquals(401, $denied['headers']['status-code']); + $this->assertEquals(404, $denied['headers']['status-code']); $preview = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', $sessionHeaders, [ 'impersonateuserid' => $targetId, From 9aef57f3594bb54ac55e37ffa0fa240497449e19 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 13:43:05 +0530 Subject: [PATCH 12/20] feat: add impersonation keys to LOCATION methods in OpenAPI3 spec --- src/Appwrite/SDK/Specification/Format/OpenAPI3.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index dfa38b0bf5..8e8d5e6301 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -384,6 +384,16 @@ class OpenAPI3 extends Format } $temp['x-appwrite']['auth'] = array_slice($securities, 0, $this->authCount); + + if ($sdk->getType() === MethodType::LOCATION) { + foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { + if (\array_key_exists($key, $this->keys)) { + $securities[$key] = []; + $temp['x-appwrite']['auth'][$key] = []; + } + } + } + $temp['security'][] = $securities; } From d2fe065de8f10ac67d2a0f2e9f46f00f299a6cdd Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 14:50:05 +0530 Subject: [PATCH 13/20] style: remove comment from LOCATION impersonation block --- src/Appwrite/SDK/Specification/Format/Swagger2.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 53156eb976..7fc23b0d99 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -375,10 +375,6 @@ class Swagger2 extends Format $temp['x-appwrite']['auth'] = \array_slice($securities, 0, $this->authCount); - // For location-type methods, embed all impersonation keys in both x-appwrite.auth - // and the standard Swagger security array so the SDK appends the corresponding - // query params to generated URLs. Browsers cannot carry custom headers on resource - // requests (img src, href), so impersonation must fall back to query params. if ($sdk->getType() === MethodType::LOCATION) { foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { if (\array_key_exists($key, $this->keys)) { From 55d3af2f598e62097a568e11fe1fb4b01780a76b Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 14:50:54 +0530 Subject: [PATCH 14/20] style: add brief comment to LOCATION impersonation block --- src/Appwrite/SDK/Specification/Format/OpenAPI3.php | 1 + src/Appwrite/SDK/Specification/Format/Swagger2.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index 8e8d5e6301..b852a72658 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -385,6 +385,7 @@ class OpenAPI3 extends Format $temp['x-appwrite']['auth'] = array_slice($securities, 0, $this->authCount); + // Impersonation falls back to query params for location-type methods (browsers can't set headers on resource URLs) if ($sdk->getType() === MethodType::LOCATION) { foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { if (\array_key_exists($key, $this->keys)) { diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 7fc23b0d99..31e5e5de07 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -375,6 +375,7 @@ class Swagger2 extends Format $temp['x-appwrite']['auth'] = \array_slice($securities, 0, $this->authCount); + // Impersonation falls back to query params for location-type methods (browsers can't set headers on resource URLs) if ($sdk->getType() === MethodType::LOCATION) { foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { if (\array_key_exists($key, $this->keys)) { From 18dfaedc376553c7ee702ad41917e4782f597314 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 15:01:45 +0530 Subject: [PATCH 15/20] refactor: use Query security scheme variants for impersonation on LOCATION methods --- src/Appwrite/Platform/Tasks/Specs.php | 54 +++++++++++++++++++ .../SDK/Specification/Format/OpenAPI3.php | 3 +- .../SDK/Specification/Format/Swagger2.php | 3 +- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index 8717ae742e..ffe8757a78 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -181,18 +181,36 @@ class Specs extends Action 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserIdQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonateUserId', + 'description' => 'Impersonate a user by ID via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserEmailQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonateEmail', + 'description' => 'Impersonate a user by email via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserPhoneQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonatePhone', + 'description' => 'Impersonate a user by phone via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], ], APP_SDK_PLATFORM_SERVER => [ 'Project' => [ @@ -255,18 +273,36 @@ class Specs extends Action 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserIdQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonateUserId', + 'description' => 'Impersonate a user by ID via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserEmailQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonateEmail', + 'description' => 'Impersonate a user by email via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserPhoneQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonatePhone', + 'description' => 'Impersonate a user by phone via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], ], APP_SDK_PLATFORM_CONSOLE => [ 'Project' => [ @@ -329,18 +365,36 @@ class Specs extends Action 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserIdQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonateUserId', + 'description' => 'Impersonate a user by ID via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserEmailQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonateEmail', + 'description' => 'Impersonate a user by email via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserPhoneQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonatePhone', + 'description' => 'Impersonate a user by phone via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], ], ]; } diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index b852a72658..c40c44b85e 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -385,9 +385,8 @@ class OpenAPI3 extends Format $temp['x-appwrite']['auth'] = array_slice($securities, 0, $this->authCount); - // Impersonation falls back to query params for location-type methods (browsers can't set headers on resource URLs) if ($sdk->getType() === MethodType::LOCATION) { - foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { + foreach (['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'] as $key) { if (\array_key_exists($key, $this->keys)) { $securities[$key] = []; $temp['x-appwrite']['auth'][$key] = []; diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 31e5e5de07..ca2643222a 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -375,9 +375,8 @@ class Swagger2 extends Format $temp['x-appwrite']['auth'] = \array_slice($securities, 0, $this->authCount); - // Impersonation falls back to query params for location-type methods (browsers can't set headers on resource URLs) if ($sdk->getType() === MethodType::LOCATION) { - foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { + foreach (['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'] as $key) { if (\array_key_exists($key, $this->keys)) { $securities[$key] = []; $temp['x-appwrite']['auth'][$key] = []; From 529847df95d950afc58da5f7bd75186bb804f703 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 18:02:18 +0530 Subject: [PATCH 16/20] refactor: add locationAuth to Method.php, use getLocationAuth() in spec formatters --- src/Appwrite/SDK/Method.php | 9 ++++++++- src/Appwrite/SDK/Specification/Format/OpenAPI3.php | 2 +- src/Appwrite/SDK/Specification/Format/Swagger2.php | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/SDK/Method.php b/src/Appwrite/SDK/Method.php index 5f6ccf9a0f..97283dfb4a 100644 --- a/src/Appwrite/SDK/Method.php +++ b/src/Appwrite/SDK/Method.php @@ -33,6 +33,7 @@ class Method * @param string $desc * @param bool $public Whether this method should be rendered on the website/documentation * @param string $projectAuth Project authentication security scheme to use in specs + * @param array $locationAuth Additional security scheme keys injected for location-type methods */ public function __construct( protected string $namespace, @@ -51,7 +52,8 @@ class Method protected array $additionalParameters = [], protected string $desc = '', protected bool $public = true, - protected string $projectAuth = 'Project' + protected string $projectAuth = 'Project', + protected array $locationAuth = ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'] ) { $this->validateMethod($name, $namespace); $this->validateAuthTypes($auth); @@ -234,6 +236,11 @@ class Method return $this->projectAuth; } + public function getLocationAuth(): array + { + return $this->locationAuth; + } + public function setNamespace(string $namespace): self { $this->namespace = $namespace; diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index c40c44b85e..cf83c3ea96 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -386,7 +386,7 @@ class OpenAPI3 extends Format $temp['x-appwrite']['auth'] = array_slice($securities, 0, $this->authCount); if ($sdk->getType() === MethodType::LOCATION) { - foreach (['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'] as $key) { + foreach ($sdk->getLocationAuth() as $key) { if (\array_key_exists($key, $this->keys)) { $securities[$key] = []; $temp['x-appwrite']['auth'][$key] = []; diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index ca2643222a..0c4c423de1 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -376,7 +376,7 @@ class Swagger2 extends Format $temp['x-appwrite']['auth'] = \array_slice($securities, 0, $this->authCount); if ($sdk->getType() === MethodType::LOCATION) { - foreach (['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'] as $key) { + foreach ($sdk->getLocationAuth() as $key) { if (\array_key_exists($key, $this->keys)) { $securities[$key] = []; $temp['x-appwrite']['auth'][$key] = []; From ead39142cd79a150eafd10c96178faaab7c2ee04 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 18:14:28 +0530 Subject: [PATCH 17/20] refactor: explicitly set locationAuth on all LOCATION methods, remove default --- src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php | 1 + src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php | 1 + src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php | 1 + src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php | 1 + src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php | 1 + src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php | 1 + src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php | 1 + src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php | 1 + .../Modules/Functions/Http/Deployments/Download/Get.php | 3 ++- .../Platform/Modules/Sites/Http/Deployments/Download/Get.php | 1 + .../Modules/Storage/Http/Buckets/Files/Download/Get.php | 3 ++- .../Modules/Storage/Http/Buckets/Files/Preview/Get.php | 1 + .../Platform/Modules/Storage/Http/Buckets/Files/View/Get.php | 3 ++- src/Appwrite/SDK/Method.php | 2 +- 14 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php index cc30f014bc..70f8a40e2c 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php @@ -42,6 +42,7 @@ class Get extends Action description: '/docs/references/avatars/get-browser.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php index 3bae32c862..4cedbb42b1 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php @@ -42,6 +42,7 @@ class Get extends Action description: '/docs/references/avatars/get-credit-card.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php index 6faa0fe223..2dcb797f7a 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php @@ -54,6 +54,7 @@ class Get extends Action description: '/docs/references/avatars/get-favicon.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php index ef9f8c0e47..6b2b76bc2f 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php @@ -42,6 +42,7 @@ class Get extends Action description: '/docs/references/avatars/get-flag.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php index 315202d4d5..9b7bee8be0 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php @@ -45,6 +45,7 @@ class Get extends Action description: '/docs/references/avatars/get-image.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php index c73d20fb0c..0b6df2353f 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php @@ -44,6 +44,7 @@ class Get extends Action description: '/docs/references/avatars/get-initials.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php index f3448f5264..86315c7101 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php @@ -42,6 +42,7 @@ class Get extends Action description: '/docs/references/avatars/get-qr.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php index 51d4df2a49..33ebcd73ab 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php @@ -57,6 +57,7 @@ class Get extends Action description: '/docs/references/avatars/get-screenshot.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php index c92e3c1406..b246ccb0dc 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php @@ -52,7 +52,8 @@ class Get extends Action ) ], contentType: ContentType::ANY, - type: MethodType::LOCATION + type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], )) ->param('functionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Function ID.', false, ['dbForProject']) ->param('deploymentId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Deployment ID.', false, ['dbForProject']) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php index 0ab998292d..13aa754d12 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php @@ -51,6 +51,7 @@ class Get extends Action ) ], type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], contentType: ContentType::ANY, )) ->param('siteId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Site ID.', false, ['dbForProject']) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php index 7e5d7d6879..22dcb3e3aa 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php @@ -57,7 +57,8 @@ class Get extends Action ) ], contentType: ContentType::ANY, - type: MethodType::LOCATION + type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], )) ->param('bucketId', '', new UID(), 'Storage bucket ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') ->param('fileId', '', new UID(), 'File ID.') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php index 9c316a3b57..bee4798b9e 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php @@ -71,6 +71,7 @@ class Get extends Action ) ], type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], contentType: ContentType::IMAGE )) ->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php index b78d582c47..ea228e2ebd 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php @@ -58,7 +58,8 @@ class Get extends Action ) ], contentType: ContentType::ANY, - type: MethodType::LOCATION + type: MethodType::LOCATION, + locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], )) ->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') ->param('fileId', '', new UID(), 'File ID.') diff --git a/src/Appwrite/SDK/Method.php b/src/Appwrite/SDK/Method.php index 97283dfb4a..ce793ee113 100644 --- a/src/Appwrite/SDK/Method.php +++ b/src/Appwrite/SDK/Method.php @@ -53,7 +53,7 @@ class Method protected string $desc = '', protected bool $public = true, protected string $projectAuth = 'Project', - protected array $locationAuth = ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'] + protected array $locationAuth = [] ) { $this->validateMethod($name, $namespace); $this->validateAuthTypes($auth); From dfbba81e91760cf674fbdbdbcb69ebaf66167ae0 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Sat, 6 Jun 2026 12:19:42 +0530 Subject: [PATCH 18/20] refactor: fold projectAuth into locationAuth array, single property per method --- .../Platform/Modules/Avatars/Http/Browsers/Get.php | 2 +- .../Platform/Modules/Avatars/Http/CreditCards/Get.php | 2 +- .../Platform/Modules/Avatars/Http/Favicon/Get.php | 2 +- .../Platform/Modules/Avatars/Http/Flags/Get.php | 2 +- .../Platform/Modules/Avatars/Http/Image/Get.php | 2 +- .../Platform/Modules/Avatars/Http/Initials/Get.php | 2 +- src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php | 2 +- .../Platform/Modules/Avatars/Http/Screenshots/Get.php | 2 +- .../Functions/Http/Deployments/Download/Get.php | 2 +- .../Modules/Sites/Http/Deployments/Download/Get.php | 2 +- .../Storage/Http/Buckets/Files/Download/Get.php | 2 +- .../Modules/Storage/Http/Buckets/Files/Preview/Get.php | 2 +- .../Modules/Storage/Http/Buckets/Files/View/Get.php | 2 +- src/Appwrite/SDK/Method.php | 10 ++-------- 14 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php index 70f8a40e2c..6bb6731c04 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php @@ -42,7 +42,7 @@ class Get extends Action description: '/docs/references/avatars/get-browser.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php index 4cedbb42b1..304c47583b 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php @@ -42,7 +42,7 @@ class Get extends Action description: '/docs/references/avatars/get-credit-card.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php index 2dcb797f7a..89e9c73ab8 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php @@ -54,7 +54,7 @@ class Get extends Action description: '/docs/references/avatars/get-favicon.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php index 6b2b76bc2f..11d3b50a99 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php @@ -42,7 +42,7 @@ class Get extends Action description: '/docs/references/avatars/get-flag.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php index 9b7bee8be0..64ced4cc68 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php @@ -45,7 +45,7 @@ class Get extends Action description: '/docs/references/avatars/get-image.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php index 0b6df2353f..93ca892f6c 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php @@ -44,7 +44,7 @@ class Get extends Action description: '/docs/references/avatars/get-initials.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php index 86315c7101..67565220fc 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php @@ -42,7 +42,7 @@ class Get extends Action description: '/docs/references/avatars/get-qr.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php index 33ebcd73ab..cf6b5e2b0a 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php @@ -57,7 +57,7 @@ class Get extends Action description: '/docs/references/avatars/get-screenshot.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php index b246ccb0dc..eb7d51921e 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php @@ -53,7 +53,7 @@ class Get extends Action ], contentType: ContentType::ANY, type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], )) ->param('functionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Function ID.', false, ['dbForProject']) ->param('deploymentId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Deployment ID.', false, ['dbForProject']) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php index 13aa754d12..26987d145f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php @@ -51,7 +51,7 @@ class Get extends Action ) ], type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], contentType: ContentType::ANY, )) ->param('siteId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Site ID.', false, ['dbForProject']) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php index 22dcb3e3aa..e24b6819fa 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php @@ -58,7 +58,7 @@ class Get extends Action ], contentType: ContentType::ANY, type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], )) ->param('bucketId', '', new UID(), 'Storage bucket ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') ->param('fileId', '', new UID(), 'File ID.') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php index bee4798b9e..9c7c7ea1d1 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php @@ -71,7 +71,7 @@ class Get extends Action ) ], type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], contentType: ContentType::IMAGE )) ->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php index ea228e2ebd..a0f2d3a0bc 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php @@ -59,7 +59,7 @@ class Get extends Action ], contentType: ContentType::ANY, type: MethodType::LOCATION, - locationAuth: ['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], )) ->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') ->param('fileId', '', new UID(), 'File ID.') diff --git a/src/Appwrite/SDK/Method.php b/src/Appwrite/SDK/Method.php index ce793ee113..e364c96163 100644 --- a/src/Appwrite/SDK/Method.php +++ b/src/Appwrite/SDK/Method.php @@ -32,8 +32,7 @@ class Method * @param array $additionalParameters * @param string $desc * @param bool $public Whether this method should be rendered on the website/documentation - * @param string $projectAuth Project authentication security scheme to use in specs - * @param array $locationAuth Additional security scheme keys injected for location-type methods + * @param array $locationAuth Security scheme keys injected for location-type methods (includes project auth) */ public function __construct( protected string $namespace, @@ -52,17 +51,12 @@ class Method protected array $additionalParameters = [], protected string $desc = '', protected bool $public = true, - protected string $projectAuth = 'Project', protected array $locationAuth = [] ) { $this->validateMethod($name, $namespace); $this->validateAuthTypes($auth); $this->validateDesc($description); - if (!\in_array($projectAuth, ['Project', 'ProjectQuery'], true)) { - self::$errors[] = "Error with {$this->getRouteName()} method: Invalid project auth scheme"; - } - foreach ($responses as $response) { $this->validateResponseModel($response->getModel()); $this->validateNoContent($response); @@ -233,7 +227,7 @@ class Method public function getProjectAuth(): string { - return $this->projectAuth; + return $this->locationAuth[0] ?? 'Project'; } public function getLocationAuth(): array From c3c8fb5b9f9f213e919b7f1d23decc8e2de6e679 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Sat, 6 Jun 2026 19:36:54 +0530 Subject: [PATCH 19/20] refactor: rename ImpersonateUserIdQuery to ImpersonateUserQuery per ProjectQuery pattern --- src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php | 2 +- .../Platform/Modules/Avatars/Http/CreditCards/Get.php | 2 +- src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php | 2 +- src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php | 2 +- src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php | 2 +- src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php | 2 +- src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php | 2 +- .../Platform/Modules/Avatars/Http/Screenshots/Get.php | 2 +- .../Modules/Functions/Http/Deployments/Download/Get.php | 2 +- .../Modules/Sites/Http/Deployments/Download/Get.php | 2 +- .../Modules/Storage/Http/Buckets/Files/Download/Get.php | 2 +- .../Modules/Storage/Http/Buckets/Files/Preview/Get.php | 2 +- .../Modules/Storage/Http/Buckets/Files/View/Get.php | 2 +- src/Appwrite/Platform/Tasks/Specs.php | 6 +++--- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php index 6bb6731c04..2d66b5b21b 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php @@ -42,7 +42,7 @@ class Get extends Action description: '/docs/references/avatars/get-browser.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php index 304c47583b..710c7cd61d 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php @@ -42,7 +42,7 @@ class Get extends Action description: '/docs/references/avatars/get-credit-card.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php index 89e9c73ab8..244f426c4d 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php @@ -54,7 +54,7 @@ class Get extends Action description: '/docs/references/avatars/get-favicon.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php index 11d3b50a99..dfeaff0f8a 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php @@ -42,7 +42,7 @@ class Get extends Action description: '/docs/references/avatars/get-flag.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php index 64ced4cc68..3c791aa128 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php @@ -45,7 +45,7 @@ class Get extends Action description: '/docs/references/avatars/get-image.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php index 93ca892f6c..792026577b 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php @@ -44,7 +44,7 @@ class Get extends Action description: '/docs/references/avatars/get-initials.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php index 67565220fc..b8f3d0247d 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php @@ -42,7 +42,7 @@ class Get extends Action description: '/docs/references/avatars/get-qr.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php index cf6b5e2b0a..63d7d3f85e 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php @@ -57,7 +57,7 @@ class Get extends Action description: '/docs/references/avatars/get-screenshot.md', auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT], type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php index eb7d51921e..8adff12784 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php @@ -53,7 +53,7 @@ class Get extends Action ], contentType: ContentType::ANY, type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], )) ->param('functionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Function ID.', false, ['dbForProject']) ->param('deploymentId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Deployment ID.', false, ['dbForProject']) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php index 26987d145f..088bf6c499 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php @@ -51,7 +51,7 @@ class Get extends Action ) ], type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], contentType: ContentType::ANY, )) ->param('siteId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Site ID.', false, ['dbForProject']) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php index e24b6819fa..a11560cd5a 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php @@ -58,7 +58,7 @@ class Get extends Action ], contentType: ContentType::ANY, type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], )) ->param('bucketId', '', new UID(), 'Storage bucket ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') ->param('fileId', '', new UID(), 'File ID.') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php index 9c7c7ea1d1..dcc033260f 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php @@ -71,7 +71,7 @@ class Get extends Action ) ], type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], contentType: ContentType::IMAGE )) ->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php index a0f2d3a0bc..a88b41b3bc 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php @@ -59,7 +59,7 @@ class Get extends Action ], contentType: ContentType::ANY, type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], )) ->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).') ->param('fileId', '', new UID(), 'File ID.') diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index ffe8757a78..fa3889125d 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -181,7 +181,7 @@ class Specs extends Action 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], - 'ImpersonateUserIdQuery' => [ + 'ImpersonateUserQuery' => [ 'type' => 'apiKey', 'name' => 'impersonateUserId', 'description' => 'Impersonate a user by ID via query param. Used for location-type methods where headers cannot be set.', @@ -273,7 +273,7 @@ class Specs extends Action 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], - 'ImpersonateUserIdQuery' => [ + 'ImpersonateUserQuery' => [ 'type' => 'apiKey', 'name' => 'impersonateUserId', 'description' => 'Impersonate a user by ID via query param. Used for location-type methods where headers cannot be set.', @@ -365,7 +365,7 @@ class Specs extends Action 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], - 'ImpersonateUserIdQuery' => [ + 'ImpersonateUserQuery' => [ 'type' => 'apiKey', 'name' => 'impersonateUserId', 'description' => 'Impersonate a user by ID via query param. Used for location-type methods where headers cannot be set.', From 1d7ed046cbfe5b3be34faea02dd4df7ba6366c9f Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Sun, 7 Jun 2026 12:50:03 +0530 Subject: [PATCH 20/20] refactor: remove getProjectAuth(), use getLocationAuth()[0] directly in spec formatters --- src/Appwrite/SDK/Method.php | 5 ----- src/Appwrite/SDK/Specification/Format/OpenAPI3.php | 4 ++-- src/Appwrite/SDK/Specification/Format/Swagger2.php | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Appwrite/SDK/Method.php b/src/Appwrite/SDK/Method.php index e364c96163..f1b327513f 100644 --- a/src/Appwrite/SDK/Method.php +++ b/src/Appwrite/SDK/Method.php @@ -225,11 +225,6 @@ class Method return $this->additionalParameters; } - public function getProjectAuth(): string - { - return $this->locationAuth[0] ?? 'Project'; - } - public function getLocationAuth(): array { return $this->locationAuth; diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index cf83c3ea96..d9c2bf301e 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -188,7 +188,7 @@ class OpenAPI3 extends Format continue; } - $methodSecurities = [$methodObj->getProjectAuth() => []]; + $methodSecurities = [($methodObj->getLocationAuth()[0] ?? 'Project') => []]; foreach ($methodObj->getAuth() as $security) { if (\array_key_exists($security->value, $this->keys)) { $methodSecurities[$security->value] = []; @@ -374,7 +374,7 @@ class OpenAPI3 extends Format } if (!empty($scope)) { - $securities = [$sdk->getProjectAuth() => []]; + $securities = [($sdk->getLocationAuth()[0] ?? 'Project') => []]; foreach ($sdk->getAuth() as $security) { /** @var AuthType $security */ diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 0c4c423de1..b1541d5ddb 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -188,7 +188,7 @@ class Swagger2 extends Format continue; } - $methodSecurities = [$methodObj->getProjectAuth() => []]; + $methodSecurities = [($methodObj->getLocationAuth()[0] ?? 'Project') => []]; foreach ($methodObj->getAuth() as $security) { /** @var AuthType $security */ if (\array_key_exists($security->value, $this->keys)) { @@ -365,7 +365,7 @@ class Swagger2 extends Format } if (!empty($scope)) { - $securities = [$sdk->getProjectAuth() => []]; + $securities = [($sdk->getLocationAuth()[0] ?? 'Project') => []]; foreach ($sdk->getAuth() as $security) { if (\array_key_exists($security->value, $this->keys)) {