From f9b09306b9795f7b571702e5234765d093b24ea4 Mon Sep 17 00:00:00 2001 From: Kyle Fowler Date: Wed, 18 Apr 2012 23:48:41 -0700 Subject: [PATCH] Custom HTML success page fix --- oauth/kqoauthauthreplyserver.cpp | 30 +++++++++++++++++------------- oauth/kqoauthmanager.cpp | 10 ++++++++-- oauth/kqoauthmanager.h | 3 ++- oauth/kqoauthrequest.cpp | 1 + 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/oauth/kqoauthauthreplyserver.cpp b/oauth/kqoauthauthreplyserver.cpp index d1883d6..faf619d 100644 --- a/oauth/kqoauthauthreplyserver.cpp +++ b/oauth/kqoauthauthreplyserver.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "kqoauthauthreplyserver.h" #include "kqoauthauthreplyserver_p.h" @@ -49,17 +51,6 @@ void KQOAuthAuthReplyServerPrivate::onBytesReady() { qDebug() << "Socket peer host address: " << socket->peerAddress(); QByteArray reply; QByteArray content; - QFile file(localFile); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - - } else { - qDebug() << "first url worked"; - QTextStream in(&file); - while (!in.atEnd()) { - QString line = in.readLine(); - qDebug() << line; - } - } QByteArray data = socket->readAll(); qDebug()<< "Query Data: " << data; @@ -69,8 +60,21 @@ void KQOAuthAuthReplyServerPrivate::onBytesReady() { content.append("

Account authorized, go ahead back to the tumblr app and start your experience!

"); } else { handlingRedirect = false; - //TODO then send down the local file if there is one - content.append("

Account linked, go ahead back to the app and check the status!

"); + QFile file("app/native/assets/" + localFile); + QString fileData; + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug() << "file worked"; + QTextStream in(&file); + while (!in.atEnd()) { + fileData += in.readLine(); + } + file.close(); + } + if(fileData.isEmpty()) { + content.append("

Account linked, go ahead back to the app and check the status!

"); + } else { + content.append(fileData); + } } reply.append("HTTP/1.0 200 OK \r\n"); diff --git a/oauth/kqoauthmanager.cpp b/oauth/kqoauthmanager.cpp index 5f49348..568e89f 100644 --- a/oauth/kqoauthmanager.cpp +++ b/oauth/kqoauthmanager.cpp @@ -304,7 +304,6 @@ void KQOAuthManager::executeAuthorizedRequest(KQOAuthRequest *request, int id) { disconnect(d->networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(onRequestReplyReceived(QNetworkReply *))); - connect(d->networkManager, SIGNAL(sslErrors(QNetworkReply*, const QList&)), this, SLOT(onSslError(QNetworkReply* reply, const QList &errors))); connect(d->networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(onAuthorizedRequestReplyReceived(QNetworkReply*)), Qt::UniqueConnection); @@ -338,6 +337,7 @@ void KQOAuthManager::executeAuthorizedRequest(KQOAuthRequest *request, int id) { } else { reply = d->networkManager->post(networkRequest, request->rawData()); } + reply->ignoreSslErrors(); d->requestIds.insert(reply, id); @@ -414,7 +414,7 @@ void KQOAuthManager::setSuccessHtmlFile(QString file) { //////////// Public convenience API ///////////// -void KQOAuthManager::getOauth2UserAuthorization(QUrl authorizationEndpoint, QString consumerKey) { +void KQOAuthManager::getOauth2UserAuthorization(QUrl authorizationEndpoint, QString consumerKey, const KQOAuthParameters &additionalParams) { Q_D(KQOAuthManager); d->setupCallbackServer(); @@ -427,6 +427,12 @@ void KQOAuthManager::getOauth2UserAuthorization(QUrl authorizationEndpoint, QStr openWebPageUrl.addQueryItem(OAUTH2_KEY_CLIENT_ID, consumerKey); openWebPageUrl.addQueryItem(OAUTH2_KEY_RESPONSE_TYPE, "token"); openWebPageUrl.addQueryItem(OAUTH2_KEY_REDIRECT_URI, serverString); + if(additionalParams.size() > 0) { + QList< QPair > urlParams = d->createQueryParams(additionalParams); + for(int i=0; i < urlParams.length(); i++){ + openWebPageUrl.addQueryItem(urlParams[i].first, urlParams[i].second); + } + } qDebug() << openWebPageUrl.toString(); navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0); } diff --git a/oauth/kqoauthmanager.h b/oauth/kqoauthmanager.h index 514af77..f4a01fb 100644 --- a/oauth/kqoauthmanager.h +++ b/oauth/kqoauthmanager.h @@ -122,8 +122,9 @@ public: /** * This is a method for bypassing all the oauth1 auth process and using the browser based oauth2 flow. This will * launch the browser and set the callback url pointed to a localhost url. Make sure your oauth2 service supports redirect_uri param. + * Add any other params in the additionalParams args like scope or state or any other */ - void getOauth2UserAuthorization(QUrl authorizationEndpoint, QString consumerKey); + void getOauth2UserAuthorization(QUrl authorizationEndpoint, QString consumerKey, const KQOAuthParameters &additionalParams); /** * Sends a request to the protected resources. Parameters for the request are service specific and * are given to the 'requestParameters' as parameters. diff --git a/oauth/kqoauthrequest.cpp b/oauth/kqoauthrequest.cpp index 28f657a..29163f9 100644 --- a/oauth/kqoauthrequest.cpp +++ b/oauth/kqoauthrequest.cpp @@ -307,6 +307,7 @@ void KQOAuthRequest::initRequest(KQOAuthRequest::RequestType type, const QUrl &r d->oauthNonce_ = d->oauthNonce(); this->setSignatureMethod(KQOAuthRequest::HMAC_SHA1); this->setHttpMethod(KQOAuthRequest::POST); + this->setRequestOAuthMethod(KQOAuthRequest::OAUTH1); d->oauthVersion = "1.0"; // Currently supports only version 1.0 d->contentType = "application/x-www-form-urlencoded";