From bdad3ffe4d076c0d4c07509efe21e05e698a91ea Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Sun, 23 Feb 2020 14:24:01 +0800 Subject: [PATCH] Add support for okta saml login --- GPClient/gpclient.cpp | 14 +++++--------- GPClient/gpclient.h | 2 +- GPClient/samlloginwindow.cpp | 8 ++++++-- GPClient/samlloginwindow.h | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/GPClient/gpclient.cpp b/GPClient/gpclient.cpp index 9b29f57..93cdfda 100644 --- a/GPClient/gpclient.cpp +++ b/GPClient/gpclient.cpp @@ -80,13 +80,13 @@ void GPClient::preloginResultFinished() return; } - QByteArray bytes = reply->readAll(); + QByteArray xmlBytes = reply->readAll(); const QString tagMethod = "saml-auth-method"; const QString tagRequest = "saml-request"; QString samlMethod; QString samlRequest; - QXmlStreamReader xml(bytes); + QXmlStreamReader xml(xmlBytes); while (!xml.atEnd()) { xml.readNext(); if (xml.tokenType() == xml.StartElement) { @@ -105,11 +105,7 @@ void GPClient::preloginResultFinished() } if (samlMethod == "POST") { - // TODO - emit connectFailed(); - QMessageBox msgBox; - msgBox.setText("TODO: SAML method is POST"); - msgBox.exec(); + samlLogin(reply->url().toString(), samlRequest); } else if (samlMethod == "REDIRECT") { samlLogin(samlRequest); } @@ -214,14 +210,14 @@ void GPClient::doAuth(const QString portal) connect(reply, &QNetworkReply::finished, this, &GPClient::preloginResultFinished); } -void GPClient::samlLogin(const QString loginUrl) +void GPClient::samlLogin(const QString loginUrl, const QString html) { SAMLLoginWindow *loginWindow = new SAMLLoginWindow(this); QObject::connect(loginWindow, &SAMLLoginWindow::success, this, &GPClient::onLoginSuccess); QObject::connect(loginWindow, &SAMLLoginWindow::rejected, this, &GPClient::connectFailed); - loginWindow->login(loginUrl); + loginWindow->login(loginUrl, html); loginWindow->exec(); delete loginWindow; } diff --git a/GPClient/gpclient.h b/GPClient/gpclient.h index 1d5b986..3bc771c 100644 --- a/GPClient/gpclient.h +++ b/GPClient/gpclient.h @@ -42,6 +42,6 @@ private: void moveCenter(); void updateConnectionStatus(QString status); void doAuth(const QString portal); - void samlLogin(const QString loginUrl); + void samlLogin(const QString loginUrl, const QString html = ""); }; #endif // GPCLIENT_H diff --git a/GPClient/samlloginwindow.cpp b/GPClient/samlloginwindow.cpp index 189baa1..60b299a 100644 --- a/GPClient/samlloginwindow.cpp +++ b/GPClient/samlloginwindow.cpp @@ -27,9 +27,13 @@ void SAMLLoginWindow::closeEvent(QCloseEvent *event) reject(); } -void SAMLLoginWindow::login(QString url) +void SAMLLoginWindow::login(QString url, QString html) { - webView->load(QUrl(url)); + if (html == "") { + webView->load(QUrl(url)); + } else { + webView->setHtml(html, url); + } } void SAMLLoginWindow::onResponseReceived(QJsonObject params) diff --git a/GPClient/samlloginwindow.h b/GPClient/samlloginwindow.h index 5e6dad1..6279e6f 100644 --- a/GPClient/samlloginwindow.h +++ b/GPClient/samlloginwindow.h @@ -15,7 +15,7 @@ public: explicit SAMLLoginWindow(QWidget *parent = nullptr); ~SAMLLoginWindow(); - void login(QString url); + void login(QString url, QString html = ""); signals: void success(QJsonObject samlResult);