DropBox Authorization: How to upgrade request token

Mar 26, 2012 at 5:23 PM
Edited Mar 26, 2012 at 5:34 PM

Hi I am trying to use a web application to authenticate with DropBox.

I am able to: 1) obatin request token using app key and app secret, 2) obtain authentication URL and redirect with callback.

However, I am unable to upgrade request token to access token. I received the unauthorized exception. I noticed that i receive 2 patrameters with the callback URL. For what do I use these?

 

// enter the comsumer key and secret
        String ConsumerKey = "********";
        String ComsumerSecret = "********";

        // 0. load the config
        DropBoxConfiguration config = DropBoxConfiguration.GetStandardConfiguration();
        config.AuthorizationCallBack = new Uri("http://google.com");
        // 1. get the request token from dropbox
        DropBoxRequestToken requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, ConsumerKey, ComsumerSecret);

        // 2. build the authorization url based on request token                        
        String url = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(config, requestToken);
        

        // 3. Redirect the user to the website of dropbox
        // ---> DO IT <--
        System.Diagnostics.Process.Start(url);
        // ---> if not, you will get an unauthorized exception <--
        // 
        //
        // 4. Exchange the request token into access token
        ICloudStorageAccessToken accessToken = DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(config, ConsumerKey, ComsumerSecret, requestToken);
        //Stream xmlStream = File.Create(@"C:\test.txt");        

        // 5. Opent the storage with the generated access token            
        CloudStorage storageNew = new CloudStorage();
        storageNew.Open(config, accessToken);

 Thanks,

Mike

Mar 28, 2012 at 4:16 PM

Hi Mike,

The parameters you get back from callback are:

  • oauth_token - The request token that was just authorized. The request token secret isn't sent back.
  • uid - The user's unique Dropbox ID.

See  https://www.dropbox.com/developers/reference/api for more information on this.

I would just double check that the oauth_token coming back is the same as the request token you are using to exchange into an access token. From looking at your code it does appear to be correct though.

May 18, 2012 at 7:27 PM

Hi Mike,

Be sure to save the RequestToken (perhaps in the session) so you can use the same token you received from dropbox directly before you sent the user to the AuthorizationUrl.

            //GET REQUEST TOKEN FROM DROPBOX
            requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, APP_KEY, APP_SECRET);

            //Save token to Session
            Session["requestToken"] = requestToken;
Good Luck!