DropNet DropBox login, how to do this programmatically in a console application?

Question:

I am using DropBox csharp API:
https://github.com/dkarzon/DropNet

From unit tests and a single working sample from here https://github.com/dkarzon/DropNet/blob/master/DropNet.Samples/DropNet.Samples.Web/Default.aspx.cs

I realized that it works as follows:

DropNet.DropNetClient client = new DropNet.DropNetClient(strApiKey, strAppSecret); DropNet.Models.UserLogin login = client.GetToken(); client.UserLogin = login; var accountInfo = client.AccountInfo(); str = accountInfo.quota_info.quota.ToString(); 

It probably throws an exception on accountinfo. (System.Net.HttpStatusCode.Unauthorized) Everything before everything works fine, I get a login (usertoken and usersecret).

I think my problem is this part of the sample application:

 var url = _client.BuildAuthorizeUrl(Request.Url.ToString() + "?dropboxcallback=1"); Response.Redirect(url); 

Where does it redirect to Dropbox for login ... I don’t have a web application, so I don’t have a URL ...

I have a console application that should automatically backup my database automatically, as a service, for which it certainly very poorly requires a web browser and a user who must enter an email address / username + password.

How can I make a login by directly supplying a hard-coded username and password?

If I use a sample application, then it works, but it requires entering a username and password on the Internet, and it takes a lot of time for a console application ...

+6
source share
5 answers

Perhaps the use of SharpBox is tested, it works.
You need to get the AccessToken as a one-time action manually, after which you can omit the login page and use the saved AccessToken.

http://www.jayway.com/2012/02/06/unboxing-dropbox-and-sharpbox-2/

Magic line:

 Globals.DropBox.Token = AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxStorageProviderTools .ExchangeDropBoxRequestTokenIntoAccessToken( Globals.DropBox.config , Globals.DropBox.AppKey, Globals.DropBox.AppSec , Globals.DropBox.requestToken ); 
+1
source

As far as I know from another API (facebook, google, stack exchange, etc.), you will have to redirect the user to the Dropbox web page, where he will give you permission to use this account to perform actions.

So it’s generally impossible to achieve this without a web browser . Otherwise, you will have to perform really dirty hacks to crack the dropbox permission system.

Please take a look at the "OAuth 2.0 authorization flow" in google. Here's a diagram I found on Yahoo that shows how it works:

The OAuth 2.0 flow

+6
source

For the uisng DropnetClient 4 argument constructor, we also need to create a web address and allow the user to authenticate his account, this will mean that an accesstoken will be generated after the user clicks the "Allow" button during the authentication process.

+2
source

As GameScripting explained, the Dropbox API uses oauth, which requires user authorization through the Dropbox website to authenticate access tokens.

Check out the documentation here: http://dkdevelopment.net/what-im-doing/dropnet/ for the three-step process.

What application are you building? The usual process is to load the browser control inside the application and go to the login URL with it.

Also look at a sample Windows Phone application to give you an idea of ​​how this process works: https://github.com/dkarzon/DropNet/blob/master/DropNet.Samples/DropNet.Samples.WP7/MainPage.xaml.cs

+1
source

Instead of hard-coding your username and password, you can hardcode the OAuth access token.

First, create a simple program (using the same application key) that follows the standard browser-based authorization flow. Then use it to authorize the application with the desired user. This will give you the OAuth access token (“token” and “token secret”) associated with that user and your application key.

Then, in your service-style application, simply copy the OAuth access token (using the DropNetClient 4-argument constructor).

+1
source

Source: https://habr.com/ru/post/920544/


All Articles