From bb02226870a21c08ec534295ea0dcb8dd4c542cf Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 12 Feb 2022 20:08:50 +0100 Subject: feat(ui): add custom MSA client id setting --- launcher/Application.cpp | 7 +- launcher/CMakeLists.txt | 6 +- launcher/ui/pages/global/APIPage.cpp | 67 ++++++++++++ launcher/ui/pages/global/APIPage.h | 60 +++++++++++ launcher/ui/pages/global/APIPage.ui | 179 +++++++++++++++++++++++++++++++++ launcher/ui/pages/global/PastePage.cpp | 63 ------------ launcher/ui/pages/global/PastePage.h | 60 ----------- launcher/ui/pages/global/PastePage.ui | 127 ----------------------- 8 files changed, 314 insertions(+), 255 deletions(-) create mode 100644 launcher/ui/pages/global/APIPage.cpp create mode 100644 launcher/ui/pages/global/APIPage.h create mode 100644 launcher/ui/pages/global/APIPage.ui delete mode 100644 launcher/ui/pages/global/PastePage.cpp delete mode 100644 launcher/ui/pages/global/PastePage.h delete mode 100644 launcher/ui/pages/global/PastePage.ui diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 93cefc28..5e70c729 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -14,7 +14,7 @@ #include "ui/pages/global/ProxyPage.h" #include "ui/pages/global/ExternalToolsPage.h" #include "ui/pages/global/AccountListPage.h" -#include "ui/pages/global/PastePage.h" +#include "ui/pages/global/APIPage.h" #include "ui/pages/global/CustomCommandsPage.h" #include "ui/themes/ITheme.h" @@ -719,6 +719,9 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) m_settings->registerSetting("CloseAfterLaunch", false); + // Custom MSA credentials + m_settings->registerSetting("MSAClientIDOverride", ""); + // Init page provider { m_globalSettingsProvider = std::make_shared(tr("Settings")); @@ -730,7 +733,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); - m_globalSettingsProvider->addPage(); + m_globalSettingsProvider->addPage(); } qDebug() << "<> Settings loaded."; } diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 3d2d4382..90149c3b 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -723,8 +723,8 @@ SET(LAUNCHER_SOURCES ui/pages/global/LauncherPage.h ui/pages/global/ProxyPage.cpp ui/pages/global/ProxyPage.h - ui/pages/global/PastePage.cpp - ui/pages/global/PastePage.h + ui/pages/global/APIPage.cpp + ui/pages/global/APIPage.h # GUI - platform pages ui/pages/modplatform/VanillaPage.cpp @@ -871,7 +871,7 @@ qt5_wrap_ui(LAUNCHER_UI ui/pages/global/AccountListPage.ui ui/pages/global/JavaPage.ui ui/pages/global/LauncherPage.ui - ui/pages/global/PastePage.ui + ui/pages/global/APIPage.ui ui/pages/global/ProxyPage.ui ui/pages/global/MinecraftPage.ui ui/pages/global/ExternalToolsPage.ui diff --git a/launcher/ui/pages/global/APIPage.cpp b/launcher/ui/pages/global/APIPage.cpp new file mode 100644 index 00000000..ad79e00c --- /dev/null +++ b/launcher/ui/pages/global/APIPage.cpp @@ -0,0 +1,67 @@ +/* Copyright 2013-2021 MultiMC & PolyMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "APIPage.h" +#include "ui_APIPage.h" + +#include +#include +#include +#include +#include + +#include "settings/SettingsObject.h" +#include "tools/BaseProfiler.h" +#include "Application.h" + +APIPage::APIPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::APIPage) +{ + static QRegularExpression validUrlRegExp("https?://.+"); + ui->setupUi(this); + ui->urlChoices->setValidator(new QRegularExpressionValidator(validUrlRegExp, ui->urlChoices)); + ui->tabWidget->tabBar()->hide();\ + loadSettings(); +} + +APIPage::~APIPage() +{ + delete ui; +} + +void APIPage::loadSettings() +{ + auto s = APPLICATION->settings(); + QString pastebinURL = s->get("PastebinURL").toString(); + ui->urlChoices->setCurrentText(pastebinURL); + QString msaClientID = s->get("MSAClientIDOverride").toString(); + ui->msaClientID->setText(msaClientID); +} + +void APIPage::applySettings() +{ + auto s = APPLICATION->settings(); + QString pastebinURL = ui->urlChoices->currentText(); + s->set("PastebinURL", pastebinURL); + QString msaClientID = ui->msaClientID->text(); + s->set("MSAClientIDOverride", msaClientID); +} + +bool APIPage::apply() +{ + applySettings(); + return true; +} diff --git a/launcher/ui/pages/global/APIPage.h b/launcher/ui/pages/global/APIPage.h new file mode 100644 index 00000000..9474ebbb --- /dev/null +++ b/launcher/ui/pages/global/APIPage.h @@ -0,0 +1,60 @@ +/* Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include "ui/pages/BasePage.h" +#include + +namespace Ui { +class APIPage; +} + +class APIPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit APIPage(QWidget *parent = 0); + ~APIPage(); + + QString displayName() const override + { + return tr("APIs"); + } + QIcon icon() const override + { + return APPLICATION->getThemedIcon("worlds"); + } + QString id() const override + { + return "apis"; + } + QString helpPage() const override + { + return "APIs"; + } + virtual bool apply() override; + +private: + void loadSettings(); + void applySettings(); + +private: + Ui::APIPage *ui; +}; + diff --git a/launcher/ui/pages/global/APIPage.ui b/launcher/ui/pages/global/APIPage.ui new file mode 100644 index 00000000..38bbc525 --- /dev/null +++ b/launcher/ui/pages/global/APIPage.ui @@ -0,0 +1,179 @@ + + + APIPage + + + + 0 + 0 + 491 + 474 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Tab 1 + + + + + + Pastebin URL + + + + + + Qt::Horizontal + + + + + + + + 10 + + + + <html><head/><body><p>Note: only input that starts with <span style=" font-weight:600;">http://</span> or <span style=" font-weight:600;">https://</span> will be accepted.</p></body></html> + + + false + + + + + + + true + + + QComboBox::NoInsert + + + + https://0x0.st + + + + + https://paste.polymc.org + + + + + + + + <html><head/><body><p>Here you can choose from a predefined list of paste services, or input the URL of a different paste service of your choice, provided it supports the same protocol as 0x0.st, that is POST a file parameter to the URL and return a link in the response body.</p></body></html> + + + Qt::RichText + + + true + + + true + + + + + + + + + + Microsoft Secured Account + + + + + + Qt::Horizontal + + + + + + + Note: you probably don't need to set this if logging in via Microsoft Secured Account already works. + + + Qt::RichText + + + true + + + + + + + (Default) + + + + + + + Enter a custom client ID for Microsoft Secured Account here. + + + Qt::RichText + + + true + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + tabWidget + + + + diff --git a/launcher/ui/pages/global/PastePage.cpp b/launcher/ui/pages/global/PastePage.cpp deleted file mode 100644 index 7c69e1a4..00000000 --- a/launcher/ui/pages/global/PastePage.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* Copyright 2013-2021 MultiMC & PolyMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "PastePage.h" -#include "ui_PastePage.h" - -#include -#include -#include -#include -#include - -#include "settings/SettingsObject.h" -#include "tools/BaseProfiler.h" -#include "Application.h" - -PastePage::PastePage(QWidget *parent) : - QWidget(parent), - ui(new Ui::PastePage) -{ - static QRegularExpression validUrlRegExp("https?://.+"); - ui->setupUi(this); - ui->urlChoices->setValidator(new QRegularExpressionValidator(validUrlRegExp, ui->urlChoices)); - ui->tabWidget->tabBar()->hide();\ - loadSettings(); -} - -PastePage::~PastePage() -{ - delete ui; -} - -void PastePage::loadSettings() -{ - auto s = APPLICATION->settings(); - QString pastebinURL = s->get("PastebinURL").toString(); - ui->urlChoices->setCurrentText(pastebinURL); -} - -void PastePage::applySettings() -{ - auto s = APPLICATION->settings(); - QString pastebinURL = ui->urlChoices->currentText(); - s->set("PastebinURL", pastebinURL); -} - -bool PastePage::apply() -{ - applySettings(); - return true; -} diff --git a/launcher/ui/pages/global/PastePage.h b/launcher/ui/pages/global/PastePage.h deleted file mode 100644 index d475dfd9..00000000 --- a/launcher/ui/pages/global/PastePage.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include "ui/pages/BasePage.h" -#include - -namespace Ui { -class PastePage; -} - -class PastePage : public QWidget, public BasePage -{ - Q_OBJECT - -public: - explicit PastePage(QWidget *parent = 0); - ~PastePage(); - - QString displayName() const override - { - return tr("Log Upload"); - } - QIcon icon() const override - { - return APPLICATION->getThemedIcon("log"); - } - QString id() const override - { - return "log-upload"; - } - QString helpPage() const override - { - return "Log-Upload"; - } - virtual bool apply() override; - -private: - void loadSettings(); - void applySettings(); - -private: - Ui::PastePage *ui; -}; - diff --git a/launcher/ui/pages/global/PastePage.ui b/launcher/ui/pages/global/PastePage.ui deleted file mode 100644 index 2d13a765..00000000 --- a/launcher/ui/pages/global/PastePage.ui +++ /dev/null @@ -1,127 +0,0 @@ - - - PastePage - - - - 0 - 0 - 491 - 474 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - Tab 1 - - - - - - Pastebin URL - - - - - - Qt::Horizontal - - - - - - - - 10 - - - - <html><head/><body><p>Note: only input that starts with <span style=" font-weight:600;">http://</span> or <span style=" font-weight:600;">https://</span> will be accepted.</p></body></html> - - - false - - - - - - - true - - - QComboBox::NoInsert - - - - https://0x0.st - - - - - https://paste.polymc.org - - - - - - - - <html><head/><body><p>Here you can choose from a predefined list of paste services, or input the URL of a different paste service of your choice, provided it supports the same protocol as 0x0.st, that is POST a file parameter to the URL and return a link in the response body.</p></body></html> - - - Qt::RichText - - - true - - - true - - - - - - - - - - Qt::Vertical - - - - 20 - 216 - - - - - - - - - - - - tabWidget - - - - -- cgit From 0854e83ce48cb30b28bd05986970e506c1106e4e Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 12 Feb 2022 20:20:51 +0100 Subject: feat: implement MSA client id override Closes #11 --- launcher/Application.cpp | 10 ++++++++++ launcher/Application.h | 2 ++ launcher/minecraft/auth/steps/MSAStep.cpp | 2 +- launcher/ui/pages/global/AccountListPage.cpp | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 5e70c729..a3d6216e 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1519,3 +1519,13 @@ QString Application::getJarsPath() } return m_jarsPath; } + +QString Application::getMSAClientID() +{ + QString clientIDOverride = m_settings->get("MSAClientIDOverride").toString(); + if (!clientIDOverride.isEmpty()) { + return clientIDOverride; + } + + return BuildConfig.MSA_CLIENT_ID; +} diff --git a/launcher/Application.h b/launcher/Application.h index c1cd8224..fb41d647 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -117,6 +117,8 @@ public: QString getJarsPath(); + QString getMSAClientID(); + /// this is the root of the 'installation'. Used for automatic updates const QString &root() { return m_rootPath; diff --git a/launcher/minecraft/auth/steps/MSAStep.cpp b/launcher/minecraft/auth/steps/MSAStep.cpp index bc10aa4e..779aee43 100644 --- a/launcher/minecraft/auth/steps/MSAStep.cpp +++ b/launcher/minecraft/auth/steps/MSAStep.cpp @@ -14,7 +14,7 @@ using Activity = Katabasis::Activity; MSAStep::MSAStep(AccountData* data, Action action) : AuthStep(data), m_action(action) { OAuth2::Options opts; opts.scope = "XboxLive.signin offline_access"; - opts.clientIdentifier = BuildConfig.MSA_CLIENT_ID; + opts.clientIdentifier = APPLICATION->getMSAClientID(); opts.authorizationUrl = "https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode"; opts.accessTokenUrl = "https://login.microsoftonline.com/consumers/oauth2/v2.0/token"; diff --git a/launcher/ui/pages/global/AccountListPage.cpp b/launcher/ui/pages/global/AccountListPage.cpp index 396d320f..ea310acd 100644 --- a/launcher/ui/pages/global/AccountListPage.cpp +++ b/launcher/ui/pages/global/AccountListPage.cpp @@ -73,7 +73,7 @@ AccountListPage::AccountListPage(QWidget *parent) updateButtonStates(); // Xbox authentication won't work without a client identifier, so disable the button if it is missing - ui->actionAddMicrosoft->setVisible(BuildConfig.MSA_CLIENT_ID.size() != 0); + ui->actionAddMicrosoft->setVisible(!APPLICATION->getMSAClientID().isEmpty()); } AccountListPage::~AccountListPage() -- cgit From 159d868b77e6962632e925caf80a347122203d27 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 12 Feb 2022 20:30:42 +0100 Subject: fix(ui): explain why 'Add Microsoft' might be disabled --- launcher/ui/pages/global/AccountListPage.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/launcher/ui/pages/global/AccountListPage.cpp b/launcher/ui/pages/global/AccountListPage.cpp index ea310acd..740697a4 100644 --- a/launcher/ui/pages/global/AccountListPage.cpp +++ b/launcher/ui/pages/global/AccountListPage.cpp @@ -73,7 +73,10 @@ AccountListPage::AccountListPage(QWidget *parent) updateButtonStates(); // Xbox authentication won't work without a client identifier, so disable the button if it is missing - ui->actionAddMicrosoft->setVisible(!APPLICATION->getMSAClientID().isEmpty()); + if (APPLICATION->getMSAClientID().isEmpty()) { + ui->actionAddMicrosoft->setVisible(false); + ui->actionAddMicrosoft->setToolTip(tr("No Microsoft Secured Account client ID was set.")); + } } AccountListPage::~AccountListPage() -- cgit From a309f4e72143b28865d5a8b94dcf913d3a95773f Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 12 Feb 2022 21:09:25 +0100 Subject: fix: MSA = Microsoft Authentication --- launcher/ui/pages/global/APIPage.ui | 6 +++--- launcher/ui/pages/global/AccountListPage.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/launcher/ui/pages/global/APIPage.ui b/launcher/ui/pages/global/APIPage.ui index 38bbc525..28c53b79 100644 --- a/launcher/ui/pages/global/APIPage.ui +++ b/launcher/ui/pages/global/APIPage.ui @@ -103,7 +103,7 @@ - Microsoft Secured Account + Microsoft Authentication @@ -116,7 +116,7 @@ - Note: you probably don't need to set this if logging in via Microsoft Secured Account already works. + Note: you probably don't need to set this if logging in via Microsoft Authentication already works. Qt::RichText @@ -136,7 +136,7 @@ - Enter a custom client ID for Microsoft Secured Account here. + Enter a custom client ID for Microsoft Authentication here. Qt::RichText diff --git a/launcher/ui/pages/global/AccountListPage.cpp b/launcher/ui/pages/global/AccountListPage.cpp index 740697a4..eb1ee8d3 100644 --- a/launcher/ui/pages/global/AccountListPage.cpp +++ b/launcher/ui/pages/global/AccountListPage.cpp @@ -75,7 +75,7 @@ AccountListPage::AccountListPage(QWidget *parent) // Xbox authentication won't work without a client identifier, so disable the button if it is missing if (APPLICATION->getMSAClientID().isEmpty()) { ui->actionAddMicrosoft->setVisible(false); - ui->actionAddMicrosoft->setToolTip(tr("No Microsoft Secured Account client ID was set.")); + ui->actionAddMicrosoft->setToolTip(tr("No Microsoft Authentication client ID was set.")); } } -- cgit