diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-10-27 21:22:04 +0300 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-10-27 21:22:04 +0300 |
commit | a7f158d1cfdc5c572a62af5a6945e4a6b88e8253 (patch) | |
tree | 8d62fdd9f2fb77d73e9fb70703078b433be28079 | |
parent | 8214e671ec0e0df90f0b7cfa0304f0b6ac99d189 (diff) | |
download | libquotient-a7f158d1cfdc5c572a62af5a6945e4a6b88e8253.tar.gz libquotient-a7f158d1cfdc5c572a62af5a6945e4a6b88e8253.zip |
Put access token to headers instead of query
-rw-r--r-- | connection.cpp | 2 | ||||
-rw-r--r-- | connectiondata.cpp | 6 | ||||
-rw-r--r-- | connectiondata.h | 4 | ||||
-rw-r--r-- | jobs/basejob.cpp | 11 |
4 files changed, 11 insertions, 12 deletions
diff --git a/connection.cpp b/connection.cpp index 427118c9..fdcfa680 100644 --- a/connection.cpp +++ b/connection.cpp @@ -131,7 +131,7 @@ void Connection::connectWithToken(const QString& userId, const QString& accessToken, const QString& deviceId) { d->userId = userId; - d->data->setToken(accessToken); + d->data->setToken(accessToken.toLatin1()); d->data->setDeviceId(deviceId); qCDebug(MAIN) << "Using server" << d->data->baseUrl() << "by user" << userId << "from device" << deviceId; diff --git a/connectiondata.cpp b/connectiondata.cpp index 9b9b6e04..6ef293cd 100644 --- a/connectiondata.cpp +++ b/connectiondata.cpp @@ -33,7 +33,7 @@ QNetworkAccessManager* getNam() struct ConnectionData::Private { QUrl baseUrl; - QString accessToken; + QByteArray accessToken; QString lastEvent; QString deviceId; @@ -52,7 +52,7 @@ ConnectionData::~ConnectionData() delete d; } -QString ConnectionData::accessToken() const +QByteArray ConnectionData::accessToken() const { return d->accessToken; } @@ -67,7 +67,7 @@ QNetworkAccessManager* ConnectionData::nam() const return getNam(); } -void ConnectionData::setToken(QString token) +void ConnectionData::setToken(QByteArray token) { d->accessToken = token; } diff --git a/connectiondata.h b/connectiondata.h index 52a7461c..933219ea 100644 --- a/connectiondata.h +++ b/connectiondata.h @@ -30,12 +30,12 @@ namespace QMatrixClient explicit ConnectionData(QUrl baseUrl); virtual ~ConnectionData(); - QString accessToken() const; + QByteArray accessToken() const; QUrl baseUrl() const; const QString& deviceId() const; QNetworkAccessManager* nam() const; - void setToken( QString accessToken ); + void setToken(QByteArray accessToken); void setHost( QString host ); void setPort( int port ); void setDeviceId(const QString& deviceId); diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp index aa47f63c..20fb68f6 100644 --- a/jobs/basejob.cpp +++ b/jobs/basejob.cpp @@ -82,9 +82,9 @@ inline QDebug operator<<(QDebug dbg, const BaseJob* j) QDebug QMatrixClient::operator<<(QDebug dbg, const BaseJob::Status& s) { - QRegularExpression filter { "(access_token)=[-_A-Za-z0-9]+" }; + QRegularExpression filter { "(access_token)(=|: )[-_A-Za-z0-9]+" }; return dbg << s.code << ':' - << QString(s.message).replace(filter, "\\1=HIDDEN"); + << QString(s.message).replace(filter, "\\1 HIDDEN"); } BaseJob::BaseJob(HttpVerb verb, const QString& name, const QString& endpoint, @@ -138,13 +138,12 @@ void BaseJob::Private::sendRequest() { QUrl url = connection->baseUrl(); url.setPath( url.path() + "/" + apiEndpoint ); - QUrlQuery q = requestQuery; - if (needsToken) - q.addQueryItem("access_token", connection->accessToken()); - url.setQuery(q); + url.setQuery(requestQuery); QNetworkRequest req {url}; req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + req.setRawHeader(QByteArray("Authorization"), + QByteArray("Bearer ") + connection->accessToken()); #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); req.setMaximumRedirectsAllowed(10); |