fix: Microsoft Account add family hint.
This commit is contained in:
@@ -136,7 +136,7 @@ public class MicrosoftService {
|
||||
|
||||
if (response.displayClaims == null || response.displayClaims.xui == null || response.displayClaims.xui.size() == 0 || !response.displayClaims.xui.get(0).containsKey("uhs")) {
|
||||
LOG.log(Level.WARNING, "Unrecognized xbox authorization response " + GSON.toJson(response));
|
||||
throw new ServerResponseMalformedException();
|
||||
throw new NoXuiException();
|
||||
}
|
||||
|
||||
String uhs = (String) response.displayClaims.xui.get(0).get("uhs");
|
||||
@@ -169,6 +169,7 @@ public class MicrosoftService {
|
||||
mapOf(pair("SandboxId", "RETAIL"),
|
||||
pair("UserTokens", Collections.singletonList(xboxResponse.token)))),
|
||||
pair("RelyingParty", "rp://api.minecraftservices.com/"), pair("TokenType", "JWT")))
|
||||
.ignoreHttpErrorCode(401)
|
||||
.getJson(XBoxLiveAuthenticationResponse.class);
|
||||
|
||||
getUhs(minecraftXstsResponse, uhs);
|
||||
@@ -331,6 +332,9 @@ public class MicrosoftService {
|
||||
public static class NoMinecraftJavaEditionProfileException extends AuthenticationException {
|
||||
}
|
||||
|
||||
public static class NoXuiException extends AuthenticationException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Error response: {"error":"invalid_grant","error_description":"The provided
|
||||
* value for the 'redirect_uri' is not valid. The value must exactly match the
|
||||
|
||||
@@ -31,7 +31,9 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
@@ -46,6 +48,7 @@ public abstract class HttpRequest {
|
||||
protected final String method;
|
||||
protected final Map<String, String> headers = new HashMap<>();
|
||||
protected ExceptionalBiConsumer<URL, Integer, IOException> responseCodeTester;
|
||||
protected final Set<Integer> toleratedHttpCodes = new HashSet<>();
|
||||
|
||||
private HttpRequest(String url, String method) {
|
||||
this.url = url;
|
||||
@@ -92,6 +95,11 @@ public abstract class HttpRequest {
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpRequest ignoreHttpErrorCode(int code) {
|
||||
toleratedHttpCodes.add(code);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpURLConnection createConnection() throws IOException {
|
||||
HttpURLConnection con = createHttpConnection(new URL(url));
|
||||
con.setRequestMethod(method);
|
||||
@@ -157,7 +165,10 @@ public abstract class HttpRequest {
|
||||
responseCodeTester.accept(new URL(url), con.getResponseCode());
|
||||
} else {
|
||||
if (con.getResponseCode() / 100 != 2) {
|
||||
throw new ResponseCodeException(new URL(url), con.getResponseCode());
|
||||
if (!toleratedHttpCodes.contains(con.getResponseCode())) {
|
||||
String data = NetworkUtils.readData(con);
|
||||
throw new ResponseCodeException(new URL(url), con.getResponseCode(), data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,20 @@ public class ResponseCodeException extends IOException {
|
||||
|
||||
private final URL url;
|
||||
private final int responseCode;
|
||||
private final String data;
|
||||
|
||||
public ResponseCodeException(URL url, int responseCode) {
|
||||
super("Unable to request url " + url + ", response code: " + responseCode);
|
||||
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;
|
||||
this.responseCode = responseCode;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public URL getUrl() {
|
||||
@@ -38,4 +47,8 @@ public class ResponseCodeException extends IOException {
|
||||
public int getResponseCode() {
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user