Custom HTML success page fix
This commit is contained in:
parent
51b8c15147
commit
f9b09306b9
4 changed files with 28 additions and 16 deletions
|
@ -21,6 +21,8 @@
|
|||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QFileInfoList>
|
||||
|
||||
#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("<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 {
|
||||
handlingRedirect = false;
|
||||
//TODO then send down the local file if there is one
|
||||
content.append("<HTML><h1>Account linked, go ahead back to the app and check the status!</h1></HTML>");
|
||||
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("<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");
|
||||
|
|
|
@ -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<QSslError>&)), this, SLOT(onSslError(QNetworkReply* reply, const QList<QSslError> &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<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();
|
||||
navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in a new issue