DropBox Authentication question

For testing purposes I've been using the DoAuth() function to get the authorization I need to continue. This brings up a dialog that asks the user to enter their account email, and password every time (and pressing return after the password, does nothing they have to click the authorize button) and then they have to click the button to allow my test application access.

This is all fine for testing, but would be quite annoying to our end users if they have to do this every time they need our program to upload or download files. Once our program is finished and fully registered with DropBox, is there a way to simplify this, so that their authorization can be "saved" somehow so they don't have to enter their credentials repeatedly?

Yes of course. The CloudStorageDemo shows persisting the access tokens to a file and reloading / reusing this for a next communication, avoiding a new authentication this way.

Can I use that same technique even before we've registered our finished app with DropBox?


Is it possible to control if the access tokens are saved to the registry or an .ini file? The documentation mentions both but at least on windows it seems to use the registry automatically, and I don't see any way to change that behavior

Yes, setting under AdvDropBox.PersistTokens.Location

OK I've set it to "plIniFile" but I have no idea where it puts the .ini file. Is that location something I can control?

The INI file is set with DropBox.App.Key, i.e.

DropBox.App.Key := '.\myinifile.ini';

That doesn't make any sense. There are two parts that DropBox gives you to create an app - a Key and a Secret. If I set the Key to a file name/location and it doesn't exist I get:

The request to link the app is invalid.

When I call DoAuth()

I tried manually creating the ini file as well and puting the key value in it like:

Key=<keyvalue> and that didn't work either, resulting in the same error message.

Sure, a typo doesn't make sense

persistence settings obviously are under dropbox.persistence, henc

OK that makes more sense, but I'm still not getting it working. I added the following to my test code:

AdvDropBox1->PersistTokens->Location = plIniFile;
AdvDropBox1->PersistTokens->Key = "C:\Users\<myname>\Desktop\Key.ini";

(where <myname> is replaced with my real name) and it never creates the Key.ini file. As long as the program is open I can do the process again without having to re-enter user ID/password/allow. Once I run the program again (after having exited) I have to login and allow again for the first time.

Do you call SaveTokens / LoadTokens ?

Did you look at the CloudStorage demo ? The demo does exactly that! Store the tokens in an INI file.

Yes of course I'm doing that. Here's my code:

TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
    bAuthorized = false;
    AdvDropBox1->PersistTokens->Location = plIniFile;
    AdvDropBox1->PersistTokens->Key = "C:\\Users\\Public\\Desktop\\Key.ini";
    AdvDropBox1->App->Name = "WorkOrder";
    AdvDropBox1->App->Key = "<redacted>";
    AdvDropBox1->App->Secret = "<redacted>";
    AdvDropBox1->OnReceivedAccessToken = AuthorizationSuccessful;
void __fastcall TForm1::Button1Click(TObject *Sender)
    bAuthorized = false;

    if(AdvDropBox1->App->Key != NULL)
        // load tokens from registry
        // test if the access token is still accepted
        bAuthorized = AdvDropBox1->TestTokens();
        // when not, try to get a new access token with the refresh token
            bAuthorized = AdvDropBox1->RefreshAccess();
        // when no new access token can be obtained, do new authentication
        TCloudItem *CompanyFolder = NULL;
        TDropBoxItem *FolderTest = NULL;
        FolderTest = AdvDropBox1->GetFolderInfo("01");
        if(FolderTest == NULL)
            CompanyFolder = AdvDropBox1->CreateFolder(NULL, "01"); // Root level
            CompanyFolder = FolderTest;
        FolderTest = NULL;
        FolderTest = AdvDropBox1->GetFolderInfo("01/BELMIK");
        if(FolderTest == NULL)
            AdvDropBox1->CreateFolder(CompanyFolder, "BELMIK"); 
            FolderTest = AdvDropBox1->GetFolderInfo("01/BELMIK");
        TDropBoxItem *WorkOrderIn = AdvDropBox1->Upload("01/BELMIK", "C:\\Users\\Public\\Desktop\\001001.in");
        //TDropBoxItem *WorkOrderIn = AdvDropBox1->Upload(FolderTest, "C:\\Users\\Public\\Desktop\\001001.in");
void __fastcall TForm1::AuthorizationSuccessful(TObject *Sender)
    bAuthorized = true;



I'm not sure what is gong wrong in your application, however the demo applications that are included with TMS Cloud Pack demonstrate the usage of saving the tokens to an ini file and are working as expected.
Have you tried running one of the demo applications to see if the ini file is created as expected for you?
If so, please use the same technique as demonstrated in the demo in your own application.