aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--connection.cpp2
-rw-r--r--connectiondata.cpp6
-rw-r--r--connectiondata.h4
-rw-r--r--jobs/basejob.cpp11
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);