diff --git a/app/init/realtime/connection.php b/app/init/realtime/connection.php index ea00b7f356..a090635bb5 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', '') ?: $request->getParam('impersonateUserId', ''))); - $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', ''))); + $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', '')); 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 f7a98e0f8f..416c294140 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', '') ?: $request->getParam('impersonateUserId', ''))); - $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', ''))); + $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', '')); if (!$user->isEmpty() && $user->getAttribute('impersonator', false)) { $userDb = (APP_MODE_ADMIN === $mode || $project->getId() === 'console') ? $dbForPlatform : $dbForProject; $targetUser = null; diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php index 2d66b5b21b..cc30f014bc 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Browsers/Get.php @@ -42,7 +42,6 @@ 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', '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 710c7cd61d..3bae32c862 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/CreditCards/Get.php @@ -42,7 +42,6 @@ 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', '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 244f426c4d..6faa0fe223 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php @@ -54,7 +54,6 @@ 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', '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 dfeaff0f8a..ef9f8c0e47 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Flags/Get.php @@ -42,7 +42,6 @@ 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', '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 3c791aa128..315202d4d5 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php @@ -45,7 +45,6 @@ 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', '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 792026577b..c73d20fb0c 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Initials/Get.php @@ -44,7 +44,6 @@ 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', '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 b8f3d0247d..f3448f5264 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/QR/Get.php @@ -42,7 +42,6 @@ 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', '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 63d7d3f85e..51d4df2a49 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php @@ -57,7 +57,6 @@ 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', '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 8adff12784..c92e3c1406 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php @@ -52,8 +52,7 @@ class Get extends Action ) ], contentType: ContentType::ANY, - type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + type: MethodType::LOCATION )) ->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 088bf6c499..0ab998292d 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,6 @@ class Get extends Action ) ], type: MethodType::LOCATION, - 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 a11560cd5a..7e5d7d6879 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,8 +57,7 @@ class Get extends Action ) ], contentType: ContentType::ANY, - type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + type: MethodType::LOCATION )) ->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 dcc033260f..9c316a3b57 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,6 @@ class Get extends Action ) ], type: MethodType::LOCATION, - 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 a88b41b3bc..b78d582c47 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,8 +58,7 @@ class Get extends Action ) ], contentType: ContentType::ANY, - type: MethodType::LOCATION, - locationAuth: ['Project', 'ImpersonateUserQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'], + type: MethodType::LOCATION )) ->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 fa3889125d..8717ae742e 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -181,36 +181,18 @@ 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', ], - 'ImpersonateUserQuery' => [ - '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' => [ @@ -273,36 +255,18 @@ 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', ], - 'ImpersonateUserQuery' => [ - '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' => [ @@ -365,36 +329,18 @@ 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', ], - 'ImpersonateUserQuery' => [ - '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/Method.php b/src/Appwrite/SDK/Method.php index f1b327513f..5f6ccf9a0f 100644 --- a/src/Appwrite/SDK/Method.php +++ b/src/Appwrite/SDK/Method.php @@ -32,7 +32,7 @@ class Method * @param array $additionalParameters * @param string $desc * @param bool $public Whether this method should be rendered on the website/documentation - * @param array $locationAuth Security scheme keys injected for location-type methods (includes project auth) + * @param string $projectAuth Project authentication security scheme to use in specs */ public function __construct( protected string $namespace, @@ -51,12 +51,16 @@ class Method protected array $additionalParameters = [], protected string $desc = '', protected bool $public = true, - protected array $locationAuth = [] + protected string $projectAuth = 'Project' ) { $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); @@ -225,9 +229,9 @@ class Method return $this->additionalParameters; } - public function getLocationAuth(): array + public function getProjectAuth(): string { - return $this->locationAuth; + return $this->projectAuth; } public function setNamespace(string $namespace): self diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index d9c2bf301e..dfa38b0bf5 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->getLocationAuth()[0] ?? 'Project') => []]; + $methodSecurities = [$methodObj->getProjectAuth() => []]; 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->getLocationAuth()[0] ?? 'Project') => []]; + $securities = [$sdk->getProjectAuth() => []]; foreach ($sdk->getAuth() as $security) { /** @var AuthType $security */ @@ -384,16 +384,6 @@ class OpenAPI3 extends Format } $temp['x-appwrite']['auth'] = array_slice($securities, 0, $this->authCount); - - if ($sdk->getType() === MethodType::LOCATION) { - foreach ($sdk->getLocationAuth() as $key) { - if (\array_key_exists($key, $this->keys)) { - $securities[$key] = []; - $temp['x-appwrite']['auth'][$key] = []; - } - } - } - $temp['security'][] = $securities; } diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index b1541d5ddb..20b1fb9b94 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->getLocationAuth()[0] ?? 'Project') => []]; + $methodSecurities = [$methodObj->getProjectAuth() => []]; 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->getLocationAuth()[0] ?? 'Project') => []]; + $securities = [$sdk->getProjectAuth() => []]; foreach ($sdk->getAuth() as $security) { if (\array_key_exists($security->value, $this->keys)) { @@ -374,16 +374,6 @@ class Swagger2 extends Format } $temp['x-appwrite']['auth'] = \array_slice($securities, 0, $this->authCount); - - if ($sdk->getType() === MethodType::LOCATION) { - foreach ($sdk->getLocationAuth() as $key) { - if (\array_key_exists($key, $this->keys)) { - $securities[$key] = []; - $temp['x-appwrite']['auth'][$key] = []; - } - } - } - $temp['security'][] = $securities; } diff --git a/tests/e2e/Services/Storage/StorageConsoleClientTest.php b/tests/e2e/Services/Storage/StorageConsoleClientTest.php index aca2717170..9d2a639631 100644 --- a/tests/e2e/Services/Storage/StorageConsoleClientTest.php +++ b/tests/e2e/Services/Storage/StorageConsoleClientTest.php @@ -10,8 +10,6 @@ use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideConsole; use Utopia\Database\Helpers\ID; -use Utopia\Database\Helpers\Permission; -use Utopia\Database\Helpers\Role; final class StorageConsoleClientTest extends Scope { @@ -200,82 +198,4 @@ final class StorageConsoleClientTest extends Scope ], $this->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::user($targetId)), - 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(404, $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 373b941fb4..1ac901bf58 100644 --- a/tests/e2e/Services/Users/UsersConsoleClientTest.php +++ b/tests/e2e/Services/Users/UsersConsoleClientTest.php @@ -83,87 +83,4 @@ final class UsersConsoleClientTest extends Scope $this->assertEquals($userId, $set['body']['$id']); $this->assertNotEmpty($set['body']['password']); } - - public function testImpersonateQueryParams(): void - { - $projectId = $this->getProject()['$id']; - $headers = array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()); - - $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']); - - $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' => $targetEmail, - 'password' => 'password123', - 'name' => 'Target', - ]); - $this->assertEquals(201, $target['headers']['status-code']); - - $this->client->call(Client::METHOD_PATCH, '/users/' . $targetId . '/phone', $headers, [ - 'number' => $targetPhone, - ]); - - $this->client->call(Client::METHOD_PATCH, '/users/' . $actorId . '/impersonator', $headers, [ - 'impersonator' => true, - ]); - - $session = $this->client->call(Client::METHOD_POST, '/users/' . $actorId . '/sessions', $headers); - $this->assertEquals(201, $session['headers']['status-code']); - - $sessionHeaders = [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-session' => $session['body']['secret'], - ]; - - $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']); - - $byUserId = $this->client->call(Client::METHOD_GET, '/account', $sessionHeaders, [ - 'impersonateuserid' => $targetId, - ]); - $this->assertEquals(200, $byUserId['headers']['status-code']); - $this->assertEquals($targetId, $byUserId['body']['$id']); - - $byEmail = $this->client->call(Client::METHOD_GET, '/account', $sessionHeaders, [ - 'impersonateemail' => $targetEmail, - ]); - $this->assertEquals(200, $byEmail['headers']['status-code']); - $this->assertEquals($targetId, $byEmail['body']['$id']); - - $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', - array_merge($sessionHeaders, ['x-appwrite-impersonate-user-id' => $targetId]), - ['impersonateuserid' => $actorId] - ); - $this->assertEquals(200, $priority['headers']['status-code']); - $this->assertEquals($targetId, $priority['body']['$id']); - } }