cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done 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

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

Re: Calling DropboxOAuth2Helper.ProcessCodeFlowAsync syncronously

klm1
Helpful | Level 6

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

Re: Calling DropboxOAuth2Helper.ProcessCodeFlowAsync syncronously

Greg-DB
Dropboxer

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

Re: Calling DropboxOAuth2Helper.ProcessCodeFlowAsync syncronously

klm1
Helpful | 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.

Re: Calling DropboxOAuth2Helper.ProcessCodeFlowAsync syncronously

Greg-DB
Dropboxer
Yes, please do share that modified version of SimpleTest so we can reproduce this and look into it. Thanks in advance!

Re: Calling DropboxOAuth2Helper.ProcessCodeFlowAsync syncronously

klm1
Helpful | Level 6

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

Re: Calling DropboxOAuth2Helper.ProcessCodeFlowAsync syncronously

Greg-DB
Dropboxer
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

Re: Calling DropboxOAuth2Helper.ProcessCodeFlowAsync syncronously

klm1
Helpful | Level 6

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

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    klm1 Helpful | Level 6
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?