Deropbox ini File Not Saving Credential OAUTH2

I have contacted Support Directly, so far no reply.

IDE: Delphi XE7

OS: Windows 10
COMPONENT: TMS Cloud Studio
QUESTION:
Btuno (or whoever is monitoring support),

We recently upgraded to V3.8.1 because of the need for OAUTH2. The Authorisation now works fine with our existing code, but saving to the ini file does NOT work correctly and hence TestTokens continues to fail.  Here is what was saved (Component v2.9 IIRC):

[DbXSecure]   (OAUTH1)
ACCESS_TOKEN=00Y9Sq9ZXtnCIC+AoFTshA
AUTH_TOKEN=EJrQsCSUJ5jzgn1cP/p41A
ACCESS_TOKEN_SECRET=28KTIW66NOSmjafd+dkB
AUTH_TOKEN_SECRET=QddIrsXljmjnn+ggcLpo9C
REFRESH_TOKEN=
EXTRA_DATA=

Now what is saved is this (which obviously FAILS TestTokens):

[DbXSecure]       (OAUTH2)
ACCESS_TOKEN=
AUTH_TOKEN=j1qw+p9S7zf3d2h7kg9sZMBcxYlpJlqmiBVSuOqPBXijBhke9V714oetFC
ACCESS_TOKEN_SECRET=
AUTH_TOKEN_SECRET=
REFRESH_TOKEN=
EXTRA_DATA=

I have not changed the code, see below. We do a logical TestTokens, RefershTokens, DoAuth then a TestTokens (which fails) to ensure the ini file is updated. 

This is in a DLL which is why I don"t use TMSDropbox.Connect, perhaps I should, one of the issues with .Connect is how do you detect when it has FAILED, you get a method called when it succeeds, but what happens if it fails - ANY IDEAS there?. 

Can you see any reason why updating the ini file is failing?

      TMSDropbox.LoadTokens;
      acc := TMSDropbox.TestTokens;
      try
        if acc then
        begin
          // We are authorized already with the Tokens we have
          Opened := True;
          WriteLog("INFO ", "Dropbox already authorised");
        end
        else
        begin
          // Try and refresh the tokens without having to authorize
          WriteLog("INFO ", "Token loading unsuccessful, trying refresh");
          if TMSDropbox.RefreshAccess then
          begin
            Opened := False;
            TMSDropbox.SaveTokens;
          end
          else
          begin
            // Nope we need to authorize
            WriteLog("INFO ", "Dropbox needs to be authorised");
            Opened := False;
            TMSDropbox.DoAuth;
            WriteLog("INFO ", "Authorisation completed, saving tokens");
            TMSDropbox.SaveTokens;
            WriteLog("INFO ", "Tokens saved");
          end;
        end;

Hi,


If you call SaveTokens directly after the DoAuth call it
is possible that the tokens haven't been retrieved yet.<o:p></o:p>

Please use the OnReceivedAccessToken event to call SaveTokens.

 Example:

procedure TForm1.AdvDropBox1ReceivedAccessToken(Sender: TObject);
begin
  AdvDropBox1.SaveTokens;
end;

Bart Holvoet2017-10-05 09:29:04

Hi Bart,


Firstly I should have said that the Dropbox Signin is in a DLL.

Having said that, the code worked with OAUTH1. Regardless, I am guessing I should be using the TMSDropbox.Connect (which is supposedly boolean), but I have issues with that in that it ALWAYS returns FALSE (see my other post).

QUESTION: If I can get the AdvDropBox1ReceivedAccessToken procedure working, what happens if the call to DoAuth FAILS. I am waiting for an event that will never get triggered and/or if the event is triggered there is no parameter passed that determines the success or failure of the DoAuth command. In the past I used to repeat the TestTokens after the DoAuth to see whether it had succeeded. Is that what should be in AdvDropBox1ReceivedAccessToken:

EXAMPLE:

procedure TForm1.AdvDropBox1ReceivedAccessToken(Sender: TObject);
begin
  if AdvDropbox1.TestTokens then
  begin
    Opened := True;
    AdvDropBox1.SaveTokens;    // Success
    WriteLog ('INFO ', 'Dropbox Authorised');
  end
  else
  begin
    Opened := False;
    WriteLog('ERROR', 'Dropbox Authorisation Failed');
  end;

Same issue as with the OnConnected, the OnReceivedAccessToken event does not get triggered even though I go through the entering of email/password and press allow and this appears to work (ie. there is no error from Dropbox). 


Since I am chasing two potential defects here concurrently, I think I should concentrate on one of them (neither are triggering the appropriate event). 

I ASSUME that the better way to do things is with the TMSDropbox.Connect call rather than a LOADTOKENS, REFRESHTOKENS, DOAUTH. With the TMSDropbox.Connect according to the documentation it wraps up the logic of trying to connect and triggers the ONCONNECTED event.

So I will try and resolve that issue. If I cannot I will come back to this one. Either way, the problem in my DLL is that neither the ONCONNECTED or the ONRECEIVEDACCESSTOKEN events are being triggered. Please see the other post for how I setup the EVENTS. 
- DoAuth technique
If the authentication worked the OnReceivedAccessToken even is triggered, if not the OnAccessDenied event is triggered.

- Connect technique
You should be able to determine from the boolean result if the authentication worked or not.
Then use the OnConnected event to call SaveTokens.

I would recommend to first start testing with the CloudStorageDemo application which should be working as expected. Then move to your own application running as a standalone application then switch to the DLL version to be able to find out where and when the saving stops working.

Bart Holvoet2017-10-05 09:38:28

Hi Bart,


- Connect technique
You should be able to determine from the boolean result if the authentication worked or not.
Then use the OnConnected event to call SaveTokens.

That's how I thought it should work, but as noted this is not working, when it does work there will be an issue. I believe now with Dropbox and Google signin, you must use the external browser for Dropbox to set application into production status. When I use an external browser with TMSDropbox.Connect - the code carries on (ie. returns boolean FALSE)  before I have time to enter the Dropbox login details into the browser screen.  In the past I have seen code where a dialog was popped saying press OK when you have authorised Dropbox.

This is both inelegant and will not work with a construct like TMSDropbox.Connect?

I am now working on the DropboxCloudStorageDemo, see other post for logging info. Initial advice: it is authenticating, but NOTHING is being displayed on the screen.

I have retested this here once more with our CloudStorageDemo. I have also set in this demo AdvDropBox1.ExternalBrowser = true.  In our demo, I cannot see any problem. When pressing Connect the default browser shows on the DropBox page asking for permission. After giving this permission by pressing "Allow", the treeview fills with the files retrieved from the Dropbox service.
The DropboxCloudStorageDemo is a demo for a data storage service from Dropbox that is deprecated and is not relevant for dealing with file storage on Dropbox. So, please use the CloudStorageDemo and select the Dropbox service in the radiogroup.


Hi Bruno,


As far as the CloudStorageDemo goes, that works fine. It is when I instantiate the component in a DLL that it does not work as expected. 

This is the same Issue as my other post: TMSDropbox.Connect Fails

It is the same thing, since the change from OAUTH1 (which worked in my DLL) to AOUTH2 , the component works as expected when used with a form, but if instantiated in a DLL it does not function as expected. 

So rather than chasing two posts, can we close this one and follow the other: TMSDropbox.Connect Fails