Replies: 10 comments 1 reply
-
|
Hi, there! I'm trying FlySystem with multiple adapters, one of those being dropbox, to access server-side offline-mode some directories. 2 days ago I tried it for the first time and managet it to work, but run into the 4-hour problem, as I made a "token in the web" which ends up being a short-lived access-token. Yesterday and today I've carefully read all this documentation:
Once finished reading I wanted to see if the flysystem-dropbox adapter supported re-generating the access-tokens from a refresh token. I have searched for My interestMy interest is making it to reach offline access for certain dropbox accounts we control (no "final user implication"). Say I need a server process that every hour needs to generate a report and make it available in a storage like dropbox. No "third users" implied in my use-case. I just don't want it to start failing after 4 hours. Questionsa) Am I correct? Is this server-side offline-mode no-user-interaction-mode still pending to be implemented in the flysystem-dropbox adapter? If already implemented where I can see docs about how to consume it? |
Beta Was this translation helpful? Give feedback.
-
|
@xmontero In my situation, when I need to back up a project daily, the code I provided above functions well, and I haven't encountered any issues with the '4-hour problem.' Does it also work for you when you follow the steps I outlined earlier? |
Beta Was this translation helpful? Give feedback.
-
|
Hey @mho22 thanks I don't know if in your class, that Illuminate-something is dependent on the Laravel framework. I can't recognize those I have done a similar solution inside my project. But I wanted my code to be designed to be framework-independent. I have all "dependency injected" so it could be used and reused within any framework using the flysystem-dropbox. Here's what I did: I've created a class, in my case From the consumption point of view it's very simple: In my own and I change it into this: The I don't mind, in my implementation, if one wants to store the access-token to be reused during consecutive calls for 3-4 hours in the filesystem, in a database, in memory or what... I just "cache it" via the cache interface. The method The gotten token is then stored into the cache for less time than its expiration in dropbox; so it'll be wiped from the cache before giving a 401 at any API call, so a new token is generated from time to time and re-cached again. At this moment I've hardcoded 10 mins although the proper way would be to read the duration from the API json reponse and take that value and substract a few minutes. The cache survives many controller calls, so the API to get the token is only called from time to time. In my current dirty implementation, once every 10 mins. It could be improved, of course. So, in short: I have it really solved in my application. I just wanted to leverage the library if this functionality was shifted inside it at some point of time and delete my implementation from my code, or offer me to push code to the library if it helps. I may share my class if anyone is interested. |
Beta Was this translation helpful? Give feedback.
-
|
@xmontero Okay, let's wait for a response from Spatie then! |
Beta Was this translation helpful? Give feedback.
-
|
@xmontero do you still use this logic and I'd be super interested in the class if you're willing to share! |
Beta Was this translation helpful? Give feedback.
-
|
@mho22 This looks like a very confusing way to do something rather simple. Why not just do: $client = new Client([$appKey, $appSecret]);
$adapter = new DropboxAdapter($client); |
Beta Was this translation helpful? Give feedback.
-
|
@sfinktah Have you tried this over a longer period? Long-lived access tokens are no longer generated, so your tokens will eventually expire. The method suggested above is a way to keep your tokens 'alive' by refreshing them while connecting to the Dropbox filesystem. At least, this was still the case six month ago. |
Beta Was this translation helpful? Give feedback.
-
Sorry, seen late. Still interested? Or am I late to the party? I'd have to dedicate time to find the class, etc. so will share only if it's going to add value. |
Beta Was this translation helpful? Give feedback.
-
|
If you have it laying around somewhere it would still be super useful! I do think ideally it would be documented/added to core, but I've kind of held off with adding this to our product due to being unsure how to implement it! |
Beta Was this translation helpful? Give feedback.
-
Well, I just tried it then, and while there are no errors produced, the directory listing shows no files. I generated a new token, and the result is the same. I don't know what to say. Very annoying. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Prior to : #86 and #95
I wanted to ask you if a new PR was necessary now that Dropbox has an updated way to work with tokens. It needs to generate a Refresh token beforehand. I added my way of working in the issue 86.
Since mid 2021, it is now mandatory to use the dropbox refresh token process :
I tried something else personally, without using AutoRefreshingDropBoxTokenService [ not necessary when using the flysystem-dropbox ] and it is less verbose :
You will still need to authorize the access to the Dropbox App using this link :
https://www.dropbox.com/oauth2/authorize?client_id<YOUR_APP_KEY>&response_type=code&token_access_type=offlineThis will give you the authorization_code needed to retrieve a refresh_token with this curl request :
curl https://api.dropbox.com/oauth2/token -d code=<ACCESS_CODE> -d grant_type=authorization_code -u <APP_KEY>:<APP_SECRET>Giving you access to the refresh_token needed in the DROPBOX_REFRESH_TOKEN indicated below . The other elements are available in your Dropbox App.
.env.example
config/filesystems.php
app/Providers/DropboxServiceProvider.php
A PR in code and documentation should be interesting. Should I PR this ? The previous code is also indicated in the Laravel 10 Documentation - Custom Filesystems
Beta Was this translation helpful? Give feedback.
All reactions