updated for dropbpox support, need to rework these commits though

This commit is contained in:
Morgan McMillian 2016-08-10 07:24:29 -07:00
parent c8d1a2d66c
commit c3fc131c22

View file

@ -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<QString, QString> > urlParams = d->createQueryParams(request->additionalParameters());
// QList< QPair<QString, QString> > urlParams = d->createQueryParams(request->additionalParameters());
QList< QPair<QString, QString> > 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;
}