dropbox-sdk-dotnet: how to get a refresh token and update the access token

1.4k Views Asked by At

I'm using the Dropbox SDK for DotNet, and it is time to support short-lived Access tokens. My use case is uncommon (web site, 'backend side'). Once the link to DropBox is made, everything should keep working unattended. In fact, it is OK to never publish the app. Each user creates its own app in their own Dropbox account and stays on Development mode forever.

Until now, the user created the dropbox app, takes note of the App key, App secret and generates an access token directly at https://www.dropbox.com/developers/apps/info/....

With this data, the application was working fine, but Access tokens will soon be short-lived only. I already verified the like to dropbox gets broken after the generated (from www.dropbox.com/developers/apps) Access Token expires.

How can I, using the SDK and having a valid Access token, get a refresh token to be saved and utilized to get a renewed access token?

I couldn't find any way in DropboxClient.cs, DropboxOauth2Helper.cs, not the examples at https://github.com/dropbox/dropbox-sdk-dotnet/tree/main/dropbox-sdk-dotnet/Examples

2

There are 2 best solutions below

1
On

It is not possible to use an access token to retrieve a refresh token. A refresh token can only be retrieved via the OAuth flow. I recommend reading the OAuth Guide for more information.

The "Generate" button on the app info page on the App Console does not currently offer the ability to generate a refresh token, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.

0
On

You can follow the accepted answer here to get a refresh token that will never expire. From this one, you can retrieve a valid token:

curl https://api.dropbox.com/oauth2/token -d grant_type=refresh_token -d refresh_token=oDfT54975DfGh12345KlMnOpQrSt01a -u <App key>:<App secret>