Skip to content

Commit ab0c58d

Browse files
committedJun 26, 2018
[auth] Code style, unique ptrs and documentation
1 parent e02845a commit ab0c58d

File tree

8 files changed

+379
-241
lines changed

8 files changed

+379
-241
lines changed
 

‎doc/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ IF(WITH_APIDOC)
5757
${CMAKE_SOURCE_DIR}/src/core/3d
5858
${CMAKE_SOURCE_DIR}/src/core/annotations
5959
${CMAKE_SOURCE_DIR}/src/core/auth
60+
${CMAKE_SOURCE_DIR}/src/auth
61+
${CMAKE_SOURCE_DIR}/src/auth/oauth2
6062
${CMAKE_SOURCE_DIR}/src/core/diagram
6163
${CMAKE_SOURCE_DIR}/src/core/dxf
6264
${CMAKE_SOURCE_DIR}/src/core/effects

‎doc/modules.dox

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,14 @@ Contains classes related to implementation of QGIS plugins.
4242
The QgsQuick library is built on top of the CORE library and Qt Quick/QML framework. It adds reusable GUI Quick Components, mainly for mobile devices.
4343

4444
*/
45+
46+
47+
48+
*/
49+
50+
/** @defgroup auth_plugins Authentication plugins
51+
52+
The QGIS authentication manager uses authentication plugins to provide most common authentication methods.
53+
54+
*/
55+

‎src/auth/oauth2/qgsauthoauth2config.cpp

Lines changed: 159 additions & 133 deletions
Large diffs are not rendered by default.

‎src/auth/oauth2/qgsauthoauth2config.h

Lines changed: 123 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,64 @@
2222

2323
#include "qgis.h"
2424

25-
25+
/**
26+
* The QgsAuthOAuth2Config class stores the configuration for OAuth2 authentication plugin
27+
* \ingroup auth_plugins
28+
*/
2629
class QgsAuthOAuth2Config : public QObject
2730
{
2831
Q_OBJECT
2932
Q_ENUMS( ConfigType )
3033
Q_ENUMS( GrantFlow )
3134
Q_ENUMS( ConfigFormat )
3235
Q_ENUMS( AccessMethod )
36+
Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged )
37+
Q_PROPERTY( int version READ version WRITE setVersion NOTIFY versionChanged )
38+
Q_PROPERTY( ConfigType configType READ configType WRITE setConfigType NOTIFY configTypeChanged )
39+
Q_PROPERTY( GrantFlow grantFlow READ grantFlow WRITE setGrantFlow NOTIFY grantFlowChanged )
40+
Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
41+
Q_PROPERTY( QString description READ description WRITE setDescription NOTIFY descriptionChanged )
42+
Q_PROPERTY( QString requestUrl READ requestUrl WRITE setRequestUrl NOTIFY requestUrlChanged )
43+
Q_PROPERTY( QString tokenUrl READ tokenUrl WRITE setTokenUrl NOTIFY tokenUrlChanged )
44+
Q_PROPERTY( QString refreshTokenUrl READ refreshTokenUrl WRITE setRefreshTokenUrl NOTIFY refreshTokenUrlChanged )
45+
Q_PROPERTY( QString redirectUrl READ redirectUrl WRITE setRedirectUrl NOTIFY redirectUrlChanged )
46+
Q_PROPERTY( int redirectPort READ redirectPort WRITE setRedirectPort NOTIFY redirectPortChanged )
47+
Q_PROPERTY( QString clientId READ clientId WRITE setClientId NOTIFY clientIdChanged )
48+
Q_PROPERTY( QString clientSecret READ clientSecret WRITE setClientSecret NOTIFY clientSecretChanged )
49+
Q_PROPERTY( QString username READ username WRITE setUsername NOTIFY usernameChanged )
50+
Q_PROPERTY( QString password READ password WRITE setPassword NOTIFY passwordChanged )
51+
Q_PROPERTY( QString scope READ scope WRITE setScope NOTIFY scopeChanged )
52+
Q_PROPERTY( QString state READ state WRITE setState NOTIFY stateChanged )
53+
Q_PROPERTY( QString apiKey READ apiKey WRITE setApiKey NOTIFY apiKeyChanged )
54+
Q_PROPERTY( bool persistToken READ persistToken WRITE setPersistToken NOTIFY persistTokenChanged )
55+
Q_PROPERTY( AccessMethod accessMethod READ accessMethod WRITE setAccessMethod NOTIFY accessMethodChanged )
56+
Q_PROPERTY( int requestTimeout READ requestTimeout WRITE setRequestTimeout NOTIFY requestTimeoutChanged )
57+
Q_PROPERTY( QVariantMap queryPairs READ queryPairs WRITE setQueryPairs NOTIFY queryPairsChanged )
3358

