Skip to content

Commit

Permalink
Fix Dropbox sync
Browse files Browse the repository at this point in the history
In order to support short-lived tokens we have to provide a
refresh token, which can be obtained from the Dropbox api.

Fixes issue #362
  • Loading branch information
sebastianfeldmann committed Nov 24, 2024
1 parent 7767662 commit ce3b139
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion doc/config/sync/dropbox.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "dropbox",
"options": {
"token": "myCrazyLongApiTokenThatIGotFromDropbox",
"refreshToken": "myCrazyLongRefreshTokenThatIGotFromDropbox",
"appKey": "myAppKey",
"appSecret": "myAppSecret",
"path": "/some/dir"
Expand Down
2 changes: 1 addition & 1 deletion doc/config/sync/dropbox.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<sync type="dropbox">
<!-- mandatory -->
<option name="token" value="mycrazylongapitokenthatigotfromdropbox" />
<option name="refreshToken" value="mycrazylongrefreshtokenthatigotfromdropbox" />

<!-- mandatory -->
<option name="appKey" value="myAppKey" />
Expand Down
41 changes: 24 additions & 17 deletions src/Backup/Sync/Dropbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ class Dropbox implements Simulator
*
* @var string
*/
protected $token;
private $appKey;

/**
* @var string
*/
private $appSecret;

/**
* @var string
*/
protected $refreshToken;

/**
* Remote path
Expand All @@ -60,16 +70,6 @@ class Dropbox implements Simulator
*/
protected $time;

/**
* @var string
*/
private $appKey;

/**
* @var string
*/
private $appSecret;

/**
* (non-PHPDoc)
*
Expand All @@ -85,12 +85,12 @@ public function setup(array $config)
}

// check for mandatory options
$this->validateConfig($config, ['token', 'path', 'appKey', 'appSecret']);
$this->validateConfig($config, ['refreshToken', 'path', 'appKey', 'appSecret']);

$this->time = time();
$this->token = $config['token'];
$this->appKey = $config['appKey'];
$this->appSecret = $config['appSecret'];
$this->time = time();
$this->refreshToken = $config['refreshToken'];
$this->appKey = $config['appKey'];
$this->appSecret = $config['appSecret'];
// make sure the path contains a leading slash
$this->path = new Path(Util\Path::withLeadingSlash($config['path']), $this->time);

Expand Down Expand Up @@ -179,7 +179,14 @@ protected function createCollector(Target $target) : Collector
protected function createClient() : DropboxApi\Dropbox
{
if (!$this->client) {
$app = new DropboxApi\DropboxApp($this->appKey, $this->appSecret, $this->token);
$app = new DropboxApi\DropboxApp($this->appKey, $this->appSecret);
$client = new DropboxApi\Dropbox($app);
$authHelper = $client->getAuthHelper();
$token = $authHelper->getRefreshedAccessToken(
new DropboxApi\Models\AccessToken(['refresh_token' => $this->refreshToken])
);

$app = new DropboxApi\DropboxApp($this->appKey, $this->appSecret, $token->getToken());
$this->client = new DropboxApi\Dropbox($app);
}
return $this->client;
Expand Down

0 comments on commit ce3b139

Please sign in to comment.