From c3fc131c22427bf742a72239f315587300556a6d Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Wed, 10 Aug 2016 07:24:29 -0700 Subject: [PATCH] updated for dropbpox support, need to rework these commits though --- oauth/kqoauthmanager.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/oauth/kqoauthmanager.cpp b/oauth/kqoauthmanager.cpp index 44f4379..4a678ff 100644 --- a/oauth/kqoauthmanager.cpp +++ b/oauth/kqoauthmanager.cpp @@ -305,6 +305,12 @@ void KQOAuthManager::executeAuthorizedRequest(KQOAuthRequest *request, int id) { networkRequest.setRawHeader("Authorization", authHeader); } + if(request->oauthMethod() == KQOAuthRequest::OAUTH2) { + QByteArray bearer; + bearer.append(request->additionalParameters().value("oauth_token")); + networkRequest.setRawHeader("Authorization", "Bearer " + bearer); + qDebug() << networkRequest.rawHeader("Authorization"); + } disconnect(d->networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(onRequestReplyReceived(QNetworkReply *))); @@ -312,8 +318,14 @@ void KQOAuthManager::executeAuthorizedRequest(KQOAuthRequest *request, int id) { this, SLOT(onAuthorizedRequestReplyReceived(QNetworkReply*)), Qt::UniqueConnection); if (request->httpMethod() == KQOAuthRequest::GET) { + // Pull the oauth_token parameter because Dropbox + KQOAuthParameters adtlparams = request->additionalParameters(); + adtlparams.remove("oauth_token"); + qDebug() << adtlparams; + // Get the requested additional params as a list of pairs we can give QUrl - QList< QPair > urlParams = d->createQueryParams(request->additionalParameters()); + // QList< QPair > urlParams = d->createQueryParams(request->additionalParameters()); + QList< QPair > urlParams = d->createQueryParams(adtlparams); // Take the original URL and append the query params to it. QUrl urlWithParams = networkRequest.url(); @@ -324,6 +336,9 @@ void KQOAuthManager::executeAuthorizedRequest(KQOAuthRequest *request, int id) { // Submit the request including the params. QNetworkReply *reply = d->networkManager->get(networkRequest); reply->ignoreSslErrors(); + + d->requestIds.insert(reply, id); + connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError))); @@ -331,6 +346,10 @@ void KQOAuthManager::executeAuthorizedRequest(KQOAuthRequest *request, int id) { networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, request->contentType()); + QByteArray argHeader; + argHeader.append(request->additionalParameters().value("arg")); + networkRequest.setRawHeader("Dropbox-API-Arg", argHeader); + qDebug() << networkRequest.rawHeaderList(); qDebug() << networkRequest.rawHeader("Authorization"); qDebug() << networkRequest.rawHeader("Content-Type"); @@ -614,6 +633,7 @@ void KQOAuthManager::onAuthorizedRequestReplyReceived( QNetworkReply *reply ) { Q_D(KQOAuthManager); QNetworkReply::NetworkError networkError = reply->error(); + qDebug() << networkError; switch (networkError) { case QNetworkReply::NoError: d->error = KQOAuthManager::NoError; @@ -636,6 +656,7 @@ void KQOAuthManager::onAuthorizedRequestReplyReceived( QNetworkReply *reply ) { // Read the content of the reply from the network. QByteArray networkReply = reply->readAll(); + qDebug() << networkReply; // Stop any timer we have set on the request. d->r->requestTimerStop(); @@ -649,6 +670,7 @@ void KQOAuthManager::onAuthorizedRequestReplyReceived( QNetworkReply *reply ) { // We need to emit the signal even if we got an error. if (d->error != KQOAuthManager::NoError) { qWarning() << "Network reply error"; + qDebug() << d->error; return; }