Dropbox adapter

This commit is contained in:
Matej Bačo
2026-04-24 12:20:48 +02:00
parent dac184b281
commit c097d9fcdd
6 changed files with 131 additions and 4 deletions
+2
View File
@@ -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());
@@ -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());
}
}
@@ -0,0 +1,50 @@
<?php
namespace Appwrite\Platform\Modules\Project\Http\Project\OAuth2\Dropbox;
use Appwrite\Auth\OAuth2\Dropbox;
use Appwrite\Platform\Modules\Project\Http\Project\OAuth2\Base;
use Appwrite\Utopia\Response;
class Update extends Base
{
public static function getProviderId(): string
{
return 'dropbox';
}
public static function getProviderClass(): string
{
return Dropbox::class;
}
public static function getProviderLabel(): string
{
return 'Dropbox';
}
public static function getResponseModel(): string
{
return Response::MODEL_OAUTH2_DROPBOX;
}
public static function getClientIdParamName(): string
{
return 'appKey';
}
public static function getClientSecretParamName(): string
{
return 'appSecret';
}
public static function getClientIdDescription(): string
{
return 'App key of Dropbox OAuth2 app. For example: jl000000000009t';
}
public static function getClientSecretDescription(): string
{
return 'App secret of Dropbox OAuth2 app. For example: g200000000000vw';
}
}
@@ -17,6 +17,7 @@ use Appwrite\Platform\Modules\Project\Http\Project\MockPhone\Get as GetMockPhone
use Appwrite\Platform\Modules\Project\Http\Project\MockPhone\Update as UpdateMockPhone;
use Appwrite\Platform\Modules\Project\Http\Project\MockPhone\XList as ListMockPhones;
use Appwrite\Platform\Modules\Project\Http\Project\OAuth2\Discord\Update as UpdateOAuth2Discord;
use Appwrite\Platform\Modules\Project\Http\Project\OAuth2\Dropbox\Update as UpdateOAuth2Dropbox;
use Appwrite\Platform\Modules\Project\Http\Project\OAuth2\Figma\Update as UpdateOAuth2Figma;
use Appwrite\Platform\Modules\Project\Http\Project\Platforms\Android\Create as CreateAndroidPlatform;
use Appwrite\Platform\Modules\Project\Http\Project\OAuth2\GitHub\Update as UpdateOAuth2GitHub;
@@ -137,5 +138,6 @@ class Http extends Service
$this->addAction(UpdateOAuth2GitHub::getName(), new UpdateOAuth2GitHub());
$this->addAction(UpdateOAuth2Discord::getName(), new UpdateOAuth2Discord());
$this->addAction(UpdateOAuth2Figma::getName(), new UpdateOAuth2Figma());
$this->addAction(UpdateOAuth2Dropbox::getName(), new UpdateOAuth2Dropbox());
}
}
+1
View File
@@ -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';
@@ -0,0 +1,47 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
class OAuth2Dropbox extends OAuth2Base
{
public function __construct()
{
parent::__construct();
$this
->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;
}
}