3459
public:
3560

61+
//! Configuration type
3662
enum ConfigType
3763
{
3864
Predefined,
3965
Custom,
4066
};
4167

68+
//! OAuth2 grant flow
4269
enum GrantFlow
4370
{
4471
AuthCode, //!< @see http://tools.ietf.org/html/rfc6749#section-4.1
4572
Implicit, //!< @see http://tools.ietf.org/html/rfc6749#section-4.2
4673
ResourceOwner, //!< @see http://tools.ietf.org/html/rfc6749#section-4.3
4774
};
4875

76+
//! Configuration format for serialize/unserialize operations
4977
enum ConfigFormat
5078
{
5179
JSON,
5280
};
5381

82+
//! Access method
5483
enum AccessMethod
5584
{
5685
Header,
@@ -60,94 +89,70 @@ class QgsAuthOAuth2Config : public QObject
6089

6190
explicit QgsAuthOAuth2Config( QObject *parent = nullptr );
6291

63-
~QgsAuthOAuth2Config();
64-
6592
//! Unique ID
66-
Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged )
6793
QString id() const { return mId; }
6894

6995
//! Increment this if method is significantly updated, allow updater code to be written
70-
Q_PROPERTY( int version READ version WRITE setVersion NOTIFY versionChanged )
7196
int version() const { return mVersion; }
7297

7398
//! Configuration type
74-
Q_PROPERTY( ConfigType configType READ configType WRITE setConfigType NOTIFY configTypeChanged )
7599
ConfigType configType() const { return mConfigType; }
76100

77101
//! Authorization flow
78-
Q_PROPERTY( GrantFlow grantFlow READ grantFlow WRITE setGrantFlow NOTIFY grantFlowChanged )
79102
GrantFlow grantFlow() const { return mGrantFlow; }
80103

81104
//! Configuration name
82-
Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
83105
QString name() const { return mName; }
84106

85107
//! Configuration description
86-
Q_PROPERTY( QString description READ description WRITE setDescription NOTIFY descriptionChanged )
87108
QString description() const { return mDescription; }
88109

89-
//!
90-
Q_PROPERTY( QString requestUrl READ requestUrl WRITE setRequestUrl NOTIFY requestUrlChanged )
110+
//! Request url
91111
QString requestUrl() const { return mRequestUrl; }
92112

93-
//!
94-
Q_PROPERTY( QString tokenUrl READ tokenUrl WRITE setTokenUrl NOTIFY tokenUrlChanged )
113+
//! Token url
95114
QString tokenUrl() const { return mTokenUrl; }
96115

97-
//!
98-
Q_PROPERTY( QString refreshTokenUrl READ refreshTokenUrl WRITE setRefreshTokenUrl NOTIFY refreshTokenUrlChanged )
116+
//! Refresh token url
99117
QString refreshTokenUrl() const { return mRefreshTokenUrl; }
100118

101-
//!
102-
Q_PROPERTY( QString redirectUrl READ redirectUrl WRITE setRedirectUrl NOTIFY redirectUrlChanged )
119+
//! Redirect url
103120
QString redirectUrl() const { return mRedirectURL; }
104121

105-
//!
106-
Q_PROPERTY( int redirectPort READ redirectPort WRITE setRedirectPort NOTIFY redirectPortChanged )
122+
//! Redirect port
107123
int redirectPort() const { return mRedirectPort; }
108124

109-
//!
110-
Q_PROPERTY( QString clientId READ clientId WRITE setClientId NOTIFY clientIdChanged )
125+
//! Client id
111126
QString clientId() const { return mClientId; }
112127

113-
//!
114-
Q_PROPERTY( QString clientSecret READ clientSecret WRITE setClientSecret NOTIFY clientSecretChanged )
128+
//! Client secret
115129
QString clientSecret() const { return mClientSecret; }
116130

