22
22
23
23
#include " qgis.h"
24
24
25
-
25
+ /* *
26
+ * The QgsAuthOAuth2Config class stores the configuration for OAuth2 authentication plugin
27
+ * \ingroup auth_plugins
28
+ */
26
29
class QgsAuthOAuth2Config : public QObject
27
30
{
28
31
Q_OBJECT
29
32
Q_ENUMS ( ConfigType )
30
33
Q_ENUMS ( GrantFlow )
31
34
Q_ENUMS ( ConfigFormat )
32
35
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 )
33
58
34
59
public:
35
60
61
+ // ! Configuration type
36
62
enum ConfigType
37
63
{
38
64
Predefined,
39
65
Custom,
40
66
};
41
67
68
+ // ! OAuth2 grant flow
42
69
enum GrantFlow
43
70
{
44
71
AuthCode, // !< @see http://tools.ietf.org/html/rfc6749#section-4.1
45
72
Implicit, // !< @see http://tools.ietf.org/html/rfc6749#section-4.2
46
73
ResourceOwner, // !< @see http://tools.ietf.org/html/rfc6749#section-4.3
47
74
};
48
75
76
+ // ! Configuration format for serialize/unserialize operations
49
77
enum ConfigFormat
50
78
{
51
79
JSON,
52
80
};
53
81
82
+ // ! Access method
54
83
enum AccessMethod
55
84
{
56
85
Header,
@@ -60,94 +89,70 @@ class QgsAuthOAuth2Config : public QObject
60
89
61
90
explicit QgsAuthOAuth2Config ( QObject *parent = nullptr );
62
91
63
- ~QgsAuthOAuth2Config ();
64
-
65
92
// ! Unique ID
66
- Q_PROPERTY ( QString id READ id WRITE setId NOTIFY idChanged )
67
93
QString id () const { return mId ; }
68
94
69
95
// ! Increment this if method is significantly updated, allow updater code to be written
70
- Q_PROPERTY ( int version READ version WRITE setVersion NOTIFY versionChanged )
71
96
int version () const { return mVersion ; }
72
97
73
98
// ! Configuration type
74
- Q_PROPERTY ( ConfigType configType READ configType WRITE setConfigType NOTIFY configTypeChanged )
75
99
ConfigType configType () const { return mConfigType ; }
76
100
77
101
// ! Authorization flow
78
- Q_PROPERTY ( GrantFlow grantFlow READ grantFlow WRITE setGrantFlow NOTIFY grantFlowChanged )
79
102
GrantFlow grantFlow () const { return mGrantFlow ; }
80
103
81
104
// ! Configuration name
82
- Q_PROPERTY ( QString name READ name WRITE setName NOTIFY nameChanged )
83
105
QString name () const { return mName ; }
84
106
85
107
// ! Configuration description
86
- Q_PROPERTY ( QString description READ description WRITE setDescription NOTIFY descriptionChanged )
87
108
QString description () const { return mDescription ; }
88
109
89
- // !
90
- Q_PROPERTY ( QString requestUrl READ requestUrl WRITE setRequestUrl NOTIFY requestUrlChanged )
110
+ // ! Request url
91
111
QString requestUrl () const { return mRequestUrl ; }
92
112
93
- // !
94
- Q_PROPERTY ( QString tokenUrl READ tokenUrl WRITE setTokenUrl NOTIFY tokenUrlChanged )
113
+ // ! Token url
95
114
QString tokenUrl () const { return mTokenUrl ; }
96
115
97
- // !
98
- Q_PROPERTY ( QString refreshTokenUrl READ refreshTokenUrl WRITE setRefreshTokenUrl NOTIFY refreshTokenUrlChanged )
116
+ // ! Refresh token url
99
117
QString refreshTokenUrl () const { return mRefreshTokenUrl ; }
100
118
101
- // !
102
- Q_PROPERTY ( QString redirectUrl READ redirectUrl WRITE setRedirectUrl NOTIFY redirectUrlChanged )
119
+ // ! Redirect url
103
120
QString redirectUrl () const { return mRedirectURL ; }
104
121
105
- // !
106
- Q_PROPERTY ( int redirectPort READ redirectPort WRITE setRedirectPort NOTIFY redirectPortChanged )
122
+ // ! Redirect port
107
123
int redirectPort () const { return mRedirectPort ; }
108
124
109
- // !
110
- Q_PROPERTY ( QString clientId READ clientId WRITE setClientId NOTIFY clientIdChanged )
125
+ // ! Client id
111
126
QString clientId () const { return mClientId ; }
112
127
113
- // !
114
- Q_PROPERTY ( QString clientSecret READ clientSecret WRITE setClientSecret NOTIFY clientSecretChanged )
128
+ // ! Client secret
115
129
QString clientSecret () const { return mClientSecret ; }
116
130
117
131
// ! Resource owner username
118
- Q_PROPERTY ( QString username READ username WRITE setUsername NOTIFY usernameChanged )
119
132
QString username () const { return mUsername ; }
120
133
121
134
// ! Resource owner password
122
- Q_PROPERTY ( QString password READ password WRITE setPassword NOTIFY passwordChanged )
123
135
QString password () const { return mPassword ; }
124
136
125
137
// ! Scope of authentication
126
- Q_PROPERTY ( QString scope READ scope WRITE setScope NOTIFY scopeChanged )
127
138
QString scope () const { return mScope ; }
128
139
129
140
// ! State passed with request
130
- Q_PROPERTY ( QString state READ state WRITE setState NOTIFY stateChanged )
131
141
QString state () const { return mState ; }
132
142
133
- // !
134
- Q_PROPERTY ( QString apiKey READ apiKey WRITE setApiKey NOTIFY apiKeyChanged )
143
+ // ! API key
135
144
QString apiKey () const { return mApiKey ; }
136
145
137
- // !
138
- Q_PROPERTY ( bool persistToken READ persistToken WRITE setPersistToken NOTIFY persistTokenChanged )
146
+ // ! Return true if the token is persistant
139
147
bool persistToken () const { return mPersistToken ; }
140
148
141
- // !
142
- Q_PROPERTY ( AccessMethod accessMethod READ accessMethod WRITE setAccessMethod NOTIFY accessMethodChanged )
149
+ // ! Access method
143
150
AccessMethod accessMethod () const { return mAccessMethod ; }
144
151
145
- // !
146
- Q_PROPERTY ( int requestTimeout READ requestTimeout WRITE setRequestTimeout NOTIFY requestTimeoutChanged )
152
+ // ! Request timeout
147
153
int requestTimeout () const { return mRequestTimeout ; }
148
154
149
- // !
150
- Q_PROPERTY ( QVariantMap queryPairs READ queryPairs WRITE setQueryPairs NOTIFY queryPairsChanged )
155
+ // ! Query pairs
151
156
QVariantMap queryPairs () const { return mQueryPairs ; }
152
157
153
158
// ! Operator used to compare configs' equality
@@ -159,7 +164,7 @@ class QgsAuthOAuth2Config : public QObject
159
164
// ! Check whether config is valid, then return it
160
165
bool isValid () const ;
161
166
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
163
168
void validateConfigId ( bool needsId = false );
164
169
165
170
// ! Load a string (e.g. JSON) of a config
@@ -168,16 +173,29 @@ class QgsAuthOAuth2Config : public QObject
168
173
// ! Save a config to a string (e.g. JSON)
169
174
QByteArray saveConfigTxt ( ConfigFormat format = JSON, bool pretty = false , bool *ok = nullptr ) const ;
170
175
171
- // !
176
+ // ! Return the configuration as a QVariant map
172
177
QVariantMap mappedProperties () const ;
173
178
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
+ */
175
187
static QByteArray serializeFromVariant ( const QVariantMap &variant,
176
188
ConfigFormat format = JSON,
177
189
bool pretty = false ,
178
190
bool *ok = nullptr );
179
191
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
+ */
181
199
static QVariantMap variantFromSerialized ( const QByteArray &serial,
182
200
ConfigFormat format = JSON,
183
201
bool *ok = nullptr );
@@ -205,112 +223,157 @@ class QgsAuthOAuth2Config : public QObject
205
223
// ! Load and parse standard directories of configs (e.g. JSON) to a mapped cache
206
224
static QgsStringMap mappedOAuth2ConfigsCache ( QObject *parent, const QString &extradir = QString::null );
207
225
208
- // !
226
+ // ! Path where config is stored
209
227
static QString oauth2ConfigsPkgDataDir ();
210
228
211
- // !
229
+ // ! Path where user settings are stored
212
230
static QString oauth2ConfigsUserSettingsDir ();
213
231
214
- // !
232
+ // ! User readable name of the \a configtype
215
233
static QString configTypeString ( ConfigType configtype );
216
234
217
- // !
235
+ // ! User readable name of the grant \a flow
218
236
static QString grantFlowString ( GrantFlow flow );
219
237
220
- // !
238
+ // ! User readable name of the access \a method
221
239
static QString accessMethodString ( AccessMethod method );
222
240
223
- // !
241
+ // ! Path of the token cache \a temporary directory
224
242
static QString tokenCacheDirectory ( bool temporary = false );
225
243
226
- // !
244
+ // ! Path of the token cache file, with optional \a suffix
227
245
static QString tokenCacheFile ( const QString &suffix = QString::null );
228
246
229
- // !
247
+ // ! Path of the token cache file, with optional \a suffix and \a temporary flag
230
248
static QString tokenCachePath ( const QString &suffix = QString::null, bool temporary = false );
231
249
232
250
public slots:
251
+ // ! Set the id to \a value
233
252
void setId ( const QString &value );
253
+ // ! Set version to \a value
234
254
void setVersion ( int value );
255
+ // ! Set config type to \a value
235
256
void setConfigType ( ConfigType value );
257
+ // ! Set grant flow to \a value
236
258
void setGrantFlow ( GrantFlow value );
259
+ // ! Set name to \a value
237
260
void setName ( const QString &value );
261
+ // ! Set description to \a value
238
262
void setDescription ( const QString &value );
263
+ // ! Set request url to \a value
239
264
void setRequestUrl ( const QString &value );
265
+ // ! Set token url to \a value
240
266
void setTokenUrl ( const QString &value );
267
+ // ! Set refresh token url to \a value
241
268
void setRefreshTokenUrl ( const QString &value );
269
+ // ! Set redirect url to \a value
242
270
void setRedirectUrl ( const QString &value );
271
+ // ! Set redirect port to \a value
243
272
void setRedirectPort ( int value );
273
+ // ! Set client id to \a value
244
274
void setClientId ( const QString &value );
275
+ // ! Set client secret to \a value
245
276
void setClientSecret ( const QString &value );
277
+ // ! Set username to \a value
246
278
void setUsername ( const QString &value );
279
+ // ! Set password to \a value
247
280
void setPassword ( const QString &value );
281
+ // ! Set scope to \a value
248
282
void setScope ( const QString &value );
283
+ // ! Set state to \a value
249
284
void setState ( const QString &value );
285
+ // ! Set api key to \a value
250
286
void setApiKey ( const QString &value );
251
287
// advanced
288
+ // ! Set persistent token flag to \a persist
252
289
void setPersistToken ( bool persist );
290
+ // ! Set access method to \a value
253
291
void setAccessMethod ( AccessMethod value );
292
+ // ! Set request timeout to \a value
254
293
void setRequestTimeout ( int value );
294
+ // ! Set query pairs to \a pairs
255
295
void setQueryPairs ( const QVariantMap &pairs );
256
-
296
+ // ! Reset configuration to defaults
257
297
void setToDefaults ();
258
-
298
+ // ! Validate configuration
259
299
void validateConfig ();
260
300
261
301
signals:
302
+ // ! Emitted when configuration has changed
262
303
void configChanged ();
304
+ // ! Emitted when configuration id has changed
263
305
void idChanged ( const QString & );
306
+ // ! Emitted when configuration version has changed
264
307
void versionChanged ( int );
308
+ // ! Emitted when configuration type has changed
265
309
void configTypeChanged ( ConfigType );
310
+ // ! Emitted when configuration grant flow has changed
266
311
void grantFlowChanged ( GrantFlow );
312
+ // ! Emitted when configuration grant flow has changed
267
313
void nameChanged ( const QString & );
314
+ // ! Emitted when configuration name has changed
268
315
void descriptionChanged ( const QString & );
316
+ // ! Emitted when configuration request urlhas changed
269
317
void requestUrlChanged ( const QString & );
318
+ // ! Emitted when configuration token url has changed
270
319
void tokenUrlChanged ( const QString & );
320
+ // ! Emitted when configuration refresh token url has changed
271
321
void refreshTokenUrlChanged ( const QString & );
322
+ // ! Emitted when configuration redirect url has changed
272
323
void redirectUrlChanged ( const QString & );
324
+ // ! Emitted when configuration redirect port has changed
273
325
void redirectPortChanged ( int );
326
+ // ! Emitted when configuration client id has changed
274
327
void clientIdChanged ( const QString & );
328
+ // ! Emitted when configuration client secret has changed
275
329
void clientSecretChanged ( const QString & );
330
+ // ! Emitted when configuration username has changed
276
331
void usernameChanged ( const QString & );
332
+ // ! Emitted when configuration password has changed
277
333
void passwordChanged ( const QString & );
334
+ // ! Emitted when configuration scope has changed
278
335
void scopeChanged ( const QString & );
336
+ // ! Emitted when configuration state has changed
279
337
void stateChanged ( const QString & );
338
+ // ! Emitted when configuration API key has changed
280
339
void apiKeyChanged ( const QString & );
281
340
282
341
// advanced
342
+ // ! Emitted when configuration persiste token flag has changed
283
343
void persistTokenChanged ( bool );
344
+ // ! Emitted when configuration access method has changed
284
345
void accessMethodChanged ( AccessMethod );
346
+ // ! Emitted when configuration request timeout has changed
285
347
void requestTimeoutChanged ( int );
348
+ // ! Emitted when configuration query pair has changed
286
349
void queryPairsChanged ( const QVariantMap & );
287
-
350
+ // ! Emitted when configuration validity has changed
288
351
void validityChanged ( bool );
289
352
290
353
private:
291
354
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 ;
295
358
QString mName ;
296
359
QString mDescription ;
297
360
QString mRequestUrl ;
298
361
QString mTokenUrl ;
299
362
QString mRefreshTokenUrl ;
300
363
QString mRedirectURL ;
301
- int mRedirectPort ;
364
+ int mRedirectPort = 7070 ;
302
365
QString mClientId ;
303
366
QString mClientSecret ;
304
367
QString mUsername ;
305
368
QString mPassword ;
306
369
QString mScope ;
307
370
QString mState ;
308
371
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
312
375
QVariantMap mQueryPairs ;
313
- bool mValid ;
376
+ bool mValid = false ;
314
377
};
315
378
316
379
#endif // QGSAUTHOAUTH2CONFIG_H
0 commit comments