Domanda

I am currently looking into adding dropbox to my c# software. I am using spring.social from https://github.com/SpringSource/spring-net-social-dropbox.

I have the following code to do the authentication

private void authenticateDropbox()
        {
            try
            {
                DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(dropboxAppKey, dropboxAppSecret, AccessLevel.AppFolder);
                //lblStatus.Content = "Getting request Token";

                OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result;
                //lblStatus.Content = "Request token retrieved";

                OAuth1Parameters parameters = new OAuth1Parameters();
                string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters);
                //lblStatus.Content = "Redirecting user for authentication";
                Process.Start(authenticateUrl);


            }
            catch (AggregateException ex)
            {
                MessageBox.Show("AggregateException: Failed to authenticate\n\n" + ex.Message, "Authentication Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show("General Exception: Failed to authenticate\n\n" + ex.Message, "Authentication Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

I am successfully loading my default browser and I can allow the app and I get the success page. In the same after it has done the Process.start() method it asks the user to press enter to continue after the success page has been shown, however, I am doing it in a wpf application and I don't really want to have to ask the user to press a button to make my program continue after authorisation from the browser.

I saw in the FetchRequestTokenAsync function there is a callback parameter but I am not sure how to do this or even if this is what I want.

Basically what I want is when the browser says that authorisation was successful it closes the browser and C# picks up that it was successfully authorised and then continues.

Thanks for any help you can provide.

È stato utile?

Soluzione

Process.Start() is used in the Console quick start, but if you are using a WPF application, you should use the WebBrowser control to load the authorization page. Then register to the Navigating event to know when the success callback page is called.

Check the Windows Phone 7 quick start in the zip package, you can easily port it to WPF. https://github.com/SpringSource/spring-net-social-dropbox/tree/master/examples/Spring.WindowsPhoneQuickStart/Spring.WindowsPhoneQuickStart

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top