From c097d9fcdd7fb70d57750cfede5b1028e5e45c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 24 Apr 2026 12:20:48 +0200 Subject: [PATCH] Dropbox adapter --- app/init/models.php | 2 + .../Project/Http/Project/OAuth2/Base.php | 33 ++++++++++-- .../Http/Project/OAuth2/Dropbox/Update.php | 50 +++++++++++++++++++ .../Modules/Project/Services/Http.php | 2 + src/Appwrite/Utopia/Response.php | 1 + .../Utopia/Response/Model/OAuth2Dropbox.php | 47 +++++++++++++++++ 6 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Dropbox/Update.php create mode 100644 src/Appwrite/Utopia/Response/Model/OAuth2Dropbox.php diff --git a/app/init/models.php b/app/init/models.php index 46e758d5b2..5c2910786d 100644 --- a/app/init/models.php +++ b/app/init/models.php @@ -106,6 +106,7 @@ use Appwrite\Utopia\Response\Model\Mock; use Appwrite\Utopia\Response\Model\MockNumber; use Appwrite\Utopia\Response\Model\None; use Appwrite\Utopia\Response\Model\OAuth2Discord; +use Appwrite\Utopia\Response\Model\OAuth2Dropbox; use Appwrite\Utopia\Response\Model\OAuth2Figma; use Appwrite\Utopia\Response\Model\OAuth2GitHub; use Appwrite\Utopia\Response\Model\Phone; @@ -356,6 +357,7 @@ Response::setModel(new MockNumber()); Response::setModel(new OAuth2GitHub()); Response::setModel(new OAuth2Discord()); Response::setModel(new OAuth2Figma()); +Response::setModel(new OAuth2Dropbox()); Response::setModel(new PolicyPasswordDictionary()); Response::setModel(new PolicyPasswordHistory()); Response::setModel(new PolicyPasswordPersonalData()); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php index e2cc405a59..b40b0f06e8 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php @@ -63,6 +63,31 @@ abstract class Base extends Action */ abstract public static function getClientSecretDescription(): string; + /** + * Public-facing name of the clientId param. Some providers use a different + * terminology (e.g. Dropbox calls it "App key"), so the param name and the + * corresponding response field can be customized by overriding this method. + * + * @return string e.g. 'clientId' (default), 'appKey' + */ + public static function getClientIdParamName(): string + { + return 'clientId'; + } + + /** + * Public-facing name of the clientSecret param. Some providers use a + * different terminology (e.g. Dropbox calls it "App secret"), so the param + * name and the corresponding response field can be customized by + * overriding this method. + * + * @return string e.g. 'clientSecret' (default), 'appSecret' + */ + public static function getClientSecretParamName(): string + { + return 'clientSecret'; + } + public static function getName() { return 'updateProjectOAuth2' . static::getProviderLabel(); @@ -95,8 +120,8 @@ abstract class Base extends Action ) ], )) - ->param('clientId', null, new Nullable(new Text(256, 0)), static::getClientIdDescription(), optional: true) - ->param('clientSecret', null, new Nullable(new Text(512, 0)), static::getClientSecretDescription(), optional: true) + ->param(static::getClientIdParamName(), null, new Nullable(new Text(256, 0)), static::getClientIdDescription(), optional: true) + ->param(static::getClientSecretParamName(), null, new Nullable(new Text(512, 0)), static::getClientSecretDescription(), optional: true) ->param('enabled', null, new Nullable(new Boolean()), 'OAuth2 sign-in method status. Set to true to enable new session creation. Setting to true will trigger end-to-end credentials validation, and will throw if the credentials are invalid.', true) ->inject('response') ->inject('dbForPlatform') @@ -168,8 +193,8 @@ abstract class Base extends Action $response->dynamic(new Document([ '$id' => $providerId, 'enabled' => $oAuthProviders[$enabledKey] ?? false, - 'clientId' => $oAuthProviders[$appIdKey] ?? '', - 'clientSecret' => $oAuthProviders[$appSecretKey] ?? '', + static::getClientIdParamName() => $oAuthProviders[$appIdKey] ?? '', + static::getClientSecretParamName() => $oAuthProviders[$appSecretKey] ?? '', ]), static::getResponseModel()); } } diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Dropbox/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Dropbox/Update.php new file mode 100644 index 0000000000..6cc34cc612 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Dropbox/Update.php @@ -0,0 +1,50 @@ +addAction(UpdateOAuth2GitHub::getName(), new UpdateOAuth2GitHub()); $this->addAction(UpdateOAuth2Discord::getName(), new UpdateOAuth2Discord()); $this->addAction(UpdateOAuth2Figma::getName(), new UpdateOAuth2Figma()); + $this->addAction(UpdateOAuth2Dropbox::getName(), new UpdateOAuth2Dropbox()); } } diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 820ec8f75f..36ab89d012 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -281,6 +281,7 @@ class Response extends SwooleResponse public const MODEL_OAUTH2_GITHUB = 'oAuth2Github'; public const MODEL_OAUTH2_DISCORD = 'oAuth2Discord'; public const MODEL_OAUTH2_FIGMA = 'oAuth2Figma'; + public const MODEL_OAUTH2_DROPBOX = 'oAuth2Dropbox'; // Health public const MODEL_HEALTH_STATUS = 'healthStatus'; diff --git a/src/Appwrite/Utopia/Response/Model/OAuth2Dropbox.php b/src/Appwrite/Utopia/Response/Model/OAuth2Dropbox.php new file mode 100644 index 0000000000..9289168bcc --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/OAuth2Dropbox.php @@ -0,0 +1,47 @@ +addRule('appKey', [ + 'type' => self::TYPE_STRING, + 'description' => 'Dropbox OAuth 2 app key.', + 'default' => '', + 'example' => 'jl000000000009t', + ]) + ->addRule('appSecret', [ + 'type' => self::TYPE_STRING, + 'description' => 'Dropbox OAuth 2 app secret.', + 'default' => '', + 'example' => 'g200000000000vw', + ]); + } + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'OAuth2Dropbox'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_OAUTH2_DROPBOX; + } +}