117131
//! Resource owner username
118-
Q_PROPERTY( QString username READ username WRITE setUsername NOTIFY usernameChanged )
119132
QString username() const { return mUsername; }
120133

121134
//! Resource owner password
122-
Q_PROPERTY( QString password READ password WRITE setPassword NOTIFY passwordChanged )
123135
QString password() const { return mPassword; }
124136

125137
//! Scope of authentication
126-
Q_PROPERTY( QString scope READ scope WRITE setScope NOTIFY scopeChanged )
127138
QString scope() const { return mScope; }
128139

129140
//! State passed with request
130-
Q_PROPERTY( QString state READ state WRITE setState NOTIFY stateChanged )
131141
QString state() const { return mState; }
132142

133-
//!
134-
Q_PROPERTY( QString apiKey READ apiKey WRITE setApiKey NOTIFY apiKeyChanged )
143+
//! API key
135144
QString apiKey() const { return mApiKey; }
136145

137-
//!
138-
Q_PROPERTY( bool persistToken READ persistToken WRITE setPersistToken NOTIFY persistTokenChanged )
146+
//! Return true if the token is persistant
139147
bool persistToken() const { return mPersistToken; }
140148

141-
//!
142-
Q_PROPERTY( AccessMethod accessMethod READ accessMethod WRITE setAccessMethod NOTIFY accessMethodChanged )
149+
//! Access method
143150
AccessMethod accessMethod() const { return mAccessMethod; }
144151

145-
//!
146-
Q_PROPERTY( int requestTimeout READ requestTimeout WRITE setRequestTimeout NOTIFY requestTimeoutChanged )
152+
//! Request timeout
147153
int requestTimeout() const { return mRequestTimeout; }
148154

149-
//!
150-
Q_PROPERTY( QVariantMap queryPairs READ queryPairs WRITE setQueryPairs NOTIFY queryPairsChanged )
155+
//! Query pairs
151156
QVariantMap queryPairs() const { return mQueryPairs; }
152157

153158
//! Operator used to compare configs' equality
@@ -159,7 +164,7 @@ class QgsAuthOAuth2Config : public QObject
159164
//! Check whether config is valid, then return it
160165
bool isValid() const;
161166

162-
//! @see http://tools.ietf.org/html/rfc6749 for required data per flow
167+
//! \see http://tools.ietf.org/html/rfc6749 for required data per flow
163168
void validateConfigId( bool needsId = false );
164169

165170
//! Load a string (e.g. JSON) of a config
@@ -168,16 +173,29 @@ class QgsAuthOAuth2Config : public QObject
168173
//! Save a config to a string (e.g. JSON)
169174
QByteArray saveConfigTxt( ConfigFormat format = JSON, bool pretty = false, bool *ok = nullptr ) const;
170175

171-
//!
176+
//! Return the configuration as a QVariant map
172177
QVariantMap mappedProperties() const;
173178

174-
//!
179+
/**
180+
* Serialize the configuration \a variant according to \a format
181+
* \param variant map where configuration is stored
182+
* \param format output format
183+
* \param pretty indentation in output
184+
* \param ok is set to false in case something goes wrong, true otherwise
185+
* \return serialized config
186+
*/
175187
static QByteArray serializeFromVariant( const QVariantMap &variant,
176188
ConfigFormat format = JSON,
177189
bool pretty = false,
178190
bool *ok = nullptr );
179191

180-
//!
192+
/**
193+
* Unserialize the configuration in \a serial according to \a format
194+
* \param serial serialized configuration
195+
* \param format output format
196+
* \param ok is set to false in case something goes wrong, true otherwise
197+
* \return config map
198+
*/
181199
static QVariantMap variantFromSerialized( const QByteArray &serial,
182200
ConfigFormat format = JSON,
183201
bool *ok = nullptr );
@@ -205,112 +223,157 @@ class QgsAuthOAuth2Config : public QObject
205223
//! Load and parse standard directories of configs (e.g. JSON) to a mapped cache
206224
static QgsStringMap mappedOAuth2ConfigsCache( QObject *parent, const QString &extradir = QString::null );
207225

208-
//!
226+
//! Path where config is stored
209227
static QString oauth2ConfigsPkgDataDir();
210228

211-
//!
229+
//! Path where user settings are stored
212230
static QString oauth2ConfigsUserSettingsDir();
213231

214-
//!
232+
//! User readable name of the \a configtype
215233
static QString configTypeString( ConfigType configtype );
216234

