|
33 | 33 | #include <QDir>
|
34 | 34 | #include <QEventLoop>
|
35 | 35 | #include <QString>
|
| 36 | +#include <QMutexLocker> |
36 | 37 |
|
37 | 38 |
|
38 | 39 | static const QString AUTH_METHOD_KEY = QStringLiteral( "OAuth2" );
|
@@ -105,6 +106,8 @@ bool QgsAuthOAuth2Method::updateNetworkRequest( QNetworkRequest &request, const
|
105 | 106 | {
|
106 | 107 | Q_UNUSED( dataprovider )
|
107 | 108 |
|
| 109 | + QMutexLocker locker( &mNetworkRequestMutex ); |
| 110 | + |
108 | 111 | QString msg;
|
109 | 112 |
|
110 | 113 | QgsO2 *o2 = getOAuth2Bundle( authcfg );
|
@@ -144,7 +147,7 @@ bool QgsAuthOAuth2Method::updateNetworkRequest( QNetworkRequest &request, const
|
144 | 147 |
|
145 | 148 | // Try to get a refresh token first
|
146 | 149 | // go into local event loop and wait for a fired refresh-related slot
|
147 |
| - QEventLoop rloop( qApp ); |
| 150 | + QEventLoop rloop( nullptr ); |
148 | 151 | connect( o2, &QgsO2::refreshFinished, &rloop, &QEventLoop::quit );
|
149 | 152 |
|
150 | 153 | // Asynchronously attempt the refresh
|
@@ -182,13 +185,13 @@ bool QgsAuthOAuth2Method::updateNetworkRequest( QNetworkRequest &request, const
|
182 | 185 | settings.setValue( timeoutkey, reqtimeout );
|
183 | 186 |
|
184 | 187 | // go into local event loop and wait for a fired linking-related slot
|
185 |
| - QEventLoop loop( qApp ); |
| 188 | + QEventLoop loop( nullptr ); |
186 | 189 | connect( o2, &QgsO2::linkingFailed, &loop, &QEventLoop::quit );
|
187 | 190 | connect( o2, &QgsO2::linkingSucceeded, &loop, &QEventLoop::quit );
|
188 | 191 |
|
189 | 192 | // add singlshot timer to quit linking after an alloted timeout
|
190 | 193 | // this should keep the local event loop from blocking forever
|
191 |
| - QTimer timer( this ); |
| 194 | + QTimer timer( nullptr ); |
192 | 195 | timer.setInterval( reqtimeout * 5 );
|
193 | 196 | timer.setSingleShot( true );
|
194 | 197 | connect( &timer, &QTimer::timeout, o2, &QgsO2::linkingFailed );
|
@@ -270,6 +273,7 @@ bool QgsAuthOAuth2Method::updateNetworkRequest( QNetworkRequest &request, const
|
270 | 273 | bool QgsAuthOAuth2Method::updateNetworkReply( QNetworkReply *reply, const QString &authcfg, const QString &dataprovider )
|
271 | 274 | {
|
272 | 275 | Q_UNUSED( dataprovider )
|
| 276 | + QMutexLocker locker( &mNetworkRequestMutex ); |
273 | 277 |
|
274 | 278 | // TODO: handle token refresh error on the reply, see O2Requestor::onRequestError()
|
275 | 279 | // Is this doable if the errors are also handled in qgsapp (and/or elsewhere)?
|
@@ -389,6 +393,7 @@ void QgsAuthOAuth2Method::onReplyFinished()
|
389 | 393 |
|
390 | 394 | void QgsAuthOAuth2Method::onNetworkError( QNetworkReply::NetworkError err )
|
391 | 395 | {
|
| 396 | + QMutexLocker locker( &mNetworkRequestMutex ); |
392 | 397 | QString msg;
|
393 | 398 | QNetworkReply *reply = qobject_cast<QNetworkReply *>( sender() );
|
394 | 399 | if ( !reply )
|
@@ -489,7 +494,7 @@ QgsO2 *QgsAuthOAuth2Method::getOAuth2Bundle( const QString &authcfg, bool fullco
|
489 | 494 | return sOAuth2ConfigCache.value( authcfg );
|
490 | 495 | }
|
491 | 496 |
|
492 |
| - QgsAuthOAuth2Config *config = new QgsAuthOAuth2Config( qApp ); |
| 497 | + QgsAuthOAuth2Config *config = new QgsAuthOAuth2Config( ); |
493 | 498 | QgsO2 *nullbundle = nullptr;
|
494 | 499 |
|
495 | 500 | // else build oauth2 config
|
@@ -542,7 +547,7 @@ QgsO2 *QgsAuthOAuth2Method::getOAuth2Bundle( const QString &authcfg, bool fullco
|
542 | 547 | QgsDebugMsg( QStringLiteral( "No custom defined dir path to load OAuth2 config" ) );
|
543 | 548 | }
|
544 | 549 |
|
545 |
| - QgsStringMap definedcache = QgsAuthOAuth2Config::mappedOAuth2ConfigsCache( extradir ); |
| 550 | + QgsStringMap definedcache = QgsAuthOAuth2Config::mappedOAuth2ConfigsCache( this, extradir ); |
546 | 551 |
|
547 | 552 | if ( !definedcache.contains( definedid ) )
|
548 | 553 | {
|
@@ -595,7 +600,7 @@ QgsO2 *QgsAuthOAuth2Method::getOAuth2Bundle( const QString &authcfg, bool fullco
|
595 | 600 | QgsDebugMsg( QStringLiteral( "Loading authenticator object with %1 flow properties of OAuth2 config: %2" )
|
596 | 601 | .arg( QgsAuthOAuth2Config::grantFlowString( config->grantFlow() ), authcfg ) );
|
597 | 602 |
|
598 |
| - QgsO2 *o2 = new QgsO2( authcfg, config, qApp, QgsNetworkAccessManager::instance() ); |
| 603 | + QgsO2 *o2 = new QgsO2( authcfg, config, nullptr, QgsNetworkAccessManager::instance() ); |
599 | 604 |
|
600 | 605 | // cache bundle
|
601 | 606 | putOAuth2Bundle( authcfg, o2 );
|
|
0 commit comments