@@ -142,6 +142,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
142
142
#include "qgisplugin.h"
143
143
#include "qgsabout.h"
144
144
#include "qgsalignrasterdialog.h"
145
+ #include "qgsappauthrequesthandler.h"
145
146
#include "qgsappbrowserproviders.h"
146
147
#include "qgsapplayertreeviewmenuprovider.h"
147
148
#include "qgsapplication.h"
@@ -13883,85 +13884,18 @@ void QgisApp::namSetup()
13883
13884
{
13884
13885
QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();
13885
13886
13886
- connect( nam, &QNetworkAccessManager::authenticationRequired,
13887
- this, &QgisApp::namAuthenticationRequired );
13888
-
13889
13887
connect( nam, &QNetworkAccessManager::proxyAuthenticationRequired,
13890
13888
this, &QgisApp::namProxyAuthenticationRequired );
13891
13889
13892
13890
connect( nam, qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestTimedOut ),
13893
13891
this, &QgisApp::namRequestTimedOut );
13894
13892
13893
+ nam->setAuthHandler( qgis::make_unique<QgsAppAuthRequestHandler>() );
13895
13894
#ifndef QT_NO_SSL
13896
13895
nam->setSslErrorHandler( qgis::make_unique<QgsAppSslErrorHandler>() );
13897
13896
#endif
13898
13897
}
13899
13898
13900
- void QgisApp::namAuthenticationRequired( QNetworkReply *inReply, QAuthenticator *auth )
13901
- {
13902
- QPointer<QNetworkReply> reply( inReply );
13903
- Q_ASSERT( qApp->thread() == QThread::currentThread() );
13904
-
13905
- QString username = auth->user();
13906
- QString password = auth->password();
13907
-
13908
- if ( username.isEmpty() && password.isEmpty() && reply->request().hasRawHeader( "Authorization" ) )
13909
- {
13910
- QByteArray header( reply->request().rawHeader( "Authorization" ) );
13911
- if ( header.startsWith( "Basic " ) )
13912
- {
13913
- QByteArray auth( QByteArray::fromBase64( header.mid( 6 ) ) );
13914
- int pos = auth.indexOf( ':' );
13915
- if ( pos >= 0 )
13916
- {
13917
- username = auth.left( pos );
13918
- password = auth.mid( pos + 1 );
13919
- }
13920
- }
13921
- }
13922
-
13923
- for ( ;; )
13924
- {
13925
- bool ok;
13926
-
13927
- {
13928
- QMutexLocker lock( QgsCredentials::instance()->mutex() );
13929
- ok = QgsCredentials::instance()->get(
13930
- QStringLiteral( "%1 at %2" ).arg( auth->realm(), reply->url().host() ),
13931
- username, password,
13932
- tr( "Authentication required" ) );
13933
- }
13934
- if ( !ok )
13935
- return;
13936
-
13937
- if ( reply.isNull() || reply->isFinished() )
13938
- return;
13939
-
13940
- if ( auth->user() != username || ( password != auth->password() && !password.isNull() ) )
13941
- break;
13942
-
13943
- // credentials didn't change - stored ones probably wrong? clear password and retry
13944
- {
13945
- QMutexLocker lock( QgsCredentials::instance()->mutex() );
13946
- QgsCredentials::instance()->put(
13947
- QStringLiteral( "%1 at %2" ).arg( auth->realm(), reply->url().host() ),
13948
- username, QString() );
13949
- }
13950
- }
13951
-
13952
- // save credentials
13953
- {
13954
- QMutexLocker lock( QgsCredentials::instance()->mutex() );
13955
- QgsCredentials::instance()->put(
13956
- QStringLiteral( "%1 at %2" ).arg( auth->realm(), reply->url().host() ),
13957
- username, password
13958
- );
13959
- }
13960
-
13961
- auth->setUser( username );
13962
- auth->setPassword( password );
13963
- }
13964
-
13965
13899
void QgisApp::namProxyAuthenticationRequired( const QNetworkProxy &proxy, QAuthenticator *auth )
13966
13900
{
13967
13901
QgsSettings settings;
0 commit comments