217-
//!
235+
//! User readable name of the grant \a flow
218236
static QString grantFlowString( GrantFlow flow );
219237

220-
//!
238+
//! User readable name of the access \a method
221239
static QString accessMethodString( AccessMethod method );
222240

223-
//!
241+
//! Path of the token cache \a temporary directory
224242
static QString tokenCacheDirectory( bool temporary = false );
225243

226-
//!
244+
//! Path of the token cache file, with optional \a suffix
227245
static QString tokenCacheFile( const QString &suffix = QString::null );
228246

229-
//!
247+
//! Path of the token cache file, with optional \a suffix and \a temporary flag
230248
static QString tokenCachePath( const QString &suffix = QString::null, bool temporary = false );
231249

232250
public slots:
251+
//! Set the id to \a value
233252
void setId( const QString &value );
253+
//! Set version to \a value
234254
void setVersion( int value );
255+
//! Set config type to \a value
235256
void setConfigType( ConfigType value );
257+
//! Set grant flow to \a value
236258
void setGrantFlow( GrantFlow value );
259+
//! Set name to \a value
237260
void setName( const QString &value );
261+
//! Set description to \a value
238262
void setDescription( const QString &value );
263+
//! Set request url to \a value
239264
void setRequestUrl( const QString &value );
265+
//! Set token url to \a value
240266
void setTokenUrl( const QString &value );
267+
//! Set refresh token url to \a value
241268
void setRefreshTokenUrl( const QString &value );
269+
//! Set redirect url to \a value
242270
void setRedirectUrl( const QString &value );
271+
//! Set redirect port to \a value
243272
void setRedirectPort( int value );
273+
//! Set client id to \a value
244274
void setClientId( const QString &value );
275+
//! Set client secret to \a value
245276
void setClientSecret( const QString &value );
277+
//! Set username to \a value
246278
void setUsername( const QString &value );
279+
//! Set password to \a value
247280
void setPassword( const QString &value );
281+
//! Set scope to \a value
248282
void setScope( const QString &value );
283+
//! Set state to \a value
249284
void setState( const QString &value );
285+
//! Set api key to \a value
250286
void setApiKey( const QString &value );
251287
// advanced
288+
//! Set persistent token flag to \a persist
252289
void setPersistToken( bool persist );
290+
//! Set access method to \a value
253291
void setAccessMethod( AccessMethod value );
292+
//! Set request timeout to \a value
254293
void setRequestTimeout( int value );
294+
//! Set query pairs to \a pairs
255295
void setQueryPairs( const QVariantMap &pairs );
256-
296+
//! Reset configuration to defaults
257297
void setToDefaults();
258-
298+
//! Validate configuration
259299
void validateConfig();
260300

261301
signals:
302+
//! Emitted when configuration has changed
262303
void configChanged();
304+
//! Emitted when configuration id has changed
263305
void idChanged( const QString & );
306+
//! Emitted when configuration version has changed
264307
void versionChanged( int );
308+
//! Emitted when configuration type has changed
265309
void configTypeChanged( ConfigType );
310+
//! Emitted when configuration grant flow has changed
266311
void grantFlowChanged( GrantFlow );
312+
//! Emitted when configuration grant flow has changed
267313
void nameChanged( const QString & );
314+
//! Emitted when configuration name has changed
268315
void descriptionChanged( const QString & );
316+
//! Emitted when configuration request urlhas changed
269317
void requestUrlChanged( const QString & );
318+
//! Emitted when configuration token url has changed
270319
void tokenUrlChanged( const QString & );
320+
//! Emitted when configuration refresh token url has changed
271321
void refreshTokenUrlChanged( const QString & );
322+
//! Emitted when configuration redirect url has changed
272323
void redirectUrlChanged( const QString & );
324+
//! Emitted when configuration redirect port has changed
273325
void redirectPortChanged( int );
326+
//! Emitted when configuration client id has changed
274327
void clientIdChanged( const QString & );
328+
//! Emitted when configuration client secret has changed
275329
void clientSecretChanged( const QString & );
330+
//! Emitted when configuration username has changed
276331
void usernameChanged( const QString & );
332+
//! Emitted when configuration password has changed
277333
void passwordChanged( const QString & );
334+
//! Emitted when configuration scope has changed
278335
void scopeChanged( const QString & );
336+
//! Emitted when configuration state has changed
279337
void stateChanged( const QString & );
338+
//! Emitted when configuration API key has changed
280339
void apiKeyChanged( const QString & );
281340

