Cannot Serialize DropBoxRequestToken before the user granting access to the API.

May 27, 2013 at 10:22 AM
I'm developing a web application that communicates to the backend (in C#) through webservice. I need to be able to serialize the DropBoxRequestToken, that sharpbox generates, so that I can send it across the UI layer to be able to send it back again (webservice - stateless), once the user has granted access. The CloudStorage.SerializeSecurityTokenToStream needs the token to be authorized(the user should have granted access by then), so that the object can be serialized. I get into a loop here. Hope you know what the problem is?

How do we serialize a DropBoxRequestToken, even before the user granting access to the API.
Jun 23, 2013 at 10:57 PM
You have to perform the following steps (I did them for desktop application, but it have to be the same for web application too):
  1. create DropBoxRequestToken requestToken with your security credentials
        // get the config of dropbox
        DropBoxConfiguration = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox) as DropBoxConfiguration;
    
        // set your own callback which will be called from DropBox after successful // authorization
        DropBoxConfiguration.AuthorizationCallBack = new Uri("my url here");
    
        // create a request token
        DropBoxRequestToken requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(DropBoxConfiguration,
                     " My Consumer Key",
                     "My Consumer Secret");
    
  2. then you authorize your token:
        //generate authorization url
        String AuthorizationUrl = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(DropBoxConfiguration, requestToken);
    
       //here - open authorization url, click "Allow"
    
  3. Then exchange your tokens
      var Token = DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(DropBoxConfiguration, ConsumerKey,
                     ConsumerSecret, requestToken);
    
  4. and then serialize THIS NEW TOKEN:
        //first open CloudStorage (you can do it, since you have a valid token)
        CloudStorage = new CloudStorage();
        StorageToken = CloudStorage.Open(DropBoxConfiguration, Token);
    
        //serialize
        FileStream file = new FileStream(TokenFilePath, FileMode.Create, System.IO.FileAccess.Write);
        CloudStorage.SerializeSecurityTokenToStream(Token, file);
        file.Close();
    
    
Best regards,
Vitaliy
Jun 25, 2013 at 9:13 AM
Hi Vitaliy
I need you little help here
In step 2 you mentioned "2.then you authorize your token: ". So I redirect the user to the AuthorizationUrl in webpage. But then where do i execute step 3 i.e "Then exchange your tokens"? Since I have redirected the user to DropBox site on which page to I exchange tokens?
Jun 25, 2013 at 9:22 AM
Also I will highly appriciate if you could give me a sample asp.net page with the above code and how to exchange tokens
Jun 25, 2013 at 12:13 PM
vitaliyb,
        Your solution will not work for SOA. In SOA approach, the UI will communicate with the backend only thorugh webservice. Request token cannot be serialized unless and until it has been exchanged. In you example, after step 2, I should pass the auth URL and the request token to the client, so that the client can sent the request token back to me after authorization. I dont have a way in webservice to persist local variables (aka request token). Also, in order to send the request token to the  client via werbservice, It SHOULD be serializable. As per sharp box API, serialization is possible only after I authorize. 
However, we came over this issue by converting the request token into a string (even before authorization) by using DotNet Marshall.