From 5db77e8404f79803813386340012cc0f7689f2ba Mon Sep 17 00:00:00 2001 From: Samar Dhwoj Acharya Date: Mon, 6 Jun 2022 00:39:06 -0500 Subject: [PATCH] handle html comment for saml result with okta 2fa (#156) --- GPClient/samlloginwindow.cpp | 31 +++++++++++++++++++++++++++++++ GPClient/samlloginwindow.h | 5 +++++ 2 files changed, 36 insertions(+) diff --git a/GPClient/samlloginwindow.cpp b/GPClient/samlloginwindow.cpp index 19c7b0d..0a93cfc 100644 --- a/GPClient/samlloginwindow.cpp +++ b/GPClient/samlloginwindow.cpp @@ -22,6 +22,7 @@ SAMLLoginWindow::SAMLLoginWindow(QWidget *parent) webView->initialize(); connect(webView, &EnhancedWebView::responseReceived, this, &SAMLLoginWindow::onResponseReceived); connect(webView, &EnhancedWebView::loadFinished, this, &SAMLLoginWindow::onLoadFinished); + connect(this, SIGNAL(getHTML(QString)), this, SLOT(handleHTML(QString))); } SAMLLoginWindow::~SAMLLoginWindow() @@ -64,6 +65,11 @@ void SAMLLoginWindow::onResponseReceived(QJsonObject params) LOGI << "Response received from " << response.value("url").toString(); + this->checkSamlResult(username, preloginCookie, userAuthCookie); +} + +void SAMLLoginWindow::checkSamlResult(QString username, QString preloginCookie, QString userAuthCookie) +{ if (!username.isEmpty()) { LOGI << "Got username from SAML response headers " << username; samlResult.insert("username", username); @@ -97,4 +103,29 @@ void SAMLLoginWindow::onResponseReceived(QJsonObject params) void SAMLLoginWindow::onLoadFinished() { LOGI << "Load finished " << this->webView->page()->url().toString(); + webView->page()->toHtml([this](const QString& result) mutable {emit getHTML(result);}); +} + +void SAMLLoginWindow::handleHTML(QString sHTML) +{ + // try to check the html body and extract from there + const QRegularExpression regex("(.*)"); + const QRegularExpressionMatch match = regex.match(sHTML); + const QString samlAuthStatusOnBody = match.captured(1); + + if (samlAuthStatusOnBody == "1") { + const QRegularExpression preloginCookieRegex("(.*)"); + const QRegularExpressionMatch preloginCookieMatch = preloginCookieRegex.match(sHTML); + const QString preloginCookie = preloginCookieMatch.captured(1); + + const QRegularExpression usernameRegex("(.*)"); + const QRegularExpressionMatch usernameMatch = usernameRegex.match(sHTML); + const QString username = usernameMatch.captured(1); + + const QRegularExpression userAuthCookieRegex("(.*)"); + const QRegularExpressionMatch userAuthCookieMatch = userAuthCookieRegex.match(sHTML); + const QString userAuthCookie = userAuthCookieMatch.captured(1); + + this->checkSamlResult(username, preloginCookie, userAuthCookie); + } } diff --git a/GPClient/samlloginwindow.h b/GPClient/samlloginwindow.h index 2d6bc79..7b76521 100644 --- a/GPClient/samlloginwindow.h +++ b/GPClient/samlloginwindow.h @@ -20,10 +20,15 @@ public: signals: void success(QMap samlResult); void fail(const QString msg); + void getHTML(QString sHTML); + +protected slots: + void handleHTML(QString sHTML); private slots: void onResponseReceived(QJsonObject params); void onLoadFinished(); + void checkSamlResult(QString username, QString preloginCookie, QString userAuthCookie); private: EnhancedWebView *webView;