QtDropbox icon indicating copy to clipboard operation
QtDropbox copied to clipboard

403 with HMACSHA1

Open lycis opened this issue 12 years ago • 6 comments

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! issue_9

lycis avatar Jan 24 '13 19:01 lycis

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.

lycis avatar Jan 24 '13 20:01 lycis

How to reproduce the error?

anjinkristou avatar Jan 25 '13 15:01 anjinkristou

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;
}

lycis avatar Jan 26 '13 12:01 lycis

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;
}

anjinkristou avatar Jan 27 '13 06:01 anjinkristou

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();
}

lycis avatar Jan 27 '13 09:01 lycis

Please make for it a test case to find out what is wrong with it.

anjinkristou avatar Feb 10 '13 04:02 anjinkristou