Skip to content

Commit 2e88dd5

Browse files
committed
[oauth] Automatic management of state parameter
Ported from https://github.com/securedimensions/QGIS-OAuth2-Plugin The Boundless Geo version of the plugin requests the state parameter to be provided by the user. We have changed that as we think that the user must not be responsible for providing that, as a duplication of a state parameter could lead to unintentional errors. The Testbed 13 version generates the state parameter automatically for each authorization request to the Authorization Server and checks the value from the redirect to ensure no CSRF attacks.
1 parent 3d20cfe commit 2e88dd5

File tree

7 files changed

+346
-196
lines changed

7 files changed

+346
-196
lines changed

src/auth/oauth2/qgsauthoauth2config.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ QgsAuthOAuth2Config::QgsAuthOAuth2Config( QObject *parent )
4444
connect( this, &QgsAuthOAuth2Config::usernameChanged, this, &QgsAuthOAuth2Config::configChanged );
4545
connect( this, &QgsAuthOAuth2Config::passwordChanged, this, &QgsAuthOAuth2Config::configChanged );
4646
connect( this, &QgsAuthOAuth2Config::scopeChanged, this, &QgsAuthOAuth2Config::configChanged );
47-
connect( this, &QgsAuthOAuth2Config::stateChanged, this, &QgsAuthOAuth2Config::configChanged );
4847
connect( this, &QgsAuthOAuth2Config::apiKeyChanged, this, &QgsAuthOAuth2Config::configChanged );
4948
connect( this, &QgsAuthOAuth2Config::persistTokenChanged, this, &QgsAuthOAuth2Config::configChanged );
5049
connect( this, &QgsAuthOAuth2Config::accessMethodChanged, this, &QgsAuthOAuth2Config::configChanged );
@@ -187,14 +186,6 @@ void QgsAuthOAuth2Config::setScope( const QString &value )
187186
emit scopeChanged( mScope );
188187
}
189188

190-
void QgsAuthOAuth2Config::setState( const QString &value )
191-
{
192-
QString preval( mState );
193-
mState = value;
194-
if ( preval != value )
195-
emit stateChanged( mState );
196-
}
197-
198189
void QgsAuthOAuth2Config::setApiKey( const QString &value )
199190
{
200191
QString preval( mApiKey );
@@ -253,7 +244,6 @@ void QgsAuthOAuth2Config::setToDefaults()
253244
setUsername( QString() );
254245
setPassword( QString() );
255246
setScope( QString() );
256-
setState( QString() );
257247
setApiKey( QString() );
258248
setPersistToken( false );
259249
setAccessMethod( QgsAuthOAuth2Config::Header );
@@ -278,7 +268,6 @@ bool QgsAuthOAuth2Config::operator==( const QgsAuthOAuth2Config &other ) const
278268
&& other.username() == this->username()
279269
&& other.password() == this->password()
280270
&& other.scope() == this->scope()
281-
&& other.state() == this->state()
282271
&& other.apiKey() == this->apiKey()
283272
&& other.persistToken() == this->persistToken()
284273
&& other.accessMethod() == this->accessMethod()
@@ -410,7 +399,6 @@ QVariantMap QgsAuthOAuth2Config::mappedProperties() const
410399
vmap.insert( QStringLiteral( "requestTimeout" ), this->requestTimeout() );
411400
vmap.insert( QStringLiteral( "requestUrl" ), this->requestUrl() );
412401
vmap.insert( QStringLiteral( "scope" ), this->scope() );
413-
vmap.insert( QStringLiteral( "state" ), this->state() );
414402
vmap.insert( QStringLiteral( "tokenUrl" ), this->tokenUrl() );
415403
vmap.insert( QStringLiteral( "username" ), this->username() );
416404
vmap.insert( QStringLiteral( "version" ), this->version() );

src/auth/oauth2/qgsauthoauth2config.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class QgsAuthOAuth2Config : public QObject
5050
Q_PROPERTY( QString username READ username WRITE setUsername NOTIFY usernameChanged )
5151
Q_PROPERTY( QString password READ password WRITE setPassword NOTIFY passwordChanged )
5252
Q_PROPERTY( QString scope READ scope WRITE setScope NOTIFY scopeChanged )
53-
Q_PROPERTY( QString state READ state WRITE setState NOTIFY stateChanged )
5453
Q_PROPERTY( QString apiKey READ apiKey WRITE setApiKey NOTIFY apiKeyChanged )
5554
Q_PROPERTY( bool persistToken READ persistToken WRITE setPersistToken NOTIFY persistTokenChanged )
5655
Q_PROPERTY( AccessMethod accessMethod READ accessMethod WRITE setAccessMethod NOTIFY accessMethodChanged )
@@ -139,9 +138,6 @@ class QgsAuthOAuth2Config : public QObject
139138
//! Scope of authentication
140139
QString scope() const { return mScope; }
141140

142-
//! State passed with request
143-
QString state() const { return mState; }
144-
145141
//! API key
146142
QString apiKey() const { return mApiKey; }
147143

@@ -282,8 +278,6 @@ class QgsAuthOAuth2Config : public QObject
282278
void setPassword( const QString &value );
283279
//! Set scope to \a value
284280
void setScope( const QString &value );
285-
//! Set state to \a value
286-
void setState( const QString &value );
287281
//! Set api key to \a value
288282
void setApiKey( const QString &value );
289283
// advanced
@@ -335,8 +329,6 @@ class QgsAuthOAuth2Config : public QObject
335329
void passwordChanged( const QString & );
336330
//! Emitted when configuration scope has changed
337331
void scopeChanged( const QString & );
338-
//! Emitted when configuration state has changed
339-
void stateChanged( const QString & );
340332
//! Emitted when configuration API key has changed
341333
void apiKeyChanged( const QString & );
342334

@@ -369,7 +361,6 @@ class QgsAuthOAuth2Config : public QObject
369361
QString mUsername;
370362
QString mPassword;
371363
QString mScope;
372-
QString mState;
373364
QString mApiKey;
374365
bool mPersistToken = false;
375366
AccessMethod mAccessMethod = AccessMethod::Header;

src/auth/oauth2/qgsauthoauth2edit.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ void QgsAuthOAuth2Edit::setupConnections()
161161
connect( leUsername, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setUsername );
162162
connect( lePassword, &QgsPasswordLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setPassword );
163163
connect( leScope, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setScope );
164-
connect( leState, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setState );
165164
connect( leApiKey, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setApiKey );
166165
connect( chkbxTokenPersist, &QCheckBox::toggled, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setPersistToken );
167166
connect( cmbbxAccessMethod, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
@@ -380,7 +379,6 @@ void QgsAuthOAuth2Edit::loadFromOAuthConfig( const QgsAuthOAuth2Config *config )
380379
leUsername->setText( config->username() );
381380
lePassword->setText( config->password() );
382381
leScope->setText( config->scope() );
383-
leState->setText( config->state() );
384382
leApiKey->setText( config->apiKey() );
385383

386384
// advanced

0 commit comments

Comments
 (0)