You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
GevorgMel
5 years agoHelpful | Level 5
Dropbox .NET SDK (Refresh Token)
Hi, I found changes in OAuth2 for API, so the authorization could be done with offline access, ascuirung both Access and Refresh tokens. This part is OK, with ProcessCodeFlow method in SDK. But co...
- 5 years ago
GevorgMel This functionality should now be available on DropboxTeamClient as of release v5.1.0. Please update and give that a try and let us know if you run in to any issues. Thanks!
OFV
Explorer | Level 3
I understand, the Dropbox client can automatically refresh the refresh tokens if fed with the correct access token and refresh token.
But how can I retrieve the actual new access token and refresh token, to store it, for new instances of the DropboxClient?
Greg-DB
5 years agoDropbox Staff
OFV The Dropbox client in the SDK can and will automatically handle the refresh for you, and you shouldn't even need to access to refresh token or new access token after a refresh. The refresh token doesn't change, and the client will automatically set its new access token. And if you need another client, you can just create it like you did originally and let the client handle the refresh again if needed.
- OFV5 years agoExplorer | Level 3
Excellent! thanks
- OFV5 years agoExplorer | Level 3
Greg, I still can't get it to work for a duration longer than the access token's validity.
(this part works:)
I ask for user authentication (only once) using the DropboxOAuth2Helper.GetAuthorizeUri with OAuthResponseType.Code and TokenAccessType.Offline.
The resulting POST http request gives me a code and DropboxOAuth2Helper.ProcessCodeFlowAsync provides me an access token and refresh token based on that code. The tokens are persisted in the DB and to be used for longer periods (months) without the user needing to re-login
(this part fails:)
The DropboxClient is instantiated with the Access_token and refresh token retrieved in the first part.
Using the DropboxClient.Files.ListFolderAsync it works for a while (a few hours after initial usser auth), but the next day it fails with "Dropbox.Api.AuthException: expired_access_token/"
It concerns an MVC webapp, and the dropboxclient is newly instantiated on every use.
I thought the DropboxClient would do "it's thing" using the initial access and refresh tokens.
(I am using the Official Dropbox .Net v2 SDK v5.5.0 Nuget package)
- Greg-DB5 years agoDropbox Staff
OFV When your "DropboxClient is instantiated with the Access_token and refresh token", are you also supplying the app key and secret? Those are required to perform the refresh. Make sure you're doing so, like in the example here.
- jon p4 years agoNew member | Level 2
I can't find any example of how to let the SDK take care of the token refreshing? I need to do this independently of user input.
Do I have to hit this method:
public DropboxClient( string oauth2RefreshToken, string appKey, string appSecret, DropboxClientConfig config )
Do I use the same refresh token every time?
- Greg-DB4 years agoDropbox Staff
jon p Yes, using that method will let the SDK take care of this for you automatically in the background. And yes, you should use the same refresh token for a given user. The refresh token can and should be used repeatedly. It does not expire on its own (though it can be revoked by the user or app).
- jon p4 years agoNew member | Level 2
Thanks for the reply, I'll try it out.
About Discuss Dropbox Developer & API
Make connections with other developers
797 PostsLatest Activity: 2 days 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!