From 7f52d57454539880704d5422b595e43e1de5116a Mon Sep 17 00:00:00 2001 From: Evan Goode Date: Sat, 26 Oct 2024 14:56:55 -0400 Subject: [PATCH] Fix MSA login --- .../auth/steps/MSADeviceCodeStep.cpp | 10 ++-- launcher/minecraft/auth/steps/MSAStep.cpp | 13 +++-- launcher/ui/dialogs/MSALoginDialog.cpp | 8 +--- launcher/ui/dialogs/MSALoginDialog.ui | 48 ++----------------- 4 files changed, 21 insertions(+), 58 deletions(-) diff --git a/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp b/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp index c283b153e..de2c61605 100644 --- a/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp +++ b/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp @@ -59,9 +59,10 @@ void MSADeviceCodeStep::perform() { QUrlQuery data; data.addQueryItem("client_id", m_clientId); - data.addQueryItem("scope", "XboxLive.SignIn XboxLive.offline_access"); + data.addQueryItem("scope", "service::user.auth.xboxlive.com::MBI_SSL"); + data.addQueryItem("response_type", "device_code"); auto payload = data.query(QUrl::FullyEncoded).toUtf8(); - QUrl url("https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode"); + QUrl url("https://login.live.com/oauth20_connect.srf"); auto headers = QList{ { "Content-Type", "application/x-www-form-urlencoded" }, { "Accept", "application/json" }, @@ -175,8 +176,9 @@ void MSADeviceCodeStep::authenticateUser() data.addQueryItem("client_id", m_clientId); data.addQueryItem("grant_type", "urn:ietf:params:oauth:grant-type:device_code"); data.addQueryItem("device_code", m_device_code); + data.addQueryItem("response_type", "device_code"); auto payload = data.query(QUrl::FullyEncoded).toUtf8(); - QUrl url("https://login.microsoftonline.com/consumers/oauth2/v2.0/token"); + QUrl url("https://login.live.com/oauth20_token.srf"); auto headers = QList{ { "Content-Type", "application/x-www-form-urlencoded" }, { "Accept", "application/json" }, @@ -274,4 +276,4 @@ void MSADeviceCodeStep::authenticationFinished() m_data->msaToken.refresh_token = rsp.refresh_token; m_data->msaToken.token = rsp.access_token; emit finished(AccountTaskState::STATE_WORKING, tr("Got")); -} \ No newline at end of file +} diff --git a/launcher/minecraft/auth/steps/MSAStep.cpp b/launcher/minecraft/auth/steps/MSAStep.cpp index 96e939028..91c596b17 100644 --- a/launcher/minecraft/auth/steps/MSAStep.cpp +++ b/launcher/minecraft/auth/steps/MSAStep.cpp @@ -104,9 +104,16 @@ MSAStep::MSAStep(AccountData* data, bool silent) : AuthStep(data), m_silent(sile } else { oauth2.setReplyHandler(new CustomOAuthOobReplyHandler(this)); } - 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"); + oauth2.setAuthorizationUrl(QUrl("https://login.live.com/oauth20_connect.srf")); + oauth2.setAccessTokenUrl(QUrl("https://login.live.com/oauth20_token.srf")); + const auto& scope = "service::user.auth.xboxlive.com::MBI_SSL"; + oauth2.setScope(scope); + // QOAuth2AuthorizationCodeFlow doesn't pass a "scope" when refreshing access tokens, but Microsoft expects it. + oauth2.setModifyParametersFunction([](QAbstractOAuth::Stage stage, QMultiMap* parameters) { + if (stage == QAbstractOAuth::Stage::RefreshingAccessToken) { + (*parameters).insert("scope", scope); + } + }); oauth2.setClientIdentifier(m_clientId); oauth2.setNetworkAccessManager(APPLICATION->network().get()); diff --git a/launcher/ui/dialogs/MSALoginDialog.cpp b/launcher/ui/dialogs/MSALoginDialog.cpp index 4e38b4187..1490cc158 100644 --- a/launcher/ui/dialogs/MSALoginDialog.cpp +++ b/launcher/ui/dialogs/MSALoginDialog.cpp @@ -145,11 +145,7 @@ void MSALoginDialog::authorizeWithBrowserWithExtra(QString url, QString code, in ui->code->setText(code); auto isDefaultUrl = url == "https://www.microsoft.com/link"; ui->qr->setVisible(isDefaultUrl); - if (isDefaultUrl) { - ui->qrMessage->setText(tr("Open %1 or scan the QR and enter the above code.").arg(linkString)); - } else { - ui->qrMessage->setText(tr("Open %1 and enter the above code.").arg(linkString)); - } + ui->qrMessage->setText(tr("Open %1 and enter the above code.").arg(linkString)); } void MSALoginDialog::onDeviceFlowStatus(QString status) @@ -172,4 +168,4 @@ MinecraftAccountPtr MSALoginDialog::newAccount(QWidget* parent) return dlg.m_account; } return nullptr; -} \ No newline at end of file +} diff --git a/launcher/ui/dialogs/MSALoginDialog.ui b/launcher/ui/dialogs/MSALoginDialog.ui index 69cd2e1ab..4989184ec 100644 --- a/launcher/ui/dialogs/MSALoginDialog.ui +++ b/launcher/ui/dialogs/MSALoginDialog.ui @@ -22,6 +22,9 @@ + + false + 1 @@ -140,51 +143,6 @@ - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - - - - - - 16 - - - - Or - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - - -