EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Dropbox sample doesn't connect

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#30974
Posted: 10/13/2014 13:35:21
by Alexander Ionov (EldoS Corp.)

Yes, you will be able to pass your own redirect URL to the StartAuthorization2 method of the Dropbox access component. This method is used to start a OAuth 2.0 protocol session. This method returns the URL you should use to let your user to login in his/her browser. Then you should receive a "code" from the Dropbox server at the specified endpoint and pass that "code" to the CompleteAuthorization2 method. After this you'll get an access token as a value of the AccessToken property. You can save it and restore later. If you restore a previously saved access token, you have to call the StartAuthorization2 method anyway (value of the parameter is not used this time), but in this case the method returns empty string and you don't need to call the CompleteAuthorization2 method.


--
Best regards,
Alexander Ionov
#30985
Posted: 10/14/2014 08:37:43
by ntr1 (Standard support level)
Joined: 02/05/2014
Posts: 71

Hi,

I'm glad to know your Dropbox component will support saving of the access token, avoiding to make browser authorization every time.

I hope there will be a fully working sample in the sample applications like for Google Drive and OneDrive!

Can I know when the new release will be available?

Thank you
#31105
Posted: 10/24/2014 10:23:44
by ntr1 (Standard support level)
Joined: 02/05/2014
Posts: 71

Hello,

I'm trying what you told me using the latest Cloudblackbox version, but I have some difficulties.

Can you please post a working sample of the process you described? Therefore, how to save the accesstoken the first time and how to reuse it.

Thank you

Regards
#31106
Posted: 10/26/2014 11:03:02
by Alexander Ionov (EldoS Corp.)

We didn't change our sample to use OAuth 2.0 for Dropbox because we couldn't make the embedded browser control to work correctly. So I can only describe in details how to use the methods. So the steps are:

0. If you have a saved access token, you should retore it to the AccessToken property

1. Call the StartAuthorization2:
Code
URL := Dropbox.StartAuthorization2(YourListeningEndpoint)

If you don't have a saved access token, the YourListeningEndpoint variable MUST have a URL registered on the Dropbox App Console for redirection. If you restored an access token, value of YourListeningEndpoint is not used.

2a. If you receive an empty URL from the StartAuthorization2 method, this means that your restored access token is applied to the HTTPS client and you are ready to send requests to the Dropbox server. In order to check if the restored access token is still valid and not expired, you can call for example the GetAccountInfo method. If you get an exception, the restored access token seems to be expired. In this case you have to clear the AccessToken property and get back to step 1 starting a new OAuth 2 session. If you succeeded to get an account info, your access token is still valid and you can go to step 5.

2b. If you receive a non-empty URL from the StartAuthorization2 method, you have to use this URL to navigate an external or an embedded browser to this URL in order to let the user to login on the Dropbox website.
To use a default browser, you can use the following line:
Code
ShellExecute(0, 'open', PWideChar(URL), nil, nil, SW_SHOW);


3. At the endpoint you've specified at step 1, you should receive a CODE string from the Dropbox server. It will be provided as a URL parameter like "YourListeningEndpoint?code=..."
When you get this CODE, you have to pass the value to the CompleteAuthorization2 method. If an error occurs during establishing a OAuth 2 session, an exception is raised.

4. Now you have a new valid token value in the AccessToken property which you can save for further usage.

5. Call data storage methods to operate with data objects.


--
Best regards,
Alexander Ionov
#31114
Posted: 10/27/2014 04:30:25
by ntr1 (Standard support level)
Joined: 02/05/2014
Posts: 71

Hello Alexander,

and thank you so much for the time you spent for this tutorial.

Making some tests, I noticed a very interesting (an NEW?) thing on Dropbox API console:

You can generate an Access Token directly from the console (for a created app) and use it to authorize the program without any browser!

(please see the attached image)

I could not believe I can get rid of the annoying browser authentication!

Here is the simple code I used now:

Dropbox.AccessToken := 'sdgsdjnsdjh2346782873YHEWJ733';
URL := Dropbox.StartAuthorization2('http://myurl');
LoadAccountInfo();


And it works! No browser authentication! Can you please check it and confirm this method will be the best one?

Thank you again!


#31115
Posted: 10/27/2014 04:46:35
by Alexander Ionov (EldoS Corp.)

Yes, we did use this generated access token for testing. But we have no information how long such generated access token is valid.
Unfortunatelly we don't know what goal you attempt to reach with your application. So we cannot confirm if this is the best method for authorization. As far as I understand the generated access token can be used to access only YOUR Dropbox account. If you don't need to access other accounts, probably the usage of the generated access token is the best way for you.


--
Best regards,
Alexander Ionov
#31116
Posted: 10/27/2014 04:55:10
by ntr1 (Standard support level)
Joined: 02/05/2014
Posts: 71

And it seems exactly the same method can be used with Google Drive:

URL := GoogleDrive.StartAuthorization();
GoogleDrive.RefreshToken := 'HJSHSjudns734562jDhdsmkswd-swdhw';
LoadRoot();

It works perfectly, and I successfully uploaded files.

(see the attached image)

Now I have to check if OneDrive can be accessed with this direct method without web browser.


#31117
Posted: 10/27/2014 05:02:09
by Alexander Ionov (EldoS Corp.)

Yep, Google Drive supports refresh token, so each time you call the StartAuthorization method, it connects to the authorization server and uses the restored RefreshToken to get a new access token for the current session.

AFAIR, OneDrive also supports refresh token, so you should be able to use it the same way as you use Google Drive.


--
Best regards,
Alexander Ionov
#31137
Posted: 10/28/2014 09:49:24
by ntr1 (Standard support level)
Joined: 02/05/2014
Posts: 71

Hi Alexander,

making some other tests, I noticed I made a little mistake in the Google Drive test. In fact, it doesn't work if you previously didn't save an access token.

So Google Drive works in a different way.
I tried to set a value for the AccessToken property directly, but it's readonly (while in Dropbox component I can set it).

Can you please check if there is a way to pass to the component the API KEY (Public Key Access) that can be generated for Google Drive ? It would solve the problem to request a browser authentication.
#31138
Posted: 10/28/2014 10:15:05
by Alexander Ionov (EldoS Corp.)

No, Public API access key cannot be used in the TElGoogleDriveDataStorage component to access Google Drive. Only OAuth 2.0 protocol is available to get access to Google Drive.


--
Best regards,
Alexander Ionov
Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.

Reply

Statistics

Topic viewed 2438 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!