cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you interested in hearing how one of our Community members uses Dropbox for sailing trips? Read all about it here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Generate Long-live access token for Oauth

Generate Long-live access token for Oauth

Ivan_
Helpful | Level 6

Hi, I need to implement long-live token generation via c# code

I found this reference https://github.com/dropbox/dropbox-sdk-dotnet/blob/main/dropbox-sdk-dotnet/Examples/OAuthPKCE/Progra...

Unfortunately, this code returns token with the "sl." prefix, so it's short-lived access token.

My main question is : does DropBox Api supports refresh token functionality ?

If yes, how to do it properly, please, provide a reference to code samples

8 Replies 8

Greg-DB
Dropbox Staff

Yes, the Dropbox API and .NET SDK do support refresh tokens.

 

That sample requests "offline" access to get a refresh token in this line, the refresh token is received here, and the refresh token is used to make a client here. The client will perform the refresh process using the supplied refresh token automatically.

Ivan_
Helpful | Level 6

Hi @Greg-DB 

Thanks for response

Unfortunately I receive error, while trying to perform refresh

Ivan__0-1688061739328.png

 

Greg-DB
Dropbox Staff

There are a number of scenarios that can cause the refresh to fail like this, such as:

  • missing/incorrect/malformed refresh token
  • revoked refresh token (e.g., when the user unlinks the app via https://www.dropbox.com/account/connected_apps , etc.)
  • missing/incorrect/malformed app key
  • incorrect/malformed app secret
  • missing app secret (if the refresh token was retrieved using the non-PKCE flow)

Check and make sure you're supplying the correct values when building the DropboxClient. If you're supplying any incorrect value(s), update your app to supply the correct value(s). If the refresh token has been revoked, you'll need to have the user re-authorize the app to access the account to receive a new valid refresh token.

 

The response body on that 400 error response may contain a more specific error message, though the .NET SDK unfortunately does not currently expose that. There's an open request to update it to do so. You can perform the call manually to check for an error message in the response body however, e.g., using curl like this:

 

 

curl https://api.dropboxapi.com/oauth2/token \
    -d refresh_token=REFRESHTOKENHERE \
    -d grant_type=refresh_token \
    -d client_id=APPKEYHERE

 

 

By the way, you do not need to check for 'expired_access_token' yourself like that. As long as you provide correct credentials to the DropboxClient, it will catch and handle that error for you automatically.

 

I recommend running the sample code first to see how it works first.

Ivan_
Helpful | Level 6

Now I receive such error

Ivan__0-1688081341237.png

I double-checked client id, everything is right

Greg-DB
Dropbox Staff

There are a number of different things that can cause that error. Did you check everything listed in my previous message?

 

Have you tried running the example code without modification first?

Ivan_
Helpful | Level 6

Hi @Greg-DB 

I am trying to implement long-live token generation via code which was provided in first reply https://github.com/dropbox/dropbox-sdk-dotnet/blob/main/dropbox-sdk-dotnet/Examples/OAuthPKCE/Progra...

 

Unfortunately, when I am trying to receive response code the browser stops at stage when it gets approve from user in dialog window 

Ivan__0-1688390298095.png

 

I keep pressing "Approve" button, but nothing happens except the eternal loading

Please, check my code, maybe something must be changed 

 

Ivan__1-1688390110027.png

Two methods are exact as at DropBox git 

Ivan__2-1688390140177.png

Console App

Ivan__3-1688390229122.png

 

Ivan_
Helpful | Level 6

@Greg-DB  I checked all listed things and problem still exists

Greg-DB
Dropbox Staff

@Ivan_ For reference, does that flow in the original sample app work for you though? I highly suggest trying that out to make sure that works and see the flow processed fully before trying it out in your own code.

 

In any case, when using a redirect URI, Dropbox will redirect the user's browser to the specified redirect URI, which the code should then handle to receive the authorization code and complete the authorization process. This basic example code doesn't actually show anything in the browser to the user when doing so, but you can update it to do so if you want. Regardless, it may be helpful to use the debugger to see where code execution is going/stopping to debug any issues in your code.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Ivan_ Helpful | Level 6
What do Dropbox user levels mean?