Skip to content

Commit

Permalink
Fix MSA login
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-goode committed Oct 26, 2024
1 parent d40b6d8 commit 7f52d57
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 58 deletions.
10 changes: 6 additions & 4 deletions launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Net::HeaderPair>{
{ "Content-Type", "application/x-www-form-urlencoded" },
{ "Accept", "application/json" },
Expand Down Expand Up @@ -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<Net::HeaderPair>{
{ "Content-Type", "application/x-www-form-urlencoded" },
{ "Accept", "application/json" },
Expand Down Expand Up @@ -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"));
}
}
13 changes: 10 additions & 3 deletions launcher/minecraft/auth/steps/MSAStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString, QVariant>* parameters) {
if (stage == QAbstractOAuth::Stage::RefreshingAccessToken) {
(*parameters).insert("scope", scope);
}
});
oauth2.setClientIdentifier(m_clientId);
oauth2.setNetworkAccessManager(APPLICATION->network().get());

Expand Down
8 changes: 2 additions & 6 deletions launcher/ui/dialogs/MSALoginDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -172,4 +168,4 @@ MinecraftAccountPtr MSALoginDialog::newAccount(QWidget* parent)
return dlg.m_account;
}
return nullptr;
}
}
48 changes: 3 additions & 45 deletions launcher/ui/dialogs/MSALoginDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QStackedWidget" name="stackedWidget2">
<property name="visible">
<bool>false</bool>
</property>
<property name="currentIndex">
<number>1</number>
</property>
Expand Down Expand Up @@ -140,51 +143,6 @@
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="Line" name="line_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="orLabel">
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>Or</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
Expand Down

0 comments on commit 7f52d57

Please sign in to comment.