Skip to content

Commit

Permalink
fix dropbox access tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Jul 11, 2023
1 parent 5ccb6d8 commit c86b323
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
39 changes: 38 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,17 @@ public function boot(): void
});

Storage::extend('dropbox', static function (Container $app, array $config): FilesystemContract {
$client = new DropboxClient($config['access_token']);
$accessToken = Http::baseUrl('https://api.dropboxapi.com')
->timeout(5)
->retry(3, 50)
->withBasicAuth($config['app_key'], $config['app_secret'])
->post('/oauth2/token?'.Arr::query([
'grant_type' => 'refresh_token',
'refresh_token' => $config['refresh_token'],
]))
->json('access_token');

$client = new DropboxClient($accessToken);
$adapter = new DropboxAdapter($client);
$config = array_merge($config, ['case_sensitive' => false]);

Expand All @@ -139,6 +149,33 @@ public function boot(): void
);
});


Storage::extend('dropbox', function ($app, $config): FilesystemContract {
$accessToken = Http::baseUrl('https://api.dropboxapi.com')
->timeout(5)
->retry(3, 50)
->withBasicAuth($config['app_key'], $config['app_secret'])
->post('/oauth2/token?'.Arr::query([
'grant_type' => 'refresh_token',
'refresh_token' => $config['refresh_token'],
]))
->json('access_token');

$adapter = new DropboxAdapter(
new DropboxClient($accessToken)
);

$config = [
'case_sensitive' => false,
];

return new FilesystemAdapter(
new Filesystem($adapter, $config),
$adapter,
$config
);
});

URL::macro('horizon', function (string $uri): string {
/** @var \Illuminate\Routing\UrlGenerator $this */
if (config('horizon.domain') !== null) {
Expand Down
4 changes: 3 additions & 1 deletion config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@

'backups' => [
'driver' => 'dropbox',
'access_token' => env('BACKUP_DROPBOX_ACCESS_TOKEN'),
'app_key' => env('BACKUP_DROPBOX_APP_KEY'),
'app_secret' => env('BACKUP_DROPBOX_APP_SECRET'),
'refresh_token' => env('BACKUP_DROPBOX_REFRESH_TOKEN'),
'throw' => true,
],

Expand Down

0 comments on commit c86b323

Please sign in to comment.