282341
// advanced
342+
//! Emitted when configuration persiste token flag has changed
283343
void persistTokenChanged( bool );
344+
//! Emitted when configuration access method has changed
284345
void accessMethodChanged( AccessMethod );
346+
//! Emitted when configuration request timeout has changed
285347
void requestTimeoutChanged( int );
348+
//! Emitted when configuration query pair has changed
286349
void queryPairsChanged( const QVariantMap & );
287-
350+
//! Emitted when configuration validity has changed
288351
void validityChanged( bool );
289352

290353
private:
291354
QString mId;
292-
int mVersion;
293-
ConfigType mConfigType;
294-
GrantFlow mGrantFlow;
355+
int mVersion = 1;
356+
ConfigType mConfigType = ConfigType::Custom;
357+
GrantFlow mGrantFlow = GrantFlow::AuthCode;
295358
QString mName;
296359
QString mDescription;
297360
QString mRequestUrl;
298361
QString mTokenUrl;
299362
QString mRefreshTokenUrl;
300363
QString mRedirectURL;
301-
int mRedirectPort;
364+
int mRedirectPort = 7070;
302365
QString mClientId;
303366
QString mClientSecret;
304367
QString mUsername;
305368
QString mPassword;
306369
QString mScope;
307370
QString mState;
308371
QString mApiKey;
309-
bool mPersistToken;
310-
AccessMethod mAccessMethod;
311-
int mRequestTimeout; // in seconds
372+
bool mPersistToken = false;
373+
AccessMethod mAccessMethod = AccessMethod::Header;
374+
int mRequestTimeout = 30 ; // in seconds
312375
QVariantMap mQueryPairs;
313-
bool mValid;
376+
bool mValid = false;
314377
};
315378

316379
#endif // QGSAUTHOAUTH2CONFIG_H

‎src/auth/oauth2/qgsauthoauth2edit.cpp

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@
2727

2828
QgsAuthOAuth2Edit::QgsAuthOAuth2Edit( QWidget *parent )
2929
: QgsAuthMethodEdit( parent )
30-
, mOAuthConfigCustom( nullptr )
3130
, mDefinedConfigsCache( QgsStringMap() )
32-
, mParentName( nullptr )
33-
, mValid( false )
34-
, mCurTab( 0 )
35-
, mPrevPersistToken( false )
36-
, btnTokenClear( nullptr )
3731
{
3832
setupUi( this );
3933

@@ -52,13 +46,9 @@ QgsAuthOAuth2Edit::QgsAuthOAuth2Edit( QWidget *parent )
5246

5347
setupConnections();
5448

55-
loadFromOAuthConfig( mOAuthConfigCustom );
49+
loadFromOAuthConfig( mOAuthConfigCustom.get() );
5650
}
5751

58-
QgsAuthOAuth2Edit::~QgsAuthOAuth2Edit()
59-
{
60-
deleteConfigObjs();
61-
}
6252

