Custom HTML success page fix

This commit is contained in:
Kyle Fowler 2012-04-18 23:48:41 -07:00
parent 51b8c15147
commit f9b09306b9
4 changed files with 28 additions and 16 deletions

View file

@ -21,6 +21,8 @@
#include <QStringList> #include <QStringList>
#include <QUrl> #include <QUrl>
#include <QFile> #include <QFile>
#include <QDir>
#include <QFileInfoList>
#include "kqoauthauthreplyserver.h" #include "kqoauthauthreplyserver.h"
#include "kqoauthauthreplyserver_p.h" #include "kqoauthauthreplyserver_p.h"
@ -49,17 +51,6 @@ void KQOAuthAuthReplyServerPrivate::onBytesReady() {
qDebug() << "Socket peer host address: " << socket->peerAddress(); qDebug() << "Socket peer host address: " << socket->peerAddress();
QByteArray reply; QByteArray reply;
QByteArray content; 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(); QByteArray data = socket->readAll();
qDebug()<< "Query Data: " << data; qDebug()<< "Query Data: " << data;
@ -69,8 +60,21 @@ void KQOAuthAuthReplyServerPrivate::onBytesReady() {
content.append("<HTML><head><script type=\"text/javascript\">var str='http://'+window.location.host + '?' + window.location.hash.substring(1); window.location=str;</script></head><h1>Account authorized, go ahead back to the tumblr app and start your experience!</h1></HTML>"); content.append("<HTML><head><script type=\"text/javascript\">var str='http://'+window.location.host + '?' + window.location.hash.substring(1); window.location=str;</script></head><h1>Account authorized, go ahead back to the tumblr app and start your experience!</h1></HTML>");
} else { } else {
handlingRedirect = false; handlingRedirect = false;
//TODO then send down the local file if there is one QFile file("app/native/assets/" + localFile);
content.append("<HTML><h1>Account linked, go ahead back to the app and check the status!</h1></HTML>"); 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("<HTML><h1>Account linked, go ahead back to the app and check the status!</h1></HTML>");
} else {
content.append(fileData);
}
} }
reply.append("HTTP/1.0 200 OK \r\n"); reply.append("HTTP/1.0 200 OK \r\n");

View file

@ -304,7 +304,6 @@ void KQOAuthManager::executeAuthorizedRequest(KQOAuthRequest *request, int id) {
disconnect(d->networkManager, SIGNAL(finished(QNetworkReply *)), disconnect(d->networkManager, SIGNAL(finished(QNetworkReply *)),
this, SLOT(onRequestReplyReceived(QNetworkReply *))); this, SLOT(onRequestReplyReceived(QNetworkReply *)));
connect(d->networkManager, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), this, SLOT(onSslError(QNetworkReply* reply, const QList<QSslError> &errors)));
connect(d->networkManager, SIGNAL(finished(QNetworkReply *)), connect(d->networkManager, SIGNAL(finished(QNetworkReply *)),
this, SLOT(onAuthorizedRequestReplyReceived(QNetworkReply*)), Qt::UniqueConnection); this, SLOT(onAuthorizedRequestReplyReceived(QNetworkReply*)), Qt::UniqueConnection);
@ -338,6 +337,7 @@ void KQOAuthManager::executeAuthorizedRequest(KQOAuthRequest *request, int id) {
} else { } else {
reply = d->networkManager->post(networkRequest, request->rawData()); reply = d->networkManager->post(networkRequest, request->rawData());
} }
reply->ignoreSslErrors();
d->requestIds.insert(reply, id); d->requestIds.insert(reply, id);
@ -414,7 +414,7 @@ void KQOAuthManager::setSuccessHtmlFile(QString file) {
//////////// Public convenience API ///////////// //////////// Public convenience API /////////////
void KQOAuthManager::getOauth2UserAuthorization(QUrl authorizationEndpoint, QString consumerKey) { void KQOAuthManager::getOauth2UserAuthorization(QUrl authorizationEndpoint, QString consumerKey, const KQOAuthParameters &additionalParams) {
Q_D(KQOAuthManager); Q_D(KQOAuthManager);
d->setupCallbackServer(); d->setupCallbackServer();
@ -427,6 +427,12 @@ void KQOAuthManager::getOauth2UserAuthorization(QUrl authorizationEndpoint, QStr
openWebPageUrl.addQueryItem(OAUTH2_KEY_CLIENT_ID, consumerKey); openWebPageUrl.addQueryItem(OAUTH2_KEY_CLIENT_ID, consumerKey);
openWebPageUrl.addQueryItem(OAUTH2_KEY_RESPONSE_TYPE, "token"); openWebPageUrl.addQueryItem(OAUTH2_KEY_RESPONSE_TYPE, "token");
openWebPageUrl.addQueryItem(OAUTH2_KEY_REDIRECT_URI, serverString); openWebPageUrl.addQueryItem(OAUTH2_KEY_REDIRECT_URI, serverString);
if(additionalParams.size() > 0) {
QList< QPair<QString, QString> > urlParams = d->createQueryParams(additionalParams);
for(int i=0; i < urlParams.length(); i++){
openWebPageUrl.addQueryItem(urlParams[i].first, urlParams[i].second);
}
}
qDebug() << openWebPageUrl.toString(); qDebug() << openWebPageUrl.toString();
navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0); navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0);
} }

View file

@ -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 * 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. * 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 * Sends a request to the protected resources. Parameters for the request are service specific and
* are given to the 'requestParameters' as parameters. * are given to the 'requestParameters' as parameters.

View file

@ -307,6 +307,7 @@ void KQOAuthRequest::initRequest(KQOAuthRequest::RequestType type, const QUrl &r
d->oauthNonce_ = d->oauthNonce(); d->oauthNonce_ = d->oauthNonce();
this->setSignatureMethod(KQOAuthRequest::HMAC_SHA1); this->setSignatureMethod(KQOAuthRequest::HMAC_SHA1);
this->setHttpMethod(KQOAuthRequest::POST); this->setHttpMethod(KQOAuthRequest::POST);
this->setRequestOAuthMethod(KQOAuthRequest::OAUTH1);
d->oauthVersion = "1.0"; // Currently supports only version 1.0 d->oauthVersion = "1.0"; // Currently supports only version 1.0
d->contentType = "application/x-www-form-urlencoded"; d->contentType = "application/x-www-form-urlencoded";