pipacs / o2

OAuth 2.0 for Qt
BSD 2-Clause "Simplified" License
317 stars 147 forks source link

GET Method return ERROR: "Host requires authentication" code : 32 Could not authenticate you #30

Closed tedr56 closed 6 years ago

tedr56 commented 9 years ago

I discovered lately all the OAuth process and for POST method, your great lib worked just fine.

Until I tried to use Oembed from Twitter using the GET method.

I've seen the issue #19 which use setToken and setTokenSecret. I wonder how since these methods are protected.

For my part, it's nothing fancy, I just try this

    O1Requestor* requestor = new O1Requestor(manager, o1, this);
    QList<O1RequestParameter> reqParams = QList<O1RequestParameter>();
    QUrl url = QUrl(QString("https://api.twitter.com/1.1/statuses/oembed.json?id=" + tweet_id));
    QNetworkRequest request(url);
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    QNetworkReply *replyEmbed = requestor->get(request, reqParams);
    connect(replyEmbed, SIGNAL(finished()), this, SLOT(addTweet()));

with

    o1 = new O1Twitter(this);
    o1->setClientId("shshshshshshshsh");
    o1->setClientSecret("shshshshshshshshshshshshshshshshshshshshshshshsh");

and successfully linked.

No matter what, I always get in response

ERROR: "Host requires authentication"
content: "{"errors":[{"code":32,"message":"Could not authenticate you."}]}"

I tried to qDebug the authParams, but it seems quite the same as the Twitter Oauth Generator

Any help would be really appreciated. Thanks.

Timac commented 6 years ago

I encountered the exact same issue as described here. After some debugging I found that I need to have the parameters in the URL as well as in the list of O1RequestParameter.

I think that in your case, you would need to write:

O1Requestor* requestor = new O1Requestor(manager, o1, this);
QByteArray idName("id");
QList<O1RequestParameter> reqParams = QList<O1RequestParameter>();
reqParams << O0RequestParameter(idName, tweet_id.toLatin1());
QUrl url = QUrl(QString("https://api.twitter.com/1.1/statuses/oembed.json?id=" + tweet_id));
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QNetworkReply *replyEmbed = requestor->get(request, reqParams);
connect(replyEmbed, SIGNAL(finished()), this, SLOT(addTweet()));
pipacs commented 6 years ago

Thanks for the update. Indeed in OAuth 1.0, query parameters, too, should participate in the request signing.