sebastianfeldmann / phpbu

PHP Backup Utility - Creates and encrypts database and file backups, syncs your backups to other servers or cloud services and assists you monitor your backup process
https://phpbu.de
Other
1.29k stars 110 forks source link

DropBox tokens expire after 4 hours #362

Open YouveGotMeowxy opened 7 months ago

YouveGotMeowxy commented 7 months ago

@sebastianfeldmann

Any chance of getting this fixed pretty soon? The key expires every 4 hours now, meaning adding to a daily cron job always fails, because the key has expired. Then in order to get it working again the user has to go back to their dbox app page, regen an 4hr key, and replace them all in their .json config. For me right now that's 9 locations in the configs. :)

btw, just wanted to add, this is one of the greatest apps ever, lol. Once it's all setup and running smooth, it's soo awesome.

Originally posted by @YouveGotMeowxy in https://github.com/sebastianfeldmann/phpbu/issues/356#issuecomment-1890908435

sebastianfeldmann commented 7 months ago

thanks @YouveGotMeowxy :)

To be honest, I'm not sure how fast I can fix this. I would need to get into this refresh token thing and implement the logic to reissue valid tokens and so on.

I hope I can start looking into it maybe end of next week but I really can't make any promises :/

Plan so far:

  1. Make refresh token configurable
  2. Make sure to retrieve valid token before the sync
  3. Execute the actual sync
YouveGotMeowxy commented 7 months ago

@sebastianfeldmann ok, thank you for any work on it. :)

I don't really know if this will help you out any, but I was just looking around about how to get a permanent token and came across this; maybe it might help ya out as well.

https://www.codemzy.com/blog/dropbox-long-lived-access-refresh-token

YouveGotMeowxy commented 3 months ago

4 months since this issue; any forward-movement happening? :)

jmcdougal commented 2 months ago

I came across this post as I was having the same issue as I use Dropbox as well for my backups. I resolved it by getting the application access code as mentioned here: https://www.codemzy.com/blog/dropbox-long-lived-access-refresh-token. Using CURL, I retrieved the long lived refresh token using the application access code with a grant type of "authorization_code". I then created another CURL request to Dropbox asking for the short lived access token that I store in a MySQL database. To do that, you use the long lived refresh token from the first CURL request with the grant type of "refresh_token".

An additional PHP script programmatically rebuilds the phpbu.xml file inserting the current refresh token into the line of <option name="token" value="<YOUR_CURRENT_SHORT_LIVED_ACCESS_TOKEN"/> . Using file_put_contents at the end of this script, the previous phpbu.xml file is replaced with a copy that has the newly updated token.

The backup runs twice daily using multiple cron jobs. The first gets the updated short lived access token. The second updates the phpbu.xml script and the third runs the backup. Each cron job is separated by five minutes. This could be simplified to one cron job and script, but works fine as is and I have moved on to other projects.

Anyway, thought this might be helpful as you navigate this issue. Overall, PHPBU is an excellent tool. Great job Sebastian!