Skip to content
Permalink
Browse files

Merge pull request #7441 from elpaso/oauth2-testbed13-client-registra…

…tion

[oauth] JWT client registration
  • Loading branch information
elpaso committed Jul 24, 2018
2 parents e6b1e48 + fbe05be commit a9f924fcb2ccfd60e947144864f8dc8595b9d92c

Large diffs are not rendered by default.

@@ -16,6 +16,7 @@
#define QGSAUTHOAUTH2EDIT_H

#include <QWidget>
#include <QNetworkReply>
#include "qgsauthmethodedit.h"
#include "ui_qgsauthoauth2edit.h"

@@ -49,6 +50,7 @@ class QgsAuthOAuth2Edit : public QgsAuthMethodEdit, private Ui::QgsAuthOAuth2Edi
*/
QgsStringMap configMap() const override;


public slots:

//! Load the configuration from \a configMap
@@ -68,30 +70,42 @@ class QgsAuthOAuth2Edit : public QgsAuthMethodEdit, private Ui::QgsAuthOAuth2Edi
void removeTokenCacheFile();

void populateGrantFlows();

void updateGrantFlow( int indx );

void exportOAuthConfig();

void importOAuthConfig();

void descriptionChanged();

void populateAccessMethods();

void updateConfigAccessMethod( int indx );

void addQueryPair();

void removeQueryPair();

void clearQueryPairs();

void populateQueryPairs( const QVariantMap &querypairs, bool append = false );

void queryTableSelectionChanged();

void updateConfigQueryPairs();

void updateDefinedConfigsCache();

void loadDefinedConfigs();

void setCurrentDefinedConfig( const QString &id );

void currentDefinedItemChanged( QListWidgetItem *cur, QListWidgetItem *prev );

void selectCurrentDefinedConfig();

void loadFromOAuthConfig( const QgsAuthOAuth2Config *config = nullptr );
void getSoftStatementDir();

void updateTokenCacheFile( bool curpersist ) const;

@@ -101,8 +115,20 @@ class QgsAuthOAuth2Edit : public QgsAuthMethodEdit, private Ui::QgsAuthOAuth2Edi

void getDefinedCustomDir();

void loadFromOAuthConfig( const QgsAuthOAuth2Config *config );

void softwareStatementJwtPathChanged( const QString &path );

void configReplyFinished();

void registerReplyFinished();

void networkError( QNetworkReply::NetworkError error );

private:

void initGui();
void parseSoftwareStatement( const QString &path );

QWidget *parentWidget() const;
QLineEdit *parentNameField() const;
@@ -117,8 +143,11 @@ class QgsAuthOAuth2Edit : public QgsAuthMethodEdit, private Ui::QgsAuthOAuth2Edi

int customTab() const { return 0; }
int definedTab() const { return 1; }
int statementTab() const { return 2; }
bool onCustomTab() const;
bool onDefinedTab() const;
bool onStatementTab() const;
void getSoftwareStatementConfig();

QString currentDefinedConfig() const { return mDefinedId; }

@@ -131,6 +160,11 @@ class QgsAuthOAuth2Edit : public QgsAuthMethodEdit, private Ui::QgsAuthOAuth2Edi
int mCurTab = 0;
bool mPrevPersistToken = false;
QToolButton *btnTokenClear = nullptr;
QString mRegistrationEndpoint;
QMap<QString, QVariant> mSoftwareStatement;
void registerSoftStatement( const QString &registrationUrl );
bool mDownloading = false;
friend class TestQgsAuthOAuth2Method;
};

#endif // QGSAUTHOAUTH2EDIT_H
@@ -75,7 +75,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tabCustom">
<attribute name="title">
@@ -202,7 +202,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-241</y>
<y>0</y>
<width>401</width>
<height>516</height>
</rect>
@@ -734,6 +734,85 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabStatement">
<attribute name="title">
<string>Software Statement</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="spacing">
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="0">
<widget class="QLabel" name="lblSoftStatementDir">
<property name="text">
<string>Software Statement</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leSoftwareStatementConfigUrl">
<property name="placeholderText">
<string>Optional</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="btnSoftStatementDir">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="oauth2_resources.qrc">
<normaloff>:/oauth2method/oauth2_resources/fileopen.svg</normaloff>:/oauth2method/oauth2_resources/fileopen.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblConfigUrl">
<property name="text">
<string>Configuration Url</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="leSoftwareStatementJwtPath">
<property name="placeholderText">
<string>Required</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="btnRegister">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Register</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
<widget class="QgsCollapsibleGroupBoxBasic" name="grpbxAdvanced">
<property name="sizePolicy">
@@ -29,6 +29,7 @@
#include "qgssettings.h"

