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
klm1
8 years agoHelpful | Level 6
Calling DropboxOAuth2Helper.ProcessCodeFlowAsync synchronously
From the OAuth guide:
"Note that for certain apps, such as command line and desktop apps, it's not possible for a web browser to redirect back to your app. In these cases, your app does not need to include a redirect_uri parameter. Dropbox will present the user with an authorization code that they will need to copy and paste into your app, at which point your app can exchange it for a reusable access token."
In the situation mentioned above, it appears that the authorization code provided on the Dropbox web page would need to be converted to an access token using (on .NET) DropboxOAuth2Helper.ProcessCodeFlowAsync(). But what if that function needs to be called synchronously? This does not seem to work as task.Wait() never returns:
var task = DropboxOAuth2Helper.ProcessCodeFlowAsync(authorizationCode, appKey, appSecret); task.Wait();
Any alternatives for handling the case where browser redirection isn't possible and the access token needs to be aquired synchronously?
For anyone reading this topic, the good folks at Dropbox were able to identify the problem and fix it in version 4.2.5 of the SDK.
- Greg-DBDropbox Staff
That code seems to work for me. Can you elaborate on how you're using it and how you're checking that it never returns?
Alternatively, would await work in your scenario?
await DropboxOAuth2Helper.ProcessCodeFlowAsync(authorizationCode, appKey, appSecret);
- klm1Helpful | Level 6
Hey Greg,
Normally (for asynchronous), you'd do something like this (basically changing the SimpleTest sample to allow inputing the authorization code into a text field, then converting that to an access token:
private async void OkClick(object sender, RoutedEventArgs e) { if (this.authorizationCode.Text == String.Empty) this.Close(); OAuth2Response response = await DropboxOAuth2Helper.ProcessCodeFlowAsync(authorizationCode.Text, appKey, appSecret); this.AccessToken = response.AccessToken; this.Uid = response.Uid; this.Result = true; this.Close(); }
That works fine and is ok as long as the function, OkClick in this simple example, can can be called asynchronously. (In our real use case, C++/CLI is the caller, and it doesn't know anything about async / await).
I tried doing this instead, which seems to work for most of the Dropbox .NET API calls (note the async and await are gone, but we wait for the task to complete using task.Wait() ):private void OkClick(object sender, RoutedEventArgs e) { if (this.authorizationCode.Text == String.Empty) this.Close(); var task = DropboxOAuth2Helper.ProcessCodeFlowAsync(authorizationCode.Text, appKey, appSecret); task.Wait(); this.AccessToken = task.Result.AccessToken; this.Uid = task.Result.Uid; this.Result = true; this.Close(); }
If I step through the code, I never see the line executed after task.Wait(). Am happy to send you the source too, it's basically just a modified version of SimpleTest.
- Greg-DBDropbox StaffYes, please do share that modified version of SimpleTest so we can reproduce this and look into it. Thanks in advance!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,882 PostsLatest Activity: 5 hours 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!