Look, so far this process is 100% repeatable.
If I have NOTHING in the INI file WRT REFRESH_TOKEN, it works as expected:
INIFILE Section, note REFRESH_TOKEN is NOT in there:
[EMPSecure]
ACCESS_TOKEN=0pfLjfDTbkMKEfa7oXOIz2V2I3UwpFXsxrz6jnkJUQi3ZDLkgIPafMz1AYCDLPyD2grCCr1T9m4YzRJIQrvIdB8APuQkW+mX5c471SSfWGQSjyj93fexZqlfVAU4ldu3TUKpQN6HGxXDLIYre1DJJXv/q2EFUmhq9HDbz0dMbhLAnquychkOrOJmlJ5oZvH
AUTH_TOKEN=j1qw+p9S7zf3d2h7kg9sZMBc0gN4OtRXHZBw3igMeyqQI+SnM9vp6VRxkA
ACCESS_TOKEN_SECRET=
AUTH_TOKEN_SECRET=
EXTRA_DATA=
Note there is NO ENTRY for REFRESHTOKEN.
I run this code:
TMSDropbox.LoadTokens;
showmessage('tokens loaded');
if TMSDropbox.RefreshAccess then
begin
ShowMessage('tokens refreshed');
Result := True;
end
else
begin
ShowMessage('refresh failed');
Result := False;
end;
Exit;
And I get the message 'tokens refreshed' with the INIFILE looking like THIS:
[EMPSecure]
ACCESS_TOKEN=0pfLjfjTa3nGKeffgzOZKuKsw4DNjucPNsN+se/bGc9jzG765HPwoYaP2vEMKDBdtZSA1nbSqkBzmf9Qz+q7n66FZgEuc9g5WC5+uR5PXWHHDZfyX7rdKEmYHAWCdIYKEZvyxXl3lIUjTMkG+uD0nB5ac/biwScZ/LkiVuEBgin2ddN8zMdJESOzBOUJ6VK
AUTH_TOKEN=j1qw+p9S7zf3d2h7kg9sZMBc0gN4kU1wjw/7pw7ItLfb7qLHhC/1MnUXPC
ACCESS_TOKEN_SECRET=
AUTH_TOKEN_SECRET=
EXTRA_DATA=
REFRESH_TOKEN=P5qUUi0CB3a+N1xf+/xwi+5hx3bUfwdwbCxNSPAqDLpmlHZ/nEmjMfVmV75HcUxFYntbqEXz0UFt7EFQxCVwEA
If, however I start with the INI File like this (note the REFRESH_TOKEN=blank) I get the message 'refresh failed' and the INI file is unchanged:
[EMPSecure]
ACCESS_TOKEN=0pfLjfjTa3nGKeffgzOZKuKsw4DNjucPNsN+se/bGc9jzG765HPwoYaP2vEMKDBdtZSA1nbSqkBzmf9Qz+q7n66FZgEuc9g5WC5+uR5PXWHHDZfyX7rdKEmYHAWCdIYKEZvyxXl3lIUjTMkG+uD0nB5ac/biwScZ/LkiVuEBgin2ddN8zMdJESOzBOUJ6VK
AUTH_TOKEN=j1qw+p9S7zf3d2h7kg9sZMBc0gN4kU1wjw/7pw7ItLfb7qLHhC/1MnUXPC
ACCESS_TOKEN_SECRET=
AUTH_TOKEN_SECRET=
REFRESH_TOKEN= <<<<<------THIS DOES NOT GET UPDATED
EXTRA_DATA=
So if the INI file does not contain a reference to REFRESH_TOKEN the code will update it with a refresh token. If it has REFRESH_TOKEN=blank, the refresh token is not updated. For completeness here are the other callbacks:
class procedure TDBEventHandlers.TMSDropboxAccessDenied(Sender: TObject);
begin
WriteLog('DEBUG', 'Enter TMSDropboxAccessDenied');
try
try
WriteLog('ERROR', 'Dropbox authentication failed, Access Denied');
// Authentication failed
Opened := False;
AuthToken := '';
AccessToken := '';
except
on E: Exception do
begin
WriteLog('ERROR', 'TMSDropboxAccessDenied error: ' + E.Message);
end;
end;
finally
WriteLog('DEBUG', 'Exit TMSDropboxAccessDenied');
end;
end;
class procedure TDBEventHandlers.TMSDropboxConnected(Sender: TObject);
var
cs: TCloudStorage;
begin
WriteLog('DEBUG', 'Enter TMSDropboxConnected');
try
try
// Need to save tokens
Opened := True;
if (Sender is TCloudStorage) then
begin
cs := Sender as TCloudStorage;
AuthToken := cs.Token_Auth;
AccessToken := cs.Token_Access;
WriteLog('DEBUG', 'Auth Token: ' + AuthToken);
WriteLog('DEBUG', 'Access Token: ' + AccessToken);
// Save tokens Regardless
cs.SaveTokens;
end
else
raise Exception.Create('Invalid object passed to TMSDropboxConnected');
except
on E: Exception do
begin
WriteLog('ERROR', 'Problem with Dropbox OnConnection: ' + E.Message);
end;
end;
finally
WriteLog('DEBUG', 'Exit TMSDropboxConnected');
end;
end;
class procedure TDBEventHandlers.TMSDropboxReceivedAccessToken(Sender: TObject);
var
cs: TCloudStorage;
begin
WriteLog('DEBUG', 'Enter TMSDropboxReceivedAccessToken');
try
try
// Need to save tokens
Opened := True;
if (Sender is TCloudStorage) then
begin
cs := Sender as TCloudStorage;
AuthToken := cs.Token_Auth;
AccessToken := cs.Token_Access;
WriteLog('DEBUG', 'Auth Token: ' + AuthToken);
WriteLog('DEBUG', 'Access Token: ' + AccessToken);
// Save tokens Regardless
cs.SaveTokens;
end
else
raise Exception.Create('Invalid object passed to TMSDropboxReceivedAccessToken');
except
on E: Exception do
begin
WriteLog('ERROR', 'Problem recieving Access Token: ' + E.Message);
end;
end;
finally
WriteLog('DEBUG', 'Exit TMSDropboxReceivedAccessToken');
end;
end;