From c4a65dd861f0704f09f258c5cc9c5530e5db981a Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 12 Jun 2024 00:34:39 +0300 Subject: [PATCH] update login flow Signed-off-by: Trial97 --- launcher/Application.h | 3 +- launcher/minecraft/auth/AuthFlow.cpp | 10 + launcher/minecraft/auth/AuthFlow.h | 3 + launcher/minecraft/auth/AuthStep.h | 1 + .../minecraft/auth/steps/MSADeviceCodeStep.h | 2 +- launcher/minecraft/auth/steps/MSAStep.cpp | 29 +- launcher/resources/documents/documents.qrc | 1 + launcher/resources/documents/login-qr.png | Bin 0 -> 7616 bytes launcher/ui/MainWindow.cpp | 8 + launcher/ui/dialogs/MSALoginDialog.cpp | 123 +++--- launcher/ui/dialogs/MSALoginDialog.h | 13 +- launcher/ui/dialogs/MSALoginDialog.ui | 383 ++++++++++++++---- launcher/ui/pages/global/AccountListPage.cpp | 5 +- ...org.prismlauncher.PrismLauncher.desktop.in | 2 +- program_info/win_install.nsi.in | 4 + 15 files changed, 421 insertions(+), 166 deletions(-) create mode 100644 launcher/resources/documents/login-qr.png diff --git a/launcher/Application.h b/launcher/Application.h index 7669e08ec..8303c7475 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -48,7 +48,6 @@ #include #include "minecraft/launch/MinecraftServerTarget.h" -#include "ui/themes/CatPack.h" class LaunchController; class LocalPeer; @@ -193,6 +192,8 @@ class Application : public QApplication { void globalSettingsClosed(); int currentCatChanged(int index); + void oauthReplyRecieved(QVariantMap); + #ifdef Q_OS_MACOS void clickedOnDock(); #endif diff --git a/launcher/minecraft/auth/AuthFlow.cpp b/launcher/minecraft/auth/AuthFlow.cpp index 5648fe9f6..45926206c 100644 --- a/launcher/minecraft/auth/AuthFlow.cpp +++ b/launcher/minecraft/auth/AuthFlow.cpp @@ -59,6 +59,9 @@ void AuthFlow::executeTask() void AuthFlow::nextStep() { + if (!Task::isRunning()) { + return; + } if (m_steps.size() == 0) { // we got to the end without an incident... assume this is all. m_currentStep.reset(); @@ -143,4 +146,11 @@ bool AuthFlow::changeState(AccountTaskState newState, QString reason) return false; } } +} +bool AuthFlow::abort() +{ + emitAborted(); + if (m_currentStep) + m_currentStep->abort(); + return true; } \ No newline at end of file diff --git a/launcher/minecraft/auth/AuthFlow.h b/launcher/minecraft/auth/AuthFlow.h index d99deec3c..4d18ac845 100644 --- a/launcher/minecraft/auth/AuthFlow.h +++ b/launcher/minecraft/auth/AuthFlow.h @@ -24,6 +24,9 @@ class AuthFlow : public Task { AccountTaskState taskState() { return m_taskState; } + public slots: + bool abort() override; + signals: void authorizeWithBrowser(const QUrl& url); void authorizeWithBrowserWithExtra(QString url, QString code, int expiresIn); diff --git a/launcher/minecraft/auth/AuthStep.h b/launcher/minecraft/auth/AuthStep.h index 4d2cf69c1..a2b2cf9e5 100644 --- a/launcher/minecraft/auth/AuthStep.h +++ b/launcher/minecraft/auth/AuthStep.h @@ -34,6 +34,7 @@ class AuthStep : public QObject { public slots: virtual void perform() = 0; + virtual void abort() {} signals: void finished(AccountTaskState resultingState, QString message); diff --git a/launcher/minecraft/auth/steps/MSADeviceCodeStep.h b/launcher/minecraft/auth/steps/MSADeviceCodeStep.h index e53eebc62..024927b31 100644 --- a/launcher/minecraft/auth/steps/MSADeviceCodeStep.h +++ b/launcher/minecraft/auth/steps/MSADeviceCodeStep.h @@ -51,7 +51,7 @@ class MSADeviceCodeStep : public AuthStep { QString describe() override; public slots: - void abort(); + void abort() override; signals: void authorizeWithBrowser(QString url, QString code, int expiresIn); diff --git a/launcher/minecraft/auth/steps/MSAStep.cpp b/launcher/minecraft/auth/steps/MSAStep.cpp index 3f31cdc16..c1eb3a33c 100644 --- a/launcher/minecraft/auth/steps/MSAStep.cpp +++ b/launcher/minecraft/auth/steps/MSAStep.cpp @@ -35,22 +35,35 @@ #include "MSAStep.h" -#include #include #include +#include #include "Application.h" +#include "BuildConfig.h" + +class CustomOAuthOobReplyHandler : public QOAuthOobReplyHandler { + Q_OBJECT + + public: + explicit CustomOAuthOobReplyHandler(QObject* parent = nullptr) : QOAuthOobReplyHandler(parent) + { + connect(APPLICATION, &Application::oauthReplyRecieved, this, &QOAuthOobReplyHandler::callbackReceived); + } + ~CustomOAuthOobReplyHandler() override + { + disconnect(APPLICATION, &Application::oauthReplyRecieved, this, &QOAuthOobReplyHandler::callbackReceived); + } + QString callback() const override { return BuildConfig.LAUNCHER_APP_BINARY_NAME + "://oauth"; } +}; MSAStep::MSAStep(AccountData* data, bool silent) : AuthStep(data), m_silent(silent) { m_clientId = APPLICATION->getMSAClientID(); - auto replyHandler = new QOAuthHttpServerReplyHandler(1337, this); - replyHandler->setCallbackText( - "