#include <QDateTime>
#include <QInputDialog>
#include <QDesktopServices>
#include <QDir>
#include <QEventLoop>
@@ -172,7 +173,8 @@ bool QgsAuthOAuth2Method::updateNetworkRequest( QNetworkRequest &request, const
connect( o2, &QgsO2::linkingSucceeded, this, &QgsAuthOAuth2Method::onLinkingSucceeded, Qt::UniqueConnection );
connect( o2, &QgsO2::openBrowser, this, &QgsAuthOAuth2Method::onOpenBrowser, Qt::UniqueConnection );
connect( o2, &QgsO2::closeBrowser, this, &QgsAuthOAuth2Method::onCloseBrowser, Qt::UniqueConnection );

connect( o2, &QgsO2::getAuthCode, this, &QgsAuthOAuth2Method::onAuthCode, Qt::UniqueConnection );
connect( this, &QgsAuthOAuth2Method::setAuthCode, o2, &QgsO2::onSetAuthCode, Qt::UniqueConnection );
//qRegisterMetaType<QNetworkReply::NetworkError>( QStringLiteral( "QNetworkReply::NetworkError" )) // for Qt::QueuedConnection, if needed;
connect( o2, &QgsO2::refreshFinished, this, &QgsAuthOAuth2Method::onRefreshFinished, Qt::UniqueConnection );

@@ -457,6 +459,16 @@ void QgsAuthOAuth2Method::onRefreshFinished( QNetworkReply::NetworkError err )
}
}

void QgsAuthOAuth2Method::onAuthCode()
{
bool ok = false;
QString code = QInputDialog::getText( QApplication::activeWindow(), QStringLiteral( "Enter the authorization code" ), QStringLiteral( "Authoriation code" ), QLineEdit::Normal, QStringLiteral( "Required" ), &ok, Qt::Dialog, Qt::InputMethodHint::ImhNone );
if ( ok && !code.isEmpty() )
{
emit setAuthCode( code );
}
}

bool QgsAuthOAuth2Method::updateDataSourceUriItems( QStringList &connectionItems, const QString &authcfg,
const QString &dataprovider )
{
@@ -71,22 +71,36 @@ class QgsAuthOAuth2Method : public QgsAuthMethod

//! Triggered when linked condition has changed
void onLinkedChanged();

//! Triggered when linking operation failed
void onLinkingFailed();

//! Triggered when linking operation succeeded
void onLinkingSucceeded();

//! Triggered when the browser needs to be opened at \a url
void onOpenBrowser( const QUrl &url );

//! Triggered on browser close
void onCloseBrowser();

//! Triggered on reply finished
void onReplyFinished();

//! Triggered on network error
void onNetworkError( QNetworkReply::NetworkError err );

//! Triggered on refresh finished
void onRefreshFinished( QNetworkReply::NetworkError err );

//! Triggered when auth code needs to be manually entered by the user
void onAuthCode();

signals:

//! Emitted when authcode was manually set by the user
void setAuthCode( const QString code );

private:
QString mTempStorePath;

@@ -144,6 +144,12 @@ void QgsO2::clearProperties()
// TODO: clear object properties
}

void QgsO2::onSetAuthCode( const QString &code )
{
setCode( code );
onVerificationReceived( QMap<QString, QString>() );
}

void QgsO2::link()
{
QgsDebugMsgLevel( QStringLiteral( "QgsO2::link" ), 4 );
@@ -222,7 +228,7 @@ void QgsO2::link()

QUrl url( tokenUrl_ );
QNetworkRequest tokenRequest( url );
tokenRequest.setHeader( QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded" );
tokenRequest.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1Literal( "application/x-www-form-urlencoded" ) );
QNetworkReply *tokenReply = manager_->post( tokenRequest, payload );

connect( tokenReply, SIGNAL( finished() ), this, SLOT( onTokenReplyFinished() ), Qt::QueuedConnection );
@@ -63,6 +63,9 @@ class QgsO2: public O2
//! Clear all properties
void clearProperties();

//! Triggered when auth code was set
void onSetAuthCode( const QString &code );

//! Authenticate.
void link() override;

0 comments on commit a9f924f

Please sign in to comment.
You can’t perform that action at this time.