diff options
| author | Javier <dev.git@javispedro.com> | 2014-12-08 02:09:07 +0100 |
|---|---|---|
| committer | Javier <dev.git@javispedro.com> | 2014-12-08 02:09:07 +0100 |
| commit | 9c20ff45555cbe74c9afa24fafe5fc0c4ff9e7b8 (patch) | |
| tree | e635d5d3bf78075976dc86fc7c4efa8206bb3a08 /daemon | |
| parent | 35581f3c0e345ecd256b15618aa5fafe23465bef (diff) | |
implement xhr authentication
Diffstat (limited to 'daemon')
| -rw-r--r-- | daemon/jskitobjects.cpp | 23 | ||||
| -rw-r--r-- | daemon/jskitobjects.h | 3 |
2 files changed, 26 insertions, 0 deletions
diff --git a/daemon/jskitobjects.cpp b/daemon/jskitobjects.cpp index 3386f16..5f5acaf 100644 --- a/daemon/jskitobjects.cpp +++ b/daemon/jskitobjects.cpp @@ -1,6 +1,7 @@ #include <QStandardPaths> #include <QDesktopServices> #include <QUrl> +#include <QAuthenticator> #include <QBuffer> #include <QDir> #include <limits> @@ -201,6 +202,8 @@ JSKitXMLHttpRequest::JSKitXMLHttpRequest(JSKitManager *mgr, QObject *parent) _net(new QNetworkAccessManager(this)), _timeout(0), _reply(0) { logger()->debug() << "constructed"; + connect(_net, &QNetworkAccessManager::authenticationRequired, + this, &JSKitXMLHttpRequest::handleAuthenticationRequired); } JSKitXMLHttpRequest::~JSKitXMLHttpRequest() @@ -215,9 +218,13 @@ void JSKitXMLHttpRequest::open(const QString &method, const QString &url, bool a _reply = 0; } + _username = username; + _password = password; _request = QNetworkRequest(QUrl(url)); _verb = method; Q_UNUSED(async); + + logger()->debug() << "opened to URL" << _request.url().toString(); } void JSKitXMLHttpRequest::setRequestHeader(const QString &header, const QString &value) @@ -455,6 +462,22 @@ void JSKitXMLHttpRequest::handleReplyError(QNetworkReply::NetworkError code) } } +void JSKitXMLHttpRequest::handleAuthenticationRequired(QNetworkReply *reply, QAuthenticator *auth) +{ + if (_reply == reply) { + logger()->debug() << "authentication required"; + + if (!_username.isEmpty() || !_password.isEmpty()) { + logger()->debug() << "using provided authorization:" << _username; + + auth->setUser(_username); + auth->setPassword(_password); + } else { + logger()->debug() << "no username or password provided"; + } + } +} + JSKitGeolocation::JSKitGeolocation(JSKitManager *mgr) : QObject(mgr), _mgr(mgr), _source(0), _lastWatchId(0) { diff --git a/daemon/jskitobjects.h b/daemon/jskitobjects.h index b1954c0..23dfabe 100644 --- a/daemon/jskitobjects.h +++ b/daemon/jskitobjects.h @@ -143,12 +143,15 @@ signals: private slots: void handleReplyFinished(); void handleReplyError(QNetworkReply::NetworkError code); + void handleAuthenticationRequired(QNetworkReply *reply, QAuthenticator *auth); private: JSKitManager *_mgr; QNetworkAccessManager *_net; QString _verb; uint _timeout; + QString _username; + QString _password; QNetworkRequest _request; QNetworkReply *_reply; QString _responseType; |
