mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
handle html comment for saml result with okta 2fa (#156)
This commit is contained in:
parent
5714063457
commit
5db77e8404
@ -22,6 +22,7 @@ SAMLLoginWindow::SAMLLoginWindow(QWidget *parent)
|
|||||||
webView->initialize();
|
webView->initialize();
|
||||||
connect(webView, &EnhancedWebView::responseReceived, this, &SAMLLoginWindow::onResponseReceived);
|
connect(webView, &EnhancedWebView::responseReceived, this, &SAMLLoginWindow::onResponseReceived);
|
||||||
connect(webView, &EnhancedWebView::loadFinished, this, &SAMLLoginWindow::onLoadFinished);
|
connect(webView, &EnhancedWebView::loadFinished, this, &SAMLLoginWindow::onLoadFinished);
|
||||||
|
connect(this, SIGNAL(getHTML(QString)), this, SLOT(handleHTML(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
SAMLLoginWindow::~SAMLLoginWindow()
|
SAMLLoginWindow::~SAMLLoginWindow()
|
||||||
@ -64,6 +65,11 @@ void SAMLLoginWindow::onResponseReceived(QJsonObject params)
|
|||||||
|
|
||||||
LOGI << "Response received from " << response.value("url").toString();
|
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()) {
|
if (!username.isEmpty()) {
|
||||||
LOGI << "Got username from SAML response headers " << username;
|
LOGI << "Got username from SAML response headers " << username;
|
||||||
samlResult.insert("username", username);
|
samlResult.insert("username", username);
|
||||||
@ -97,4 +103,29 @@ void SAMLLoginWindow::onResponseReceived(QJsonObject params)
|
|||||||
void SAMLLoginWindow::onLoadFinished()
|
void SAMLLoginWindow::onLoadFinished()
|
||||||
{
|
{
|
||||||
LOGI << "Load finished " << this->webView->page()->url().toString();
|
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("<saml-auth-status>(.*)</saml-auth-status>");
|
||||||
|
const QRegularExpressionMatch match = regex.match(sHTML);
|
||||||
|
const QString samlAuthStatusOnBody = match.captured(1);
|
||||||
|
|
||||||
|
if (samlAuthStatusOnBody == "1") {
|
||||||
|
const QRegularExpression preloginCookieRegex("<prelogin-cookie>(.*)</prelogin-cookie>");
|
||||||
|
const QRegularExpressionMatch preloginCookieMatch = preloginCookieRegex.match(sHTML);
|
||||||
|
const QString preloginCookie = preloginCookieMatch.captured(1);
|
||||||
|
|
||||||
|
const QRegularExpression usernameRegex("<saml-username>(.*)</saml-username>");
|
||||||
|
const QRegularExpressionMatch usernameMatch = usernameRegex.match(sHTML);
|
||||||
|
const QString username = usernameMatch.captured(1);
|
||||||
|
|
||||||
|
const QRegularExpression userAuthCookieRegex("<portal-userauthcookie>(.*)</portal-userauthcookie>");
|
||||||
|
const QRegularExpressionMatch userAuthCookieMatch = userAuthCookieRegex.match(sHTML);
|
||||||
|
const QString userAuthCookie = userAuthCookieMatch.captured(1);
|
||||||
|
|
||||||
|
this->checkSamlResult(username, preloginCookie, userAuthCookie);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,15 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void success(QMap<QString, QString> samlResult);
|
void success(QMap<QString, QString> samlResult);
|
||||||
void fail(const QString msg);
|
void fail(const QString msg);
|
||||||
|
void getHTML(QString sHTML);
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void handleHTML(QString sHTML);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onResponseReceived(QJsonObject params);
|
void onResponseReceived(QJsonObject params);
|
||||||
void onLoadFinished();
|
void onLoadFinished();
|
||||||
|
void checkSamlResult(QString username, QString preloginCookie, QString userAuthCookie);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EnhancedWebView *webView;
|
EnhancedWebView *webView;
|
||||||
|
Loading…
Reference in New Issue
Block a user