mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-05-20 07:26:58 -04:00
Initial commit
This commit is contained in:
59
GPClient/samlloginwindow.cpp
Normal file
59
GPClient/samlloginwindow.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "samlloginwindow.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
SAMLLoginWindow::SAMLLoginWindow(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setWindowTitle("SAML Login");
|
||||
resize(610, 406);
|
||||
QVBoxLayout *verticalLayout = new QVBoxLayout(this);
|
||||
webView = new EnhancedWebView(this);
|
||||
webView->setUrl(QUrl("about:blank"));
|
||||
verticalLayout->addWidget(webView);
|
||||
|
||||
webView->initialize();
|
||||
QObject::connect(webView, &EnhancedWebView::responseReceived, this, &SAMLLoginWindow::onResponseReceived);
|
||||
}
|
||||
|
||||
SAMLLoginWindow::~SAMLLoginWindow()
|
||||
{
|
||||
delete webView;
|
||||
}
|
||||
|
||||
void SAMLLoginWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
reject();
|
||||
}
|
||||
|
||||
void SAMLLoginWindow::login(QString url)
|
||||
{
|
||||
webView->load(QUrl(url));
|
||||
}
|
||||
|
||||
void SAMLLoginWindow::onResponseReceived(QJsonObject params)
|
||||
{
|
||||
QString type = params.value("type").toString();
|
||||
// Skip non-document response
|
||||
if (type != "Document") {
|
||||
return;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user