mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-05-20 07:26:58 -04:00
Code refactor, support multiple gateways and non-SAML authentication (#9)
* Code refactor * Update README.md
This commit is contained in:
@@ -1,19 +1,24 @@
|
||||
#include "samlloginwindow.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <plog/Log.h>
|
||||
#include <QWebEngineProfile>
|
||||
|
||||
SAMLLoginWindow::SAMLLoginWindow(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setWindowTitle("SAML Login");
|
||||
resize(610, 406);
|
||||
setWindowTitle("GlobalProtect SAML Login");
|
||||
resize(700, 550);
|
||||
|
||||
QVBoxLayout *verticalLayout = new QVBoxLayout(this);
|
||||
webView = new EnhancedWebView(this);
|
||||
webView->setUrl(QUrl("about:blank"));
|
||||
// webView->page()->profile()->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
|
||||
verticalLayout->addWidget(webView);
|
||||
|
||||
webView->initialize();
|
||||
QObject::connect(webView, &EnhancedWebView::responseReceived, this, &SAMLLoginWindow::onResponseReceived);
|
||||
connect(webView, &EnhancedWebView::responseReceived, this, &SAMLLoginWindow::onResponseReceived);
|
||||
connect(webView, &EnhancedWebView::loadFinished, this, &SAMLLoginWindow::onLoadFinished);
|
||||
}
|
||||
|
||||
SAMLLoginWindow::~SAMLLoginWindow()
|
||||
@@ -29,7 +34,7 @@ void SAMLLoginWindow::closeEvent(QCloseEvent *event)
|
||||
|
||||
void SAMLLoginWindow::login(QString url, QString html)
|
||||
{
|
||||
if (html == "") {
|
||||
if (html.isEmpty()) {
|
||||
webView->load(QUrl(url));
|
||||
} else {
|
||||
webView->setHtml(html, url);
|
||||
@@ -47,17 +52,24 @@ void SAMLLoginWindow::onResponseReceived(QJsonObject params)
|
||||
QJsonObject response = params.value("response").toObject();
|
||||
QJsonObject headers = response.value("headers").toObject();
|
||||
|
||||
foreach (const QString& key, headers.keys()) {
|
||||
if (key.startsWith("saml-") || key == "prelogin-cookie" || key == "portal-userauthcookie") {
|
||||
samlResult.insert(key, headers.value(key));
|
||||
}
|
||||
}
|
||||
const QString username = headers.value("saml-username").toString();
|
||||
const QString preloginCookie = headers.value("prelogin-cookie").toString();
|
||||
|
||||
// Check the SAML result
|
||||
if (samlResult.contains("saml-username")
|
||||
&& (samlResult.contains("prelogin-cookie") || samlResult.contains("portal-userauthcookie"))) {
|
||||
samlResult.insert("server", QUrl(response.value("url").toString()).authority());
|
||||
emit success(samlResult);
|
||||
accept();
|
||||
if (!username.isEmpty() && !preloginCookie.isEmpty()) {
|
||||
samlResult.insert("username", username);
|
||||
samlResult.insert("preloginCookie", preloginCookie);
|
||||
}
|
||||
}
|
||||
|
||||
void SAMLLoginWindow::onLoadFinished()
|
||||
{
|
||||
LOGI << "Load finished " << this->webView->page()->url().toString();
|
||||
|
||||
// Check the SAML result
|
||||
if (!samlResult.value("username").isEmpty() && !samlResult.value("preloginCookie").isEmpty()) {
|
||||
emit success(samlResult);
|
||||
accept();
|
||||
} else {
|
||||
open();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user