Compare commits

...

3 Commits

Author SHA1 Message Date
Kevin Yue
86ad51b0ad Add extra parameters to prelogin request 2020-05-29 23:44:02 +08:00
Kevin Yue
1e2322b938 Fix saml login for portal-userauthcookie (#12) 2020-05-29 23:38:51 +08:00
Kevin Yue
4313b9d0e7 Update README.md 2020-05-25 10:05:11 +08:00
5 changed files with 30 additions and 11 deletions

View File

@@ -10,7 +10,7 @@ using namespace gpclient::helper;
GatewayAuthenticator::GatewayAuthenticator(const QString& gateway, const PortalConfigResponse& portalConfig) GatewayAuthenticator::GatewayAuthenticator(const QString& gateway, const PortalConfigResponse& portalConfig)
: QObject() : QObject()
, preloginUrl("https://" + gateway + "/ssl-vpn/prelogin.esp") , preloginUrl("https://" + gateway + "/ssl-vpn/prelogin.esp?tmp=tmp&kerberos-support=yes&ipv6-support=yes&clientVer=4100&clientos=Linux")
, loginUrl("https://" + gateway + "/ssl-vpn/login.esp") , loginUrl("https://" + gateway + "/ssl-vpn/login.esp")
, portalConfig(portalConfig) , portalConfig(portalConfig)
{ {
@@ -151,11 +151,16 @@ void GatewayAuthenticator::samlAuth(QString samlMethod, QString samlRequest, QSt
void GatewayAuthenticator::onSAMLLoginSuccess(const QMap<QString, QString> &samlResult) void GatewayAuthenticator::onSAMLLoginSuccess(const QMap<QString, QString> &samlResult)
{ {
PLOGI << "SAML login succeeded, got the prelogin cookie " << samlResult.value("preloginCookie"); if (samlResult.contains("preloginCookie")) {
PLOGI << "SAML login succeeded, got the prelogin-cookie " << samlResult.value("preloginCookie");
} else {
PLOGI << "SAML login succeeded, got the portal-userauthcookie " << samlResult.value("userAuthCookie");
}
LoginParams params; LoginParams params;
params.setUser(samlResult.value("username")); params.setUser(samlResult.value("username"));
params.setPreloginCookie(samlResult.value("preloginCookie")); params.setPreloginCookie(samlResult.value("preloginCookie"));
params.setUserAuthCookie(samlResult.value("userAuthCookie"));
login(params); login(params);
} }

View File

@@ -14,7 +14,7 @@ using namespace gpclient::helper;
PortalAuthenticator::PortalAuthenticator(const QString& portal) : QObject() PortalAuthenticator::PortalAuthenticator(const QString& portal) : QObject()
, portal(portal) , portal(portal)
, preloginUrl("https://" + portal + "/global-protect/prelogin.esp") , preloginUrl("https://" + portal + "/global-protect/prelogin.esp?tmp=tmp&kerberos-support=yes&ipv6-support=yes&clientVer=4100&clientos=Linux")
, configUrl("https://" + portal + "/global-protect/getconfig.esp") , configUrl("https://" + portal + "/global-protect/getconfig.esp")
{ {
} }
@@ -124,9 +124,13 @@ void PortalAuthenticator::samlAuth()
void PortalAuthenticator::onSAMLLoginSuccess(const QMap<QString, QString> samlResult) void PortalAuthenticator::onSAMLLoginSuccess(const QMap<QString, QString> samlResult)
{ {
PLOGI << "SAML login succeeded, got the prelogin cookie " << samlResult.value("preloginCookie"); if (samlResult.contains("preloginCookie")) {
PLOGI << "SAML login succeeded, got the prelogin-cookie " << samlResult.value("preloginCookie");
} else {
PLOGI << "SAML login succeeded, got the portal-userauthcookie " << samlResult.value("userAuthCookie");
}
fetchConfig(samlResult.value("username"), "", samlResult.value("preloginCookie")); fetchConfig(samlResult.value("username"), "", samlResult.value("preloginCookie"), samlResult.value("userAuthCookie"));
} }
void PortalAuthenticator::onSAMLLoginFail(const QString msg) void PortalAuthenticator::onSAMLLoginFail(const QString msg)
@@ -134,13 +138,14 @@ void PortalAuthenticator::onSAMLLoginFail(const QString msg)
emitFail(msg); emitFail(msg);
} }
void PortalAuthenticator::fetchConfig(QString username, QString password, QString preloginCookie) void PortalAuthenticator::fetchConfig(QString username, QString password, QString preloginCookie, QString userAuthCookie)
{ {
LoginParams params; LoginParams params;
params.setServer(portal); params.setServer(portal);
params.setUser(username); params.setUser(username);
params.setPassword(password); params.setPassword(password);
params.setPreloginCookie(preloginCookie); params.setPreloginCookie(preloginCookie);
params.setUserAuthCookie(userAuthCookie);
// Save the username and password for future use. // Save the username and password for future use.
this->username = username; this->username = username;

View File

@@ -47,7 +47,7 @@ private:
void tryAutoLogin(); void tryAutoLogin();
void normalAuth(); void normalAuth();
void samlAuth(); void samlAuth();
void fetchConfig(QString username, QString password, QString preloginCookie = ""); void fetchConfig(QString username, QString password, QString preloginCookie = "", QString userAuthCookie = "");
void emitFail(const QString& msg = ""); void emitFail(const QString& msg = "");
}; };

View File

@@ -59,11 +59,19 @@ void SAMLLoginWindow::onResponseReceived(QJsonObject params)
const QString username = headers.value("saml-username").toString(); const QString username = headers.value("saml-username").toString();
const QString preloginCookie = headers.value("prelogin-cookie").toString(); const QString preloginCookie = headers.value("prelogin-cookie").toString();
const QString userAuthCookie = headers.value("portal-userauthcookie").toString();
if (!username.isEmpty() && !preloginCookie.isEmpty()) { if (!username.isEmpty()) {
samlResult.insert("username", username); samlResult.insert("username", username);
}
if (!preloginCookie.isEmpty()) {
samlResult.insert("preloginCookie", preloginCookie); samlResult.insert("preloginCookie", preloginCookie);
} }
if (!userAuthCookie.isEmpty()) {
samlResult.insert("userAuthCookie", userAuthCookie);
}
} }
void SAMLLoginWindow::onLoadFinished() void SAMLLoginWindow::onLoadFinished()
@@ -71,7 +79,8 @@ void SAMLLoginWindow::onLoadFinished()
LOGI << "Load finished " << this->webView->page()->url().toString(); LOGI << "Load finished " << this->webView->page()->url().toString();
// Check the SAML result // Check the SAML result
if (!samlResult.value("username").isEmpty() && !samlResult.value("preloginCookie").isEmpty()) { if (samlResult.contains("username")
&& (samlResult.contains("preloginCookie") || samlResult.contains("userAuthCookie"))) {
emit success(samlResult); emit success(samlResult);
accept(); accept();
} else { } else {

View File

@@ -7,10 +7,10 @@ A GlobalProtect VPN client (GUI) for Linux based on Openconnect and built with Q
## Features ## Features
- Similar user experience as the offical client in macOS. - Similar user experience as the official client in macOS.
- Supports both SAML and non-SAML authentication modes. - Supports both SAML and non-SAML authentication modes.
- Supports automatically selecting the preferred gateway from the multiple gateways. - Supports automatically selecting the preferred gateway from the multiple gateways.
- Supports switching gateway manually. - Supports switching gateway from the system tray menu manually.
## Prerequisites ## Prerequisites