CpanelInc / backup-transport-dropbox

cPanel Custom Backup Transport for Dropbox
Apache License 2.0
15 stars 7 forks source link

Feature Request - Introduce token refreshing #26

Open 14nd90 opened 2 years ago

14nd90 commented 2 years ago

Appreciate this project is deprecated, but since Sep 2021 this script has become nearly redundant because Dropbox has prevented long lived access tokens being generated. This means that when I generate a new token in the Dropbox API and put it into this script, it works only for 4 hours.

May well try and tackle this myself but have no Perl experience.

14nd90 commented 2 years ago

Did manage to sort this. Dropbox does still generate long-lived refresh tokens which can then be used to obtain an access token, but these are just not generate-able through your Dropbox account as previously.

This long lived token is returned alongside a normal access token when 'token_access_type=offline' is added to a standard authorize request. I obtained this by knocking together a temporary script (but of course this could be done through a couple of standard curl calls from the command line instead)

use WebService::Dropbox;
use Data::Dumper; 

my $dropbox = WebService::Dropbox->new({
    key    => 'xxx',
    secret => 'xxx' 
});

my $url = $dropbox->authorize({
    response_type => 'code',
    token_access_type => 'offline'
});

print "Please Access URL and press Enter: $url\n";
print "Please Input Code: ";

chomp( my $code = <STDIN> );

unless ($dropbox->token($code)) {
    die $dropbox->error;
}

print Dumper($dropbox);

Then comb through the response for the "refresh_token" (since I don't think WebService supports accessing it nicely)

Then back in our transporter script, we can swap out this

$dropbox->access_token('xxx');

For this

$dropbox->refresh_access_token('xxx');