update login flow

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97
2024-06-12 00:34:39 +03:00
parent 6b1c4981e7
commit c4a65dd861
15 changed files with 421 additions and 166 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -34,6 +34,7 @@ class AuthStep : public QObject {
public slots:
virtual void perform() = 0;
virtual void abort() {}
signals:
void finished(AccountTaskState resultingState, QString message);

View File

@@ -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);

View File

@@ -35,22 +35,35 @@
#include "MSAStep.h"
#include <QtNetworkAuth/qoauthhttpserverreplyhandler.h>
#include <QAbstractOAuth2>
#include <QNetworkRequest>
#include <QOAuthOobReplyHandler>
#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(
" <iframe src=\"https://prismlauncher.org/successful-login\" title=\"PrismLauncher Microsoft login\" style=\"position:fixed; "
"top:0; left:0; bottom:0; right:0; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; "
"z-index:999999;\"/> ");
oauth2.setReplyHandler(replyHandler);
auto bv = new CustomOAuthOobReplyHandler();
oauth2.setReplyHandler(bv);
oauth2.setAuthorizationUrl(QUrl("https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize"));
oauth2.setAccessTokenUrl(QUrl("https://login.microsoftonline.com/consumers/oauth2/v2.0/token"));
oauth2.setScope("XboxLive.SignIn XboxLive.offline_access");
@@ -106,3 +119,5 @@ void MSAStep::perform()
oauth2.grant();
}
}
#include "MSAStep.moc"