6353
void QgsAuthOAuth2Edit::initGui()
6454
{
@@ -160,26 +150,26 @@ void QgsAuthOAuth2Edit::setupConnections()
160150
connect( cmbbxGrantFlow, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
161151
this, &QgsAuthOAuth2Edit::updateGrantFlow ); // also updates GUI
162152
connect( pteDescription, &QPlainTextEdit::textChanged, this, &QgsAuthOAuth2Edit::descriptionChanged );
163-
connect( leRequestUrl, &QLineEdit::textChanged, mOAuthConfigCustom, &QgsAuthOAuth2Config::setRequestUrl );
164-
connect( leTokenUrl, &QLineEdit::textChanged, mOAuthConfigCustom, &QgsAuthOAuth2Config::setTokenUrl );
165-
connect( leRefreshTokenUrl, &QLineEdit::textChanged, mOAuthConfigCustom, &QgsAuthOAuth2Config::setRefreshTokenUrl );
166-
connect( leRedirectUrl, &QLineEdit::textChanged, mOAuthConfigCustom, &QgsAuthOAuth2Config::setRedirectUrl );
153+
connect( leRequestUrl, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setRequestUrl );
154+
connect( leTokenUrl, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setTokenUrl );
155+
connect( leRefreshTokenUrl, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setRefreshTokenUrl );
156+
connect( leRedirectUrl, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setRedirectUrl );
167157
connect( spnbxRedirectPort, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ),
168-
mOAuthConfigCustom, &QgsAuthOAuth2Config::setRedirectPort );
169-
connect( leClientId, &QLineEdit::textChanged, mOAuthConfigCustom, &QgsAuthOAuth2Config::setClientId );
170-
connect( leClientSecret, &QgsPasswordLineEdit::textChanged, mOAuthConfigCustom, &QgsAuthOAuth2Config::setClientSecret );
171-
connect( leUsername, &QLineEdit::textChanged, mOAuthConfigCustom, &QgsAuthOAuth2Config::setUsername );
172-
connect( lePassword, &QgsPasswordLineEdit::textChanged, mOAuthConfigCustom, &QgsAuthOAuth2Config::setPassword );
173-
connect( leScope, &QLineEdit::textChanged, mOAuthConfigCustom, &QgsAuthOAuth2Config::setScope );
174-
connect( leState, &QLineEdit::textChanged, mOAuthConfigCustom, &QgsAuthOAuth2Config::setState );
175-
connect( leApiKey, &QLineEdit::textChanged, mOAuthConfigCustom, &QgsAuthOAuth2Config::setApiKey );
176-
connect( chkbxTokenPersist, &QCheckBox::toggled, mOAuthConfigCustom, &QgsAuthOAuth2Config::setPersistToken );
158+
mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setRedirectPort );
159+
connect( leClientId, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setClientId );
160+
connect( leClientSecret, &QgsPasswordLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setClientSecret );
161+
connect( leUsername, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setUsername );
162+
connect( lePassword, &QgsPasswordLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setPassword );
163+
connect( leScope, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setScope );
164+
connect( leState, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setState );
165+
connect( leApiKey, &QLineEdit::textChanged, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setApiKey );
166+
connect( chkbxTokenPersist, &QCheckBox::toggled, mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setPersistToken );
177167
connect( cmbbxAccessMethod, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
178168
this, &QgsAuthOAuth2Edit::updateConfigAccessMethod );
179169
connect( spnbxRequestTimeout, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ),
180-
mOAuthConfigCustom, &QgsAuthOAuth2Config::setRequestTimeout );
170+
mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::setRequestTimeout );
181171

182-
connect( mOAuthConfigCustom, &QgsAuthOAuth2Config::validityChanged, this, &QgsAuthOAuth2Edit::configValidityChanged );
172+
connect( mOAuthConfigCustom.get(), &QgsAuthOAuth2Config::validityChanged, this, &QgsAuthOAuth2Edit::configValidityChanged );
183173

184174
if ( mParentName )
185175
{
@@ -286,7 +276,7 @@ void QgsAuthOAuth2Edit::loadConfig( const QgsStringMap &configmap )
286276
//###################### DO NOT LEAVE ME UNCOMMENTED #####################
287277

288278
// could only be loading defaults at this point
289-
loadFromOAuthConfig( mOAuthConfigCustom );
279+
loadFromOAuthConfig( mOAuthConfigCustom.get() );
290280

291281
mPrevPersistToken = mOAuthConfigCustom->persistToken();
292282
}
@@ -361,7 +351,7 @@ void QgsAuthOAuth2Edit::clearConfig()
361351
// reload predefined table
362352
loadDefinedConfigs();
363353

364-
loadFromOAuthConfig( mOAuthConfigCustom );
354+
loadFromOAuthConfig( mOAuthConfigCustom.get() );
365355
}
366356

367357
// slot
@@ -571,16 +561,11 @@ void QgsAuthOAuth2Edit::getDefinedCustomDir()
571561

572562
void QgsAuthOAuth2Edit::initConfigObjs()
573563
{
574-
mOAuthConfigCustom = new QgsAuthOAuth2Config( this );
564+
mOAuthConfigCustom = qgis::make_unique<QgsAuthOAuth2Config>( nullptr );
575565
mOAuthConfigCustom->setConfigType( QgsAuthOAuth2Config::Custom );
576566
mOAuthConfigCustom->setToDefaults();
577567
}
578568

579-
void QgsAuthOAuth2Edit::deleteConfigObjs()
580-
{
581-
delete mOAuthConfigCustom;
582-
mOAuthConfigCustom = nullptr;
583-
}
584569

