Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add User Agent Override to SAML Authentication #261

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions GPClient/gpclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ void GPClient::onSettingsButtonClicked()
{
settingsDialog->setClientos(settings::get("clientos", "Linux").toString());
settingsDialog->setOsVersion(settings::get("os-version", QSysInfo::prettyProductName()).toString());
settingsDialog->setSamlUserAgent(settings::get("samlUserAgent", "").toString());
settingsDialog->show();
}

void GPClient::onSettingsAccepted()
{
settings::save("clientos", settingsDialog->clientos());
settings::save("os-version", settingsDialog->osVersion());
settings::save("samlUserAgent", settingsDialog->samlUserAgent());
}

void GPClient::on_connectButton_clicked()
Expand Down
2 changes: 1 addition & 1 deletion GPClient/gphelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace gpclient {
namespace settings {

extern QSettings *_settings;
static const QStringList reservedKeys {"extraArgs", "clientos"};
static const QStringList reservedKeys {"extraArgs", "clientos", "samlUserAgent"};

QVariant get(const QString &key, const QVariant &defaultValue = QVariant());
QStringList get_all(const QString &key, const QVariant &defaultValue = QVariant());
Expand Down
6 changes: 6 additions & 0 deletions GPClient/samlloginwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
#include <QWebEngineCookieStore>
#include <plog/Log.h>

#include "gphelper.h"
#include "samlloginwindow.h"

using namespace gpclient::helper;

SAMLLoginWindow::SAMLLoginWindow(QWidget *parent)
: QDialog(parent)
, webView(new EnhancedWebView(this))
Expand Down Expand Up @@ -42,6 +45,9 @@ void SAMLLoginWindow::closeEvent(QCloseEvent *event)
void SAMLLoginWindow::login(const QString samlMethod, const QString samlRequest, const QString preloginUrl)
{
webView->page()->profile()->cookieStore()->deleteSessionCookies();
const QString& ua = settings::get("samlUserAgent", "").toString();
if (!ua.isEmpty())
webView->page()->profile()->setHttpUserAgent(ua);

if (samlMethod == "POST") {
webView->setHtml(samlRequest, preloginUrl);
Expand Down
8 changes: 8 additions & 0 deletions GPClient/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ void SettingsDialog::setOsVersion(QString osVersion) {
QString SettingsDialog::osVersion() {
return ui->osVersionInput->text();
}

void SettingsDialog::setSamlUserAgent(QString samlUserAgent) {
ui->samlUserAgentInput->setText(samlUserAgent);
}

QString SettingsDialog::samlUserAgent() {
return ui->samlUserAgentInput->text();
}
3 changes: 3 additions & 0 deletions GPClient/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class SettingsDialog : public QDialog
void setOsVersion(QString osVersion);
QString osVersion();

void setSamlUserAgent(QString samlUserAgent);
QString samlUserAgent();

private:
Ui::SettingsDialog *ui;
};
Expand Down
24 changes: 17 additions & 7 deletions GPClient/settingsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>488</width>
<height>220</height>
<height>328</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -55,7 +55,17 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>os-version:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="osVersionInput"/>
</item>
<item row="4" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -65,13 +75,13 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="osVersionInput"/>
<item row="3" column="1">
<widget class="QLineEdit" name="samlUserAgentInput"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>os-version:</string>
<string>saml-user-agent:</string>
</property>
</widget>
</item>
Expand Down
Loading