diff --git a/external/o2/src/o2.cpp b/external/o2/src/o2.cpp index 0b11b60a0811..f5939587d5dd 100644 --- a/external/o2/src/o2.cpp +++ b/external/o2/src/o2.cpp @@ -219,7 +219,7 @@ void O2::link() { QUrl url(tokenUrl_); QNetworkRequest tokenRequest(url); tokenRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); - QNetworkReply *tokenReply = manager_->post(tokenRequest, payload); + QNetworkReply *tokenReply = getManager()->post(tokenRequest, payload); connect(tokenReply, SIGNAL(finished()), this, SLOT(onTokenReplyFinished()), Qt::QueuedConnection); connect(tokenReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onTokenReplyError(QNetworkReply::NetworkError)), Qt::QueuedConnection); @@ -268,7 +268,7 @@ void O2::onVerificationReceived(const QMap response) { qDebug() << QString("O2::onVerificationReceived: Exchange access code data:\n%1").arg(QString(data)); - QNetworkReply *tokenReply = manager_->post(tokenRequest, data); + QNetworkReply *tokenReply = getManager()->post(tokenRequest, data); timedReplies_.add(tokenReply); connect(tokenReply, SIGNAL(finished()), this, SLOT(onTokenReplyFinished()), Qt::QueuedConnection); connect(tokenReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onTokenReplyError(QNetworkReply::NetworkError)), Qt::QueuedConnection); @@ -390,6 +390,11 @@ void O2::setExpires(int v) { store_->setValue(key, QString::number(v)); } +QNetworkAccessManager *O2::getManager() +{ + return manager_; +} + QString O2::refreshToken() { QString key = QString(O2_KEY_REFRESH_TOKEN).arg(clientId_); return store_->value(key); @@ -424,7 +429,7 @@ void O2::refresh() { parameters.insert(O2_OAUTH2_GRANT_TYPE, O2_OAUTH2_REFRESH_TOKEN); QByteArray data = buildRequestBody(parameters); - QNetworkReply *refreshReply = manager_->post(refreshRequest, data); + QNetworkReply *refreshReply = getManager()->post(refreshRequest, data); timedReplies_.add(refreshReply); connect(refreshReply, SIGNAL(finished()), this, SLOT(onRefreshFinished()), Qt::QueuedConnection); connect(refreshReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onRefreshError(QNetworkReply::NetworkError)), Qt::QueuedConnection); diff --git a/external/o2/src/o2.h b/external/o2/src/o2.h index c350e1506cad..c09eab592806 100644 --- a/external/o2/src/o2.h +++ b/external/o2/src/o2.h @@ -161,6 +161,8 @@ protected Q_SLOTS: /// Set token expiration time. void setExpires(int v); + virtual QNetworkAccessManager *getManager(); + protected: QString username_; QString password_; diff --git a/src/auth/oauth2/qgso2.cpp b/src/auth/oauth2/qgso2.cpp index 2b2fde4dd2bc..d4ce2a18f4e2 100644 --- a/src/auth/oauth2/qgso2.cpp +++ b/src/auth/oauth2/qgso2.cpp @@ -231,7 +231,7 @@ void QgsO2::link() QUrl url( tokenUrl_ ); QNetworkRequest tokenRequest( url ); tokenRequest.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1Literal( "application/x-www-form-urlencoded" ) ); - QNetworkReply *tokenReply = manager_->post( tokenRequest, payload ); + QNetworkReply *tokenReply = getManager()->post( tokenRequest, payload ); connect( tokenReply, SIGNAL( finished() ), this, SLOT( onTokenReplyFinished() ), Qt::QueuedConnection ); connect( tokenReply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( onTokenReplyError( QNetworkReply::NetworkError ) ), Qt::QueuedConnection ); @@ -299,7 +299,7 @@ void QgsO2::onVerificationReceived( QMap response ) parameters.insert( O2_OAUTH2_REDIRECT_URI, redirectUri_ ); parameters.insert( O2_OAUTH2_GRANT_TYPE, O2_AUTHORIZATION_CODE ); QByteArray data = buildRequestBody( parameters ); - QNetworkReply *tokenReply = manager_->post( tokenRequest, data ); + QNetworkReply *tokenReply = getManager()->post( tokenRequest, data ); timedReplies_.add( tokenReply ); connect( tokenReply, &QNetworkReply::finished, this, &QgsO2::onTokenReplyFinished, Qt::QueuedConnection ); connect( tokenReply, qgis::overload::of( &QNetworkReply::error ), this, &QgsO2::onTokenReplyError, Qt::QueuedConnection ); @@ -336,3 +336,8 @@ void QgsO2::onVerificationReceived( QMap response ) setRefreshToken( response.value( O2_OAUTH2_REFRESH_TOKEN ) ); } } + +QNetworkAccessManager *QgsO2::getManager() +{ + return QgsNetworkAccessManager::instance(); +} diff --git a/src/auth/oauth2/qgso2.h b/src/auth/oauth2/qgso2.h index 683bb0441922..834dcce7529f 100644 --- a/src/auth/oauth2/qgso2.h +++ b/src/auth/oauth2/qgso2.h @@ -74,6 +74,10 @@ class QgsO2: public O2 //! Handle verification response. void onVerificationReceived( QMap response ) override; + protected: + + QNetworkAccessManager* getManager() override; + signals: //! Emitted when the state has changed