We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
Forum Discussion
cjacky475
2 years agoExplorer | Level 3
What's the correct way to handle expired access token
Hello, after user authenticates via OAuth2 I request refresh token, which I store on user's mobile device. Now to perform various actions (upload/download) from the user's Dropbox storage, I build: ...
- 2 years ago
Hi again cjacky475,
As seems the spam filter has caught your post 🤷 It happens from time to time - fake positive detection.
cjacky475 wrote:...
As from my current understanding, SDK updates the token internally for the current client. After I create client again, I provide the old access token and the refresh process starts again. Each time I instantiate the client, refresh will happen, until I manually call the refresh token method, get the access token, and save it, right?
In general Yes, but not need to perform it manually. Something more: DbxCredential class with nested classes and static objects ('JsonWriter<DbxCredential> Writer' and 'JsonReader<DbxCredential> Reader') make store and read entire credentials information much more easy and less error prone. Updating the access token only is insecure. The client updates everything needed within DbxCredetial object. 😉 Saving entire content and read back whenever needed (on next client object construction) is the best practice (in spite not something mandatory).
cjacky475 wrote:...
This way SDK will be refreshing the access token, since I always provide the old access token.
Greg-DB wrote:And as Здравко said, it is not required, but you can retrieve the current access token using DbxCredential.getAccessToken if you want.
The access token stored in the DbxCredential object that I used to create the DbxClientV2 stores the old access token.
...
Whenever needed (i.e. when valid access token is needed, but the previous one is expired already) the client will update all needed in the passed DbxCredential object. Yes, if the passed object contains only outdated data (including access token), refresh will be forced on every first operation. Something no best when client objects are going to construct relatively often - it's unlikely refresh to be mandatory/needed every single time. That's why the information in credential object is good to be stored at the object work finish (not only the access token). So when read the next time, the information will be actual.
cjacky475 wrote:...
My question again: after I instantiate user, perform some operations, how to get the updated access token? Can I get it from the client object? The SDK automatically refreshes the access token and where does it store it for me to access it? Thanks.
...
Let's think a bit...🤔 There are different ways an argument to be passed to a method/constructor. They commonly are divided to passed by value and passed by reference. Do you know how are they distinct? 🧐 ... and what are you using actually in your code? 😕... 😯😁
Hope this gives some directions... of thinking. 😉
Greg-DB
Dropbox Staff
cjacky475 Здравко is correct; when using an official Dropbox SDK and supplying a refresh token, you do not need to catch this in your own code.
It looks like you're using the Dropbox Java SDK, so if you're interested, you can see where the Java SDK handles this error internally for you here.
cjacky475
2 years agoExplorer | Level 3
Hi, Greg-DB, thanks for the answer. What if I perform a lot of operations, how is this secure to constantly use refresh token to get the access token? Is there no way to get the access token after it was refreshed internally in the SDK? This way I could store the access token and next time use it to instantiate the client object. Thanks.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,877 PostsLatest Activity: 12 months agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!