|
23 | 23 | #include "qgso2.h"
|
24 | 24 | #include "qgsauthoauth2config.h"
|
25 | 25 | #include "qgsauthoauth2edit.h"
|
| 26 | +#include "qgsguiutils.h" |
26 | 27 | #include "qgsnetworkaccessmanager.h"
|
27 | 28 | #include "qgslogger.h"
|
28 | 29 | #include "qgsmessagelog.h"
|
@@ -142,23 +143,50 @@ bool QgsAuthOAuth2Method::updateNetworkRequest( QNetworkRequest &request, const
|
142 | 143 |
|
143 | 144 | if ( expired )
|
144 | 145 | {
|
145 |
| - msg = QStringLiteral( "Token expired, attempting refresh for authcfg %1" ).arg( authcfg ); |
146 |
| - QgsMessageLog::logMessage( msg, AUTH_METHOD_KEY, Qgis::MessageLevel::Info ); |
147 |
| - |
148 |
| - // Try to get a refresh token first |
149 |
| - // go into local event loop and wait for a fired refresh-related slot |
150 |
| - QEventLoop rloop( nullptr ); |
151 |
| - connect( o2, &QgsO2::refreshFinished, &rloop, &QEventLoop::quit ); |
152 |
| - |
153 |
| - // Asynchronously attempt the refresh |
154 |
| - // TODO: This already has a timed reply setup in O2 base class (and in QgsNetworkAccessManager!) |
155 |
| - // May need to address this or app crashes will occur! |
156 |
| - o2->refresh(); |
157 |
| - |
158 |
| - // block request update until asynchronous linking loop is quit |
159 |
| - rloop.exec( QEventLoop::ExcludeUserInputEvents ); |
160 |
| - |
161 |
| - // refresh result should set o2 to (un)linked |
| 146 | + if ( o2->refreshToken().isEmpty() || o2->refreshTokenUrl().isEmpty() ) |
| 147 | + { |
| 148 | + msg = QStringLiteral( "Token expired, but no refresh token or URL defined for authcfg %1" ).arg( authcfg ); |
| 149 | + QgsMessageLog::logMessage( msg, AUTH_METHOD_KEY, Qgis::MessageLevel::Info ); |
| 150 | + // clear any previous token session properties |
| 151 | + o2->unlink(); |
| 152 | + } |
| 153 | + else |
| 154 | + { |
| 155 | + msg = QStringLiteral( "Token expired, attempting refresh for authcfg %1" ).arg( authcfg ); |
| 156 | + QgsMessageLog::logMessage( msg, AUTH_METHOD_KEY, Qgis::MessageLevel::Info ); |
| 157 | + |
| 158 | + // Try to get a refresh token first |
| 159 | + // go into local event loop and wait for a fired refresh-related slot |
| 160 | + QEventLoop rloop( nullptr ); |
| 161 | + connect( o2, &QgsO2::refreshFinished, &rloop, &QEventLoop::quit ); |
| 162 | + |
| 163 | + // add singlshot timer to quit refresh after an alloted timeout |
| 164 | + // this should keep the local event loop from blocking forever |
| 165 | + QTimer r_timer( nullptr ); |
| 166 | + int r_reqtimeout = o2->oauth2config()->requestTimeout() * 1000; |
| 167 | + r_timer.setInterval( r_reqtimeout ); |
| 168 | + r_timer.setSingleShot( true ); |
| 169 | + connect( &r_timer, &QTimer::timeout, &rloop, &QEventLoop::quit ); |
| 170 | + r_timer.start(); |
| 171 | + |
| 172 | + QgsTemporaryCursorOverride waitCursor( Qt::WaitCursor ); |
| 173 | + |
| 174 | + // Asynchronously attempt the refresh |
| 175 | + // TODO: This already has a timed reply setup in O2 base class (and in QgsNetworkAccessManager!) |
| 176 | + // May need to address this or app crashes will occur! |
| 177 | + o2->refresh(); |
| 178 | + |
| 179 | + // block request update until asynchronous linking loop is quit |
| 180 | + rloop.exec(); |
| 181 | + if ( r_timer.isActive() ) |
| 182 | + { |
| 183 | + r_timer.stop(); |
| 184 | + } |
| 185 | + |
| 186 | + waitCursor.release(); |
| 187 | + |
| 188 | + // refresh result should set o2 to (un)linked |
| 189 | + } |
162 | 190 | }
|
163 | 191 | }
|
164 | 192 |
|
|
0 commit comments