585570
bool QgsAuthOAuth2Edit::hasTokenCacheFile()
586571
{
@@ -710,25 +695,29 @@ void QgsAuthOAuth2Edit::updateGrantFlow( int indx )
710695

711696
lblRequestUrl->setVisible( !resowner );
712697
leRequestUrl->setVisible( !resowner );
713-
if ( resowner ) leRequestUrl->setText( QString() );
698+
if ( resowner )
699+
leRequestUrl->setText( QString() );
714700

715701
lblRedirectUrl->setVisible( !resowner );
716702
frameRedirectUrl->setVisible( !resowner );
717703

718704
lblClientSecret->setVisible( !implicit );
719705
leClientSecret->setVisible( !implicit );
720-
if ( implicit ) leClientSecret->setText( QString() );
706+
if ( implicit )
707+
leClientSecret->setText( QString() );
721708

722709
leClientId->setPlaceholderText( resowner ? tr( "Optional" ) : tr( "Required" ) );
723710
leClientSecret->setPlaceholderText( resowner ? tr( "Optional" ) : tr( "Required" ) );
724711

725712

726713
lblUsername->setVisible( resowner );
727714
leUsername->setVisible( resowner );
728-
if ( !resowner ) leUsername->setText( QString() );
715+
if ( !resowner )
716+
leUsername->setText( QString() );
729717
lblPassword->setVisible( resowner );
730718
lePassword->setVisible( resowner );
731-
if ( !resowner ) lePassword->setText( QString() );
719+
if ( !resowner )
720+
lePassword->setText( QString() );
732721
}
733722

734723
// slot
@@ -762,7 +751,7 @@ void QgsAuthOAuth2Edit::exportOAuthConfig()
762751
mOAuthConfigCustom->setName( mParentName->text() );
763752
}
764753

