diff --git a/app/config/collections/common.php b/app/config/collections/common.php index 80bb717423..37fbcc8ca3 100644 --- a/app/config/collections/common.php +++ b/app/config/collections/common.php @@ -1523,6 +1523,13 @@ return [ 'lengths' => [], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => ID::custom('_key_team_confirm'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['teamInternalId', 'confirm'], + 'lengths' => [], + 'orders' => [], + ], ], ], diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index 6195c11724..748211f222 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -404,6 +404,13 @@ $platformCollections = [ 'lengths' => [], 'orders' => [], ], + [ + '$id' => ID::custom('_key_teamInternalId'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['teamInternalId'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], ], ], @@ -635,6 +642,13 @@ $platformCollections = [ 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => ID::custom('_key_project_id'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['projectId'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], ], ], @@ -1007,7 +1021,14 @@ $platformCollections = [ 'attributes' => ['projectInternalId'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], - ] + ], + [ + '$id' => ID::custom('_key_project_id'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['projectId'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], ], ], diff --git a/composer.json b/composer.json index dac5be561f..9a84be6111 100644 --- a/composer.json +++ b/composer.json @@ -79,8 +79,8 @@ "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", "utopia-php/preloader": "0.2.*", - "utopia-php/queue": "0.17.*", - "utopia-php/servers": "0.3.*", + "utopia-php/queue": "0.18.*", + "utopia-php/servers": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/storage": "2.*", "utopia-php/system": "0.10.*", diff --git a/composer.lock b/composer.lock index 64c703cf2d..bbf0d59a96 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "67c7d160c4a122b14eaa235d2417ea60", + "content-hash": "ec2ad489c60f0102f0dfab223b6d1fe4", "packages": [ { "name": "adhocore/jwt", @@ -2708,16 +2708,16 @@ }, { "name": "symfony/http-client", - "version": "v7.4.8", + "version": "v7.4.9", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "01933e626c3de76bea1e22641e205e78f6a34342" + "reference": "7e941c6abf4e3bf7dca160bf0e11ef36a9f832f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/01933e626c3de76bea1e22641e205e78f6a34342", - "reference": "01933e626c3de76bea1e22641e205e78f6a34342", + "url": "https://api.github.com/repos/symfony/http-client/zipball/7e941c6abf4e3bf7dca160bf0e11ef36a9f832f6", + "reference": "7e941c6abf4e3bf7dca160bf0e11ef36a9f832f6", "shasum": "" }, "require": { @@ -2785,7 +2785,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.4.8" + "source": "https://github.com/symfony/http-client/tree/v7.4.9" }, "funding": [ { @@ -2805,7 +2805,7 @@ "type": "tidelift" } ], - "time": "2026-03-30T12:55:43+00:00" + "time": "2026-04-29T13:25:15+00:00" }, { "name": "symfony/http-client-contracts", @@ -3658,21 +3658,21 @@ }, { "name": "utopia-php/cli", - "version": "0.23.2", + "version": "0.23.3", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "145b91fef827853bcceaa3ab8ca2b1d6faaca2ab" + "reference": "3c45ae5bcdcd3c7916e1909d74c60b8e771610db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/145b91fef827853bcceaa3ab8ca2b1d6faaca2ab", - "reference": "145b91fef827853bcceaa3ab8ca2b1d6faaca2ab", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/3c45ae5bcdcd3c7916e1909d74c60b8e771610db", + "reference": "3c45ae5bcdcd3c7916e1909d74c60b8e771610db", "shasum": "" }, "require": { "php": ">=7.4", - "utopia-php/servers": "0.3.*" + "utopia-php/servers": "0.4.0" }, "require-dev": { "laravel/pint": "1.2.*", @@ -3703,9 +3703,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cli/issues", - "source": "https://github.com/utopia-php/cli/tree/0.23.2" + "source": "https://github.com/utopia-php/cli/tree/0.23.3" }, - "time": "2026-04-27T09:19:04+00:00" + "time": "2026-05-05T04:38:59+00:00" }, { "name": "utopia-php/compression", @@ -4272,23 +4272,23 @@ }, { "name": "utopia-php/http", - "version": "0.34.24", + "version": "0.34.25", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "d1eced0627c5a9fceddf53992ed97d664b810d33" + "reference": "76be330d4197bae680eb4ccc29c573456fe91904" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/d1eced0627c5a9fceddf53992ed97d664b810d33", - "reference": "d1eced0627c5a9fceddf53992ed97d664b810d33", + "url": "https://api.github.com/repos/utopia-php/http/zipball/76be330d4197bae680eb4ccc29c573456fe91904", + "reference": "76be330d4197bae680eb4ccc29c573456fe91904", "shasum": "" }, "require": { "php": ">=8.3", "utopia-php/compression": "0.1.*", "utopia-php/di": "0.3.*", - "utopia-php/servers": "0.3.*", + "utopia-php/servers": "0.4.0", "utopia-php/telemetry": "0.2.*", "utopia-php/validators": "0.2.*" }, @@ -4322,9 +4322,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.34.24" + "source": "https://github.com/utopia-php/http/tree/0.34.25" }, - "time": "2026-04-24T12:16:53+00:00" + "time": "2026-05-05T04:39:15+00:00" }, { "name": "utopia-php/image", @@ -4647,26 +4647,26 @@ }, { "name": "utopia-php/platform", - "version": "0.13.0", + "version": "0.13.2", "source": { "type": "git", "url": "https://github.com/utopia-php/platform.git", - "reference": "d23af5349a7ea9ee11f9920a13626226f985522e" + "reference": "a20cb8b20a1e4c9886309c2d033a0292ba0937b9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/platform/zipball/d23af5349a7ea9ee11f9920a13626226f985522e", - "reference": "d23af5349a7ea9ee11f9920a13626226f985522e", + "url": "https://api.github.com/repos/utopia-php/platform/zipball/a20cb8b20a1e4c9886309c2d033a0292ba0937b9", + "reference": "a20cb8b20a1e4c9886309c2d033a0292ba0937b9", "shasum": "" }, "require": { "ext-json": "*", "ext-redis": "*", - "php": ">=8.1", - "utopia-php/cli": "0.23.*", - "utopia-php/http": "0.34.*", - "utopia-php/queue": "0.17.*", - "utopia-php/servers": "0.3.*" + "php": ">=8.3", + "utopia-php/cli": "0.23.3", + "utopia-php/http": "0.34.25", + "utopia-php/queue": "0.18.2", + "utopia-php/servers": "0.4.0" }, "require-dev": { "laravel/pint": "1.2.*", @@ -4692,9 +4692,9 @@ ], "support": { "issues": "https://github.com/utopia-php/platform/issues", - "source": "https://github.com/utopia-php/platform/tree/0.13.0" + "source": "https://github.com/utopia-php/platform/tree/0.13.2" }, - "time": "2026-04-17T09:57:18+00:00" + "time": "2026-05-05T06:00:26+00:00" }, { "name": "utopia-php/pools", @@ -4804,25 +4804,24 @@ }, { "name": "utopia-php/queue", - "version": "0.17.0", + "version": "0.18.2", "source": { "type": "git", "url": "https://github.com/utopia-php/queue.git", - "reference": "0fbc7d7312f5cf76ec112513fb93317000901f5f" + "reference": "f85ca003c99ff475708c05466643d067403c0c22" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/queue/zipball/0fbc7d7312f5cf76ec112513fb93317000901f5f", - "reference": "0fbc7d7312f5cf76ec112513fb93317000901f5f", + "url": "https://api.github.com/repos/utopia-php/queue/zipball/f85ca003c99ff475708c05466643d067403c0c22", + "reference": "f85ca003c99ff475708c05466643d067403c0c22", "shasum": "" }, "require": { "php": ">=8.3", "php-amqplib/php-amqplib": "^3.7", "utopia-php/di": "0.3.*", - "utopia-php/fetch": "0.5.*", "utopia-php/pools": "1.*", - "utopia-php/servers": "0.3.*", + "utopia-php/servers": "0.4.0", "utopia-php/telemetry": "0.2.*", "utopia-php/validators": "0.2.*" }, @@ -4865,9 +4864,9 @@ ], "support": { "issues": "https://github.com/utopia-php/queue/issues", - "source": "https://github.com/utopia-php/queue/tree/0.17.0" + "source": "https://github.com/utopia-php/queue/tree/0.18.2" }, - "time": "2026-03-23T16:21:31+00:00" + "time": "2026-05-05T04:38:59+00:00" }, { "name": "utopia-php/registry", @@ -4923,16 +4922,16 @@ }, { "name": "utopia-php/servers", - "version": "0.3.0", + "version": "0.4.0", "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "235be31200df9437fc96a1c270ffef4c64fafe52" + "reference": "7db346ef377503efe0acafe0791085270cd9ed70" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/235be31200df9437fc96a1c270ffef4c64fafe52", - "reference": "235be31200df9437fc96a1c270ffef4c64fafe52", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/7db346ef377503efe0acafe0791085270cd9ed70", + "reference": "7db346ef377503efe0acafe0791085270cd9ed70", "shasum": "" }, "require": { @@ -4971,9 +4970,9 @@ ], "support": { "issues": "https://github.com/utopia-php/servers/issues", - "source": "https://github.com/utopia-php/servers/tree/0.3.0" + "source": "https://github.com/utopia-php/servers/tree/0.4.0" }, - "time": "2026-03-13T11:31:42+00:00" + "time": "2026-05-05T04:08:30+00:00" }, { "name": "utopia-php/span", @@ -5021,16 +5020,16 @@ }, { "name": "utopia-php/storage", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "8a2e3a86fd01aaed675884146665308c2122264e" + "reference": "64e132a3768e22243eda36fe4262da22fd204f3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/8a2e3a86fd01aaed675884146665308c2122264e", - "reference": "8a2e3a86fd01aaed675884146665308c2122264e", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/64e132a3768e22243eda36fe4262da22fd204f3c", + "reference": "64e132a3768e22243eda36fe4262da22fd204f3c", "shasum": "" }, "require": { @@ -5067,22 +5066,22 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/2.0.1" + "source": "https://github.com/utopia-php/storage/tree/2.0.2" }, - "time": "2026-04-29T09:05:48+00:00" + "time": "2026-05-01T15:06:16+00:00" }, { "name": "utopia-php/system", - "version": "0.10.1", + "version": "0.10.2", "source": { "type": "git", "url": "https://github.com/utopia-php/system.git", - "reference": "7c1669533bb9c285de19191270c8c1439161a78a" + "reference": "04229a822b147c1abaf1a92fb42c2d7aad4625df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/system/zipball/7c1669533bb9c285de19191270c8c1439161a78a", - "reference": "7c1669533bb9c285de19191270c8c1439161a78a", + "url": "https://api.github.com/repos/utopia-php/system/zipball/04229a822b147c1abaf1a92fb42c2d7aad4625df", + "reference": "04229a822b147c1abaf1a92fb42c2d7aad4625df", "shasum": "" }, "require": { @@ -5123,9 +5122,9 @@ ], "support": { "issues": "https://github.com/utopia-php/system/issues", - "source": "https://github.com/utopia-php/system/tree/0.10.1" + "source": "https://github.com/utopia-php/system/tree/0.10.2" }, - "time": "2026-03-15T21:07:41+00:00" + "time": "2026-05-05T14:33:41+00:00" }, { "name": "utopia-php/telemetry", @@ -5467,16 +5466,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.25.1", + "version": "1.27.5", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "f21a556b9acdbf75bbdcdc90a078af641646eade" + "reference": "9faa38b48d422f3da764a719712905c83b3922cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/f21a556b9acdbf75bbdcdc90a078af641646eade", - "reference": "f21a556b9acdbf75bbdcdc90a078af641646eade", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/9faa38b48d422f3da764a719712905c83b3922cb", + "reference": "9faa38b48d422f3da764a719712905c83b3922cb", "shasum": "" }, "require": { @@ -5512,9 +5511,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/1.25.1" + "source": "https://github.com/appwrite/sdk-generator/tree/1.27.5" }, - "time": "2026-04-28T11:12:22+00:00" + "time": "2026-05-05T12:09:40+00:00" }, { "name": "brianium/paratest", @@ -6621,16 +6620,16 @@ }, { "name": "phpunit/phpunit", - "version": "12.5.23", + "version": "12.5.24", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c54fcf3d6bcb6e96ac2f7e40097dc37b5f139969" + "reference": "d75dd30597caa80e72fad2ef7904601a30ef1046" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c54fcf3d6bcb6e96ac2f7e40097dc37b5f139969", - "reference": "c54fcf3d6bcb6e96ac2f7e40097dc37b5f139969", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d75dd30597caa80e72fad2ef7904601a30ef1046", + "reference": "d75dd30597caa80e72fad2ef7904601a30ef1046", "shasum": "" }, "require": { @@ -6699,7 +6698,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.23" + "source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.24" }, "funding": [ { @@ -6707,7 +6706,7 @@ "type": "other" } ], - "time": "2026-04-18T06:12:49+00:00" + "time": "2026-05-01T04:21:04+00:00" }, { "name": "sebastian/cli-parser", @@ -7692,16 +7691,16 @@ }, { "name": "symfony/console", - "version": "v8.0.8", + "version": "v8.0.9", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "5b66d385dc58f69652e56f78a4184615e3f2b7f7" + "reference": "7113778e2e91f4709cb3194a75dfa9c0d028d94d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/5b66d385dc58f69652e56f78a4184615e3f2b7f7", - "reference": "5b66d385dc58f69652e56f78a4184615e3f2b7f7", + "url": "https://api.github.com/repos/symfony/console/zipball/7113778e2e91f4709cb3194a75dfa9c0d028d94d", + "reference": "7113778e2e91f4709cb3194a75dfa9c0d028d94d", "shasum": "" }, "require": { @@ -7758,7 +7757,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v8.0.8" + "source": "https://github.com/symfony/console/tree/v8.0.9" }, "funding": [ { @@ -7778,7 +7777,7 @@ "type": "tidelift" } ], - "time": "2026-03-30T15:14:47+00:00" + "time": "2026-04-29T15:02:55+00:00" }, { "name": "symfony/polyfill-ctype", diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Get.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Get.php index ae46a59c67..250a3e5df1 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Get.php @@ -11,7 +11,7 @@ use Utopia\Config\Config; use Utopia\Database\Document; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; -use Utopia\Validator\Text; +use Utopia\Validator\WhiteList; class Get extends Action { @@ -86,28 +86,28 @@ class Get extends Action ) ] )) - ->param('provider', '', new Text(128), 'OAuth2 provider key. For example: github, google, apple.') + ->param('providerId', '', new WhiteList(\array_keys(Config::getParam('oAuthProviders', [])), true), 'OAuth2 provider key. For example: github, google, apple.', aliases: ['provider']) ->inject('response') ->inject('project') ->callback($this->action(...)); } public function action( - string $provider, + string $providerId, Response $response, Document $project, ): void { $providers = Config::getParam('oAuthProviders', []); - if (!\array_key_exists($provider, $providers) || !($providers[$provider]['enabled'] ?? false)) { + if (!\array_key_exists($providerId, $providers) || !($providers[$providerId]['enabled'] ?? false)) { throw new Exception(Exception::PROJECT_PROVIDER_UNSUPPORTED); } $actions = Base::getProviderActions(); - if (!isset($actions[$provider])) { + if (!isset($actions[$providerId])) { throw new Exception(Exception::PROJECT_PROVIDER_UNSUPPORTED); } - $updateClass = $actions[$provider]; + $updateClass = $actions[$providerId]; $action = new $updateClass(); $response->dynamic($action->buildReadResponse($project), $updateClass::getResponseModel()); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/XList.php index d0780e4bae..6a84868286 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/XList.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/XList.php @@ -2,14 +2,21 @@ namespace Appwrite\Platform\Modules\Project\Http\Project\OAuth2; +use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response; use Utopia\Config\Config; use Utopia\Database\Document; +use Utopia\Database\Exception\Query as QueryException; +use Utopia\Database\Query; +use Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Query\Limit; +use Utopia\Database\Validator\Query\Offset; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; +use Utopia\Validator\Boolean; class XList extends Action { @@ -43,15 +50,28 @@ class XList extends Action ) ] )) + ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('project') ->callback($this->action(...)); } + /** + * @param array $queries + */ public function action( + array $queries, + bool $includeTotal, Response $response, Document $project, ): void { + try { + $queries = Query::parseQueries($queries); + } catch (QueryException $e) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); + } + $providers = Config::getParam('oAuthProviders', []); $actions = Base::getProviderActions(); @@ -66,8 +86,16 @@ class XList extends Action $documents[] = $action->buildReadResponse($project); } + $total = $includeTotal ? \count($documents) : 0; + + $grouped = Query::groupByType($queries); + $offset = $grouped['offset'] ?? 0; + $limit = $grouped['limit'] ?? null; + + $documents = \array_slice($documents, $offset, $limit); + $response->dynamic(new Document([ - 'total' => \count($documents), + 'total' => $total, 'providers' => $documents, ]), Response::MODEL_OAUTH2_PROVIDER_LIST); } diff --git a/tests/e2e/Services/Project/OAuth2Base.php b/tests/e2e/Services/Project/OAuth2Base.php index 5451435c3c..a55cc559b2 100644 --- a/tests/e2e/Services/Project/OAuth2Base.php +++ b/tests/e2e/Services/Project/OAuth2Base.php @@ -5,6 +5,7 @@ namespace Tests\E2E\Services\Project; use PHPUnit\Framework\Attributes\Before; use PHPUnit\Framework\Attributes\DataProvider; use Tests\E2E\Client; +use Utopia\Database\Query; trait OAuth2Base { @@ -172,6 +173,40 @@ trait OAuth2Base $this->assertNotContains('mock-unverified', $ids); } + public function testListOAuth2ProvidersTotalFalse(): void + { + $response = $this->listOAuth2Providers(total: false); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame(0, $response['body']['total']); + $this->assertGreaterThan(0, \count($response['body']['providers'])); + } + + public function testListOAuth2ProvidersWithLimit(): void + { + $response = $this->listOAuth2Providers([ + Query::limit(1)->toString(), + ]); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertCount(1, $response['body']['providers']); + $this->assertGreaterThan(1, $response['body']['total']); + } + + public function testListOAuth2ProvidersWithOffset(): void + { + $listAll = $this->listOAuth2Providers(); + $this->assertSame(200, $listAll['headers']['status-code']); + + $listOffset = $this->listOAuth2Providers([ + Query::offset(1)->toString(), + ]); + + $this->assertSame(200, $listOffset['headers']['status-code']); + $this->assertCount(\count($listAll['body']['providers']) - 1, $listOffset['body']['providers']); + $this->assertSame($listAll['body']['total'], $listOffset['body']['total']); + } + // ========================================================================= // Get OAuth2 provider // ========================================================================= @@ -188,6 +223,28 @@ trait OAuth2Base $this->assertSame('', $response['body']['clientSecret']); } + public function testGetOAuth2ProviderWithAlias(): void + { + // The action declares the canonical param name as `providerId` and + // registers `provider` as an alias so that older SDK versions that + // send the provider in the query string continue to work. + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]; + $headers = \array_merge($headers, $this->getHeaders()); + + // Call with `provider` in query string (legacy behaviour) + $response = $this->client->call( + Client::METHOD_GET, + '/project/oauth2/github?provider=github', + $headers, + ); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame('github', $response['body']['$id']); + } + public function testGetOAuth2ProviderClientSecretWriteOnly(): void { $this->updateOAuth2('amazon', [ @@ -221,19 +278,23 @@ trait OAuth2Base public function testGetOAuth2ProviderUnsupported(): void { + // The `providerId` param is validated by a WhiteList of registered + // OAuth2 provider keys, so an unknown value is rejected at validation + // time — before the action runs — and surfaces as a generic argument + // error rather than `project_provider_unsupported`. $response = $this->getOAuth2Provider('not-a-real-provider'); $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('project_provider_unsupported', $response['body']['type']); + $this->assertSame('general_argument_invalid', $response['body']['type']); } public function testGetOAuth2ProviderRegisteredInConfigButNoUpdateClass(): void { - // `mock` is present in oAuthProviders config (enabled: true) but is NOT - // registered in Base::getProviderActions(). Get::action has two - // separate `unsupported` throw branches — testGetOAuth2ProviderUnsupported - // covers the first (provider missing from config); this covers the - // second (provider in config but missing from the action registry). + // `mock` is present in oAuthProviders config (enabled: true) but is + // NOT registered in Base::getProviderActions(). It passes the + // WhiteList validator (which only checks config membership) and + // reaches the action body, where the action-registry check throws + // `project_provider_unsupported`. $response = $this->getOAuth2Provider('mock'); $this->assertSame(400, $response['headers']['status-code']); @@ -2573,7 +2634,7 @@ trait OAuth2Base ); } - protected function getOAuth2Provider(string $provider, bool $authenticated = true): mixed + protected function getOAuth2Provider(string $providerId, bool $authenticated = true): mixed { $headers = [ 'content-type' => 'application/json', @@ -2586,13 +2647,23 @@ trait OAuth2Base return $this->client->call( Client::METHOD_GET, - '/project/oauth2/' . $provider, + '/project/oauth2/' . $providerId, $headers, ); } - protected function listOAuth2Providers(bool $authenticated = true): mixed + protected function listOAuth2Providers(?array $queries = null, ?bool $total = null, bool $authenticated = true): mixed { + $params = []; + + if ($queries !== null) { + $params['queries'] = $queries; + } + + if ($total !== null) { + $params['total'] = $total; + } + $headers = [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -2606,6 +2677,7 @@ trait OAuth2Base Client::METHOD_GET, '/project/oauth2', $headers, + $params, ); } }