cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

Calling DropboxOAuth2Helper.ProcessCodeFlowAsync synchronously

Calling DropboxOAuth2Helper.ProcessCodeFlowAsync synchronously

klm1
Helpful | Level 6
Go to solution

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?

 

1 Accepted Solution

Accepted Solutions

klm1
Helpful | Level 6
Go to solution

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.

View solution in original post

6 Replies 6

Greg-DB
Dropbox Staff
Go to solution

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);

klm1
Helpful | Level 6
Go to solution

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-DB
Dropbox Staff
Go to solution
Yes, please do share that modified version of SimpleTest so we can reproduce this and look into it. Thanks in advance!

klm1
Helpful | Level 6
Go to solution

What's the best way to make the files available to you, Greg?

Greg-DB
Dropbox Staff
Go to solution
You can post a Dropbox shared link for the project:

https://www.dropbox.com/help/167

If you'd prefer to share privately, you can open an API ticket here instead:

https://www.dropbox.com/developers/contact

klm1
Helpful | Level 6
Go to solution

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.

Need more support?
Who's talking

Top contributors to this post

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