765-
if ( !QgsAuthOAuth2Config::writeOAuth2Config( configpath, mOAuthConfigCustom,
754+
if ( !QgsAuthOAuth2Config::writeOAuth2Config( configpath, mOAuthConfigCustom.get(),
766755
QgsAuthOAuth2Config::JSON, true ) )
767756
{
768757
QgsDebugMsg( QStringLiteral( "FAILED to export OAuth2 config file" ) );

‎src/auth/oauth2/qgsauthoauth2edit.h

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,39 @@
2323
#include "qgsauthoauth2config.h"
2424

2525

26+
/**
27+
* The QgsAuthOAuth2Edit class allows editing of an OAuth2 authentication configuration
28+
* \ingroup auth_plugins
29+
*/
2630
class QgsAuthOAuth2Edit : public QgsAuthMethodEdit, private Ui::QgsAuthOAuth2Edit
2731
{
2832
Q_OBJECT
2933

3034
public:
3135
explicit QgsAuthOAuth2Edit( QWidget *parent = nullptr );
32-
virtual ~QgsAuthOAuth2Edit();
36+
virtual ~QgsAuthOAuth2Edit() = default;
3337

38+
/**
39+
* Validate current configuration
40+
* \return true if current configuration is valid
41+
*/
3442
bool validateConfig() override;
3543

44+
/**
45+
* Current configuration
46+
* \return current configuration map
47+
*/
3648
QgsStringMap configMap() const override;
3749

3850
public slots:
51+
52+
//! Load the configuration from \a configMap
3953
void loadConfig( const QgsStringMap &configmap ) override;
4054

55+
//! Reset configuration to defaults
4156
void resetConfig() override;
4257

58+
//! Clear configuration
4359
void clearConfig() override;
4460

4561
private slots:
@@ -91,7 +107,6 @@ class QgsAuthOAuth2Edit : public QgsAuthMethodEdit, private Ui::QgsAuthOAuth2Edi
91107
QString parentConfigId() const;
92108

93109
void initConfigObjs();
94-
void deleteConfigObjs();
95110

96111
bool hasTokenCacheFile();
97112

@@ -105,15 +120,15 @@ class QgsAuthOAuth2Edit : public QgsAuthMethodEdit, private Ui::QgsAuthOAuth2Edi
105120

106121
QString currentDefinedConfig() const { return mDefinedId; }
107122

108-
QgsAuthOAuth2Config *mOAuthConfigCustom;
123+
std::unique_ptr<QgsAuthOAuth2Config> mOAuthConfigCustom;
109124
QgsStringMap mDefinedConfigsCache;
110125
QString mDefinedId;
111-
QLineEdit *mParentName;
126+
QLineEdit *mParentName = nullptr;
112127
QgsStringMap mConfigMap;
113-
bool mValid;
114-
int mCurTab;
115-
bool mPrevPersistToken;
116-
QToolButton *btnTokenClear;
128+
bool mValid = false;
129+
int mCurTab = 0;
130+
bool mPrevPersistToken = false;
131+
QToolButton *btnTokenClear = nullptr;
117132
};
118133

119134
#endif // QGSAUTHOAUTH2EDIT_H

‎src/auth/oauth2/qgsauthoauth2method.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727

2828
class QgsO2;
2929

30+
/**
31+
* The QgsAuthOAuth2Method class handles all network connection operation for the OAuth2 authentication plugin
32+
* \ingroup auth_plugins
33+
*/
3034
class QgsAuthOAuth2Method : public QgsAuthMethod
3135
{
3236
Q_OBJECT
@@ -35,35 +39,51 @@ class QgsAuthOAuth2Method : public QgsAuthMethod
3539
explicit QgsAuthOAuth2Method();
3640
~QgsAuthOAuth2Method();
3741

38-
// QgsAuthMethod interface
42+
//! OAuth2 method key
3943
QString key() const override;
4044

45+
//! OAuth2 method description
4146
QString description() const override;
4247

48+
//! Human readable description
4349
QString displayDescription() const override;
4450

51+
//! Update network \a request with given \a authcfg and optional \a dataprovider
4552
bool updateNetworkRequest( QNetworkRequest &request, const QString &authcfg,
4653
const QString &dataprovider = QString() ) override;
4754

55+
//! Update network \a reply with given \a authcfg and optional \a dataprovider
4856
bool updateNetworkReply( QNetworkReply *reply, const QString &authcfg,
4957
const QString &dataprovider ) override;
5058

59+
//! Update data source \a connectionItems with given \a authcfg and optional \a dataprovider
5160
bool updateDataSourceUriItems( QStringList &connectionItems, const QString &authcfg,
5261
const QString &dataprovider = QString() ) override;
5362

63+
//! Clear cached configuration for given \a authcfg
5464
void clearCachedConfig( const QString &authcfg ) override;
5565

66+
//! Update OAuth2 method configuration with \a config
5667
void updateMethodConfig( QgsAuthMethodConfig &mconfig ) override;
5768

5869
public slots:
70+
71+
//! Triggered when linked condition has changed
5972
void onLinkedChanged();
73+
//! Triggered when linking operation failed
6074
void onLinkingFailed();
75+
//! Triggered when linking operation succeeded
6176
void onLinkingSucceeded();
6277

78+
//! Triggered when the browser needs to be opened at \a url
6379
void onOpenBrowser( const QUrl &url );
80+
//! Triggered on browser close
6481
void onCloseBrowser();
82+
//! Triggered on reply finished
6583
void onReplyFinished();
84+
//! Triggered on network error
6685
void onNetworkError( QNetworkReply::NetworkError err );
86+
//! Triggered on refresh finished
6787
void onRefreshFinished( QNetworkReply::NetworkError err );
6888

6989
private:

‎src/auth/oauth2/qgso2.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,27 @@ class QgsO2: public O2
2929
Q_OBJECT
3030

3131
public:
32+
33+
/**
34+
* Construct QgsO2
35+
* \param authcfg authentication configuration id
36+
* \param oauth2config OAuth2 configuration
37+
* \param parent
38+
* \param manager QGIS network access manager instance
39+
*/
3240
explicit QgsO2( const QString &authcfg, QgsAuthOAuth2Config *oauth2config = nullptr,
3341
QObject *parent = nullptr, QNetworkAccessManager *manager = nullptr );
3442

3543
~QgsO2();
3644

45+
//! Authentication configuration id
3746
QString authcfg() const { return mAuthcfg; }
47+
//! OAuth2 configuration
3848
QgsAuthOAuth2Config *oauth2config() { return mOAuth2Config; }
3949

4050
public slots:
51+
52+
//! Clear all properties
4153
void clearProperties();
4254

4355
private:

0 commit comments

Comments
 (0)
Please sign in to comment.