Skip to content
Permalink
Browse files
Merge pull request #43229 from nirvn/close_browser
[network access manager] handle abortion of browser login request
  • Loading branch information
nirvn committed May 15, 2021
2 parents 8513b80 + 8647ec5 commit 8ebef88e27d5591e8c7b5bd9fe6b39ac5faeba76
@@ -343,6 +343,18 @@ Forwards an external browser login closure request to the authentication handler
.. versionadded:: 3.20
%End

void abortAuthBrowser();
%Docstring
Abort any outstanding external browser login request.

.. note::

Background threads will listen to aborted browser request signals from the network manager on the main thread.

.. versionadded:: 3.20
%End




signals:
@@ -483,6 +495,12 @@ See :py:class:`QgsSslErrorHandler` for details on how to handle SSL errors and p
void requestTimedOut( QNetworkReply * );


void authBrowserAborted();
%Docstring
Emitted when external browser logins are to be aborted.

.. versionadded:: 3.20
%End

protected:
virtual QNetworkReply *createRequest( QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0 );
@@ -195,6 +195,7 @@ bool QgsAuthOAuth2Method::updateNetworkRequest( QNetworkRequest &request, const
QEventLoop loop( nullptr );
connect( o2, &QgsO2::linkingFailed, &loop, &QEventLoop::quit );
connect( o2, &QgsO2::linkingSucceeded, &loop, &QEventLoop::quit );
connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::authBrowserAborted, &loop, &QEventLoop::quit );

// add single shot timer to quit linking after an allotted timeout
// this should keep the local event loop from blocking forever
@@ -468,6 +468,7 @@ void QgsNetworkAccessManager::requestAuthOpenBrowser( const QUrl &url ) const
if ( this != sMainNAM )
{
sMainNAM->requestAuthOpenBrowser( url );
connect( sMainNAM, &QgsNetworkAccessManager::authBrowserAborted, this, &QgsNetworkAccessManager::abortAuthBrowser );
return;
}
mAuthHandler->handleAuthRequestOpenBrowser( url );
@@ -478,11 +479,21 @@ void QgsNetworkAccessManager::requestAuthCloseBrowser() const
if ( this != sMainNAM )
{
sMainNAM->requestAuthCloseBrowser();
disconnect( sMainNAM, &QgsNetworkAccessManager::authBrowserAborted, this, &QgsNetworkAccessManager::abortAuthBrowser );
return;
}
mAuthHandler->handleAuthRequestCloseBrowser();
}

void QgsNetworkAccessManager::abortAuthBrowser()
{
if ( this != sMainNAM )
{
disconnect( sMainNAM, &QgsNetworkAccessManager::authBrowserAborted, this, &QgsNetworkAccessManager::abortAuthBrowser );
}
emit authBrowserAborted();
}

void QgsNetworkAccessManager::handleAuthRequest( QNetworkReply *reply, QAuthenticator *auth )
{
mAuthHandler->handleAuthRequest( reply, auth );
@@ -530,6 +530,15 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
*/
void requestAuthCloseBrowser() const;

/**
* Abort any outstanding external browser login request.
*
* \note Background threads will listen to aborted browser request signals from the network manager on the main thread.
* \since QGIS 3.20
*/
void abortAuthBrowser();


#ifndef SIP_RUN
//! Settings entry network timeout
static const inline QgsSettingsEntryInteger settingsNetworkTimeout = QgsSettingsEntryInteger( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), QgsSettings::NoSection, 60000, QObject::tr( "Network timeout" ) );
@@ -678,6 +687,12 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
///@endcond
#endif

/**
* Emitted when external browser logins are to be aborted.
*
* \since QGIS 3.20
*/
void authBrowserAborted();

private slots:
void abortRequest();

0 comments on commit 8ebef88

Please sign in to comment.