EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Dropbox OAuth2 issues

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
#31458
Posted: 11/19/2014 18:03:45
by Alan Reinhold (Priority Standard support level)
Joined: 10/15/2014
Posts: 12

I'm trying to implement the Dropbox system with the latest 12.0.262 version of the client. I found this post (https://eldos.com/forum/read.php?FID=7&TID=5539&MID=31106#message31106) about the new OAuth2 system, and have attempted to implement a working version for this system.

I am using a HTTPListener to handle the callback URL, which is defined as "http://localhost:8081/", and I'm able to get the code from Dropbox in the response. However, when I pass this code back to the CompleteAuthorization2() method, it throws an EEIDropboxDataStorageError "Authorization failed" exception.

Here are the steps that I'm doing.

1.) Start new thread with HTTPListener waiting for request at "http://localhost:8081".
2.) Call Dropbox.StartAuthorization2(@"http://localhost:8081/"). This is the same redirect URL I have registered with Dropbox.
3.) Open url returned from the StartAuthorization2 method in an embedded browser, very similar to current system in Demo application.
4.) After I authorize my application, the browser is redirected to the "http://localhost:8081/".
5.) HttpListener gets the response and extracts the code returned in the URL from the request by the browser.
6.) I then call Dropbox.CompleteAuthorization2(<code>); <-- Throws the exception.


Is there something that I am missing about how this OAuth2 system should be implemented?
#31468
Posted: 11/20/2014 07:16:05
by Alexander Ionov (EldoS Corp.)

Thank you for reporting this.

Your steps are absolutely correct and this should work in the next build we expect this weekend. We've fixed the bug.

Also below is very simple code which connects to Dropbox and gets account info. It uses our TElOAuth2RedirectReceiver class instead of a HTTPLisener.
Code
static void TestDropbox()
{
    TElHTTPSClient transport = new TElHTTPSClient();
    transport.OnCertificateValidate += delegate(object sender, SBX509.TElX509Certificate certificate, ref bool validate)
    {
        validate = true;
    };  

    TElDropboxDataStorage dropbox = new TElDropboxDataStorage();
    dropbox.HTTPClient = transport;

    dropbox.AppKey = "<key>";
    dropbox.AppSecret = "<secret>";

    string redirectUrl = @"http://localhost:5050";

    string authUrl = dropbox.StartAuthorization2(redirectUrl);
    if (!String.IsNullOrEmpty(authUrl))
    {
        SBOAuth2.TElOAuth2RedirectReceiver receiver = new SBOAuth2.TElOAuth2RedirectReceiver();
        receiver.ResponsePage.Text = @"<html><body><center><h1>Response from Dropbox server received</h1>Please close the browser window/tab</center></body></html>";
        receiver.Activate(redirectUrl);

        System.Diagnostics.Process.Start(authUrl);

        while (receiver.Active)
        {
            receiver.Receive();
            System.Threading.Thread.Sleep(100);
        }

        dropbox.CompleteAuthorization2(receiver.AuthorizationCode);
    }

    Console.WriteLine(dropbox.GetAccountInfoStr());
}


--
Best regards,
Alexander Ionov
#32321
Posted: 02/23/2015 16:57:39
by Alan Reinhold (Priority Standard support level)
Joined: 10/15/2014
Posts: 12

Since we are starting the default browser through the System.Diagnostics.Process.Start(string URL) method, we are not guaranteed to be given back a Process object to monitor. How will my code know if the user just closes or navigates away from the Authorization page for dropbox? With the above code, this will wait forever because the receiver.Active will never be false. Infinit loop.
#32324
Posted: 02/24/2015 01:43:34
by Alexander Ionov (EldoS Corp.)

Sorry, this is up to you to decide how to handle this issue. You can try to use a kind of monitoring, or just to add a timeout, or something else.

OAuth2 client requires a authorization code provided in order to exchange it to an access token which will allow the Dropbox data storage component to get user's data from the server.

Unfortunately OAuth is not very suitable to be used in standalone applications because user authorization must be performed in a web browser. We created the TElOAuth2RedirectReceiver component in order to help the developers to get that authorization code in more simple manner. But we cannot provide a source code which can monitor and handle all available web browsers automatically.

Also unfortunately Dropbox does not provide a separate OAuth2 end-point for standalone applications like GDrive and OneDrive do. Also it is not possible to use the embedded WebBrowser control (I don't know why - it just doesn't work for Dropbox) to handle authorization stage with this cloud provider.


--
Best regards,
Alexander Ionov

Reply

Statistics

Topic viewed 1336 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!