QtDropbox
QtDropbox copied to clipboard
403 with HMACSHA1
I tried to use HMAC-SHA1 to connect to Dropbox. The connection was created successfuly but any operation always returns this error:
403 "This device's system time is more than 2 months out of date".
Please look into this.
Thanks!
The 403 occured because I had an old token stored. When I deleted the old token I gt:
401 - OAuthError in API v1+: Request mis-signed: Invalid or missing signature.
I get this error on authorisation.
How to reproduce the error?
I get the error as soon as I try to connect. Here's my connect function that keeps getting QDropbox::TokenExpired in the while loop. The debug output indicates:
401 - OAuthError in API v1+: Request mis-signed: Invalid or missing signature.
bool tester::connect()
{
QFile tokenReadFile("token.txt");
if(tokenReadFile.exists())
{
if(tokenReadFile.open(QIODevice::ReadOnly))
{
QTextStream instream(&tokenReadFile);
QString token = instream.readLine().trimmed();
QString secret = instream.readLine().trimmed();
qDebug() << "using token '" << token << "' for connection";
if(!token.isEmpty() && !secret.isEmpty())
{
d.setToken(token);
d.setSharedSecret(secret);
tokenReadFile.close();
return true;
}
tokenReadFile.close();
}
}
if(!d.requestTokenAndWait())
{
qDebug() << "Error on request token: " << d.error();
return false;
}
reauthenticate();
if(!d.requestAccessTokenAndWait())
{
qDebug() << "Error on request access token: " << d.error();
while(d.error() == QDropbox::TokenExpired)
{
reauthenticate();
d.requestAccessTokenAndWait();
}
if(d.error())
return false;
}
// save access token
QFile tokenSaveFile("token.txt");
if(!tokenSaveFile.open(QIODevice::WriteOnly|QIODevice::Truncate))
{
qDebug() << "Could not save token: " << tokenSaveFile.errorString();
return false;
}
QTextStream stream(&tokenSaveFile);
stream << d.token() << "\n";
stream << d.tokenSecret() << "\n";
stream.flush();
tokenSaveFile.close();
return true;
}
Doing the same thing I could not get any error. After the execution of the code I got my tokens in the file as expected. What are you doing special in reauthenticate(). In my case I replaces it with QDesktopServices::openUrl(d.authorizeLink()); and commented the second reauthenticate();
bool MainWindow::testConnection()
{
QDropbox d("Secret1", "Secret2");
QFile tokenReadFile("token.txt");
if(tokenReadFile.exists())
{
if(tokenReadFile.open(QIODevice::ReadOnly))
{
QTextStream instream(&tokenReadFile);
QString token = instream.readLine().trimmed();
QString secret = instream.readLine().trimmed();
qDebug() << "using token '" << token << "' for connection";
if(!token.isEmpty() && !secret.isEmpty())
{
d.setToken(token);
d.setSharedSecret(secret);
tokenReadFile.close();
return true;
}
tokenReadFile.close();
}
}
if(!d.requestTokenAndWait())
{
qDebug() << "Error on request token: " << d.error();
return false;
}
QDesktopServices::openUrl(d.authorizeLink());
if(!d.requestAccessTokenAndWait())
{
qDebug() << "Error on request access token: " << d.error();
while(d.error() == QDropbox::TokenExpired)
{
// QDesktopServices::openUrl(d.authorizeLink());
d.requestAccessTokenAndWait();
}
if(d.error())
return false;
}
// save access token
QFile tokenSaveFile("token.txt");
if(!tokenSaveFile.open(QIODevice::WriteOnly|QIODevice::Truncate))
{
qDebug() << "Could not save token: " << tokenSaveFile.errorString();
return false;
}
QTextStream stream(&tokenSaveFile);
stream << d.token() << "\n";
stream << d.tokenSecret() << "\n";
stream.flush();
tokenSaveFile.close();
return true;
}
That's what happens in reauthenticate():
void tester::reauthenticate()
{
qDebug() << "reauth" << endl;
qDebug() << "please authorize" << QDesktopServices::openUrl(d.authorizeLink()) << endl;
waitForUserAction();
}
void tester::waitForUserAction()
{
QTextStream stream(stdin, QIODevice::ReadOnly);
QString str = stream.readLine();
}
Please make for it a test case to find out what is wrong with it.