add tip for microsoft login Xbox 400 error

This commit is contained in:
ShirosakiMio 2024-08-19 09:41:05 +08:00
parent 5be5c728f9
commit cf278c11f8
6 changed files with 53 additions and 25 deletions

View File

@ -471,6 +471,8 @@ public final class Accounts {
} else {
return context.getString(R.string.account_methods_microsoft_error_unknown);
}
} else if (exception instanceof MicrosoftService.XBox400Exception) {
return context.getString(R.string.account_methods_microsoft_error_wrong_verify_method);
} else if (exception instanceof MicrosoftService.NoMinecraftJavaEditionProfileException) {
return context.getString(R.string.account_methods_microsoft_error_no_character);
} else if (exception instanceof MicrosoftService.NoXuiException) {

View File

@ -67,6 +67,7 @@
<string name="account_methods_microsoft_error_country_unavailable">Xbox Live 不支持您所在的国家/地区。</string>
<string name="account_methods_microsoft_error_missing_xbox_account">你的微软账户没有链接到 Xbox 账户,请先创建。</string>
<string name="account_methods_microsoft_error_unknown">登录失败</string>
<string name="account_methods_microsoft_error_wrong_verify_method">请在 Microsoft 账户登陆页面使用账户 + 密码登录。请不要使用验证码登录。</string>
<string name="account_methods_microsoft_error_no_character">你的账户尚未获取 Minecraft : Java Edition</string>
<string name="account_methods_microsoft_error_add_family_probably">请检查并确保年龄设置大于 18 岁。</string>
<string name="account_methods_microsoft_close_page">Microsoft 账户登录完成</string>

View File

@ -81,6 +81,7 @@
<string name="account_methods_microsoft_error_country_unavailable">Xbox Live is not available in your current country/region.</string>
<string name="account_methods_microsoft_error_missing_xbox_account">Your Microsoft account does not have a linked Xbox account yet. Please create one before continuing.</string>
<string name="account_methods_microsoft_error_unknown">Failed to log in</string>
<string name="account_methods_microsoft_error_wrong_verify_method">Please log in using your account and password on the Microsoft account login page. Please do not use a verification code to log in.</string>
<string name="account_methods_microsoft_error_no_character">Your account does not own the Minecraft Java Edition.\nThe game profile may not have been created.</string>
<string name="account_methods_microsoft_error_add_family_probably">Please check if the age indicated in your account settings is at least 18 years old. If not and you believe this is an error, you can go to official website to change it.</string>
<string name="account_methods_microsoft_close_page">Microsoft account authorization is now completed.</string>

View File

@ -118,8 +118,11 @@ public class MicrosoftService {
}
private MicrosoftSession authenticateViaLiveAccessToken(String liveAccessToken, String liveRefreshToken) throws IOException, JsonParseException, AuthenticationException {
String uhs;
XBoxLiveAuthenticationResponse xboxResponse, minecraftXstsResponse;
try {
// Authenticate with XBox Live
XBoxLiveAuthenticationResponse xboxResponse = HttpRequest
xboxResponse = HttpRequest
.POST("https://user.auth.xboxlive.com/user/authenticate")
.json(mapOf(
pair("Properties",
@ -127,12 +130,12 @@ public class MicrosoftService {
pair("RpsTicket", "d=" + liveAccessToken))),
pair("RelyingParty", "http://auth.xboxlive.com"), pair("TokenType", "JWT")))
.retry(5)
.accept("application/json").getJson(XBoxLiveAuthenticationResponse.class);
.accept("application/json")
.getJson(XBoxLiveAuthenticationResponse.class);
String uhs = getUhs(xboxResponse, null);
uhs = getUhs(xboxResponse, null);
// Authenticate Minecraft with XSTS
XBoxLiveAuthenticationResponse minecraftXstsResponse = HttpRequest
minecraftXstsResponse = HttpRequest
.POST("https://xsts.auth.xboxlive.com/xsts/authorize")
.json(mapOf(
pair("Properties",
@ -142,6 +145,12 @@ public class MicrosoftService {
.ignoreHttpErrorCode(401)
.retry(5)
.getJson(XBoxLiveAuthenticationResponse.class);
} catch (ResponseCodeException e) {
if (e.getResponseCode() == 400) {
throw new XBox400Exception();
}
throw e;
}
getUhs(minecraftXstsResponse, uhs);
@ -298,6 +307,9 @@ public class MicrosoftService {
public static final long ADD_FAMILY = 2148916238L;
}
public static class XBox400Exception extends AuthenticationException {
}
public static class NoMinecraftJavaEditionProfileException extends AuthenticationException {
}

View File

@ -189,13 +189,18 @@ public abstract class HttpRequest {
os.write(bytes);
}
URL url = new URL(this.url);
if (responseCodeTester != null) {
responseCodeTester.accept(new URL(url), con.getResponseCode());
responseCodeTester.accept(url, con.getResponseCode());
} else {
if (con.getResponseCode() / 100 != 2) {
if (!ignoreHttpCode && !toleratedHttpCodes.contains(con.getResponseCode())) {
String data = NetworkUtils.readData(con);
throw new ResponseCodeException(new URL(url), con.getResponseCode(), data);
try {
throw new ResponseCodeException(url, con.getResponseCode(), NetworkUtils.readData(con));
} catch (IOException e) {
throw new ResponseCodeException(url, con.getResponseCode(), e);
}
}
}
}

View File

@ -33,6 +33,13 @@ public final class ResponseCodeException extends IOException {
this.data = null;
}
public ResponseCodeException(URL url, int responseCode, Throwable cause) {
super("Unable to request url " + url + ", response code: " + responseCode, cause);
this.url = url;
this.responseCode = responseCode;
this.data = null;
}
public ResponseCodeException(URL url, int responseCode, String data) {
super("Unable to request url " + url + ", response code: " + responseCode + ", data: " + data);
this.url = url;