mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 16:16:04 -04:00
[MSA new] Throw exception when response error; Progress bar re-impl
This commit is contained in:
parent
3aa5621c97
commit
83d6f64958
@ -19,12 +19,14 @@ import net.kdt.pojavlaunch.value.launcherprofiles.*;
|
||||
import net.kdt.pojavlaunch.value.*;
|
||||
|
||||
public class MicrosoftAuthTask extends AsyncTask<String, Void, Object> {
|
||||
/*
|
||||
private static final String authTokenUrl = "https://login.live.com/oauth20_token.srf";
|
||||
private static final String xblAuthUrl = "https://user.auth.xboxlive.com/user/authenticate";
|
||||
private static final String xstsAuthUrl = "https://xsts.auth.xboxlive.com/xsts/authorize";
|
||||
private static final String mcLoginUrl = "https://api.minecraftservices.com/authentication/login_with_xbox";
|
||||
// private static final String mcStoreUrl = "https://api.minecraftservices.com/entitlements/mcstore";
|
||||
private static final String mcStoreUrl = "https://api.minecraftservices.com/entitlements/mcstore";
|
||||
private static final String mcProfileUrl = "https://api.minecraftservices.com/minecraft/profile";
|
||||
*/
|
||||
|
||||
//private Gson gson = new Gson();
|
||||
private RefreshListener listener;
|
||||
@ -43,14 +45,13 @@ public class MicrosoftAuthTask extends AsyncTask<String, Void, Object> {
|
||||
build.setMessage(ctx.getString(R.string.global_waiting));
|
||||
build.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
build.setCancelable(false);
|
||||
build.setMax(5);
|
||||
build.setMax(6);
|
||||
build.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object doInBackground(String... args) {
|
||||
try {
|
||||
|
||||
String authCode = args[0];
|
||||
/*
|
||||
publishProgress();
|
||||
@ -68,7 +69,7 @@ public class MicrosoftAuthTask extends AsyncTask<String, Void, Object> {
|
||||
publishProgress();
|
||||
|
||||
*/
|
||||
Msa msa = new Msa(authCode);
|
||||
Msa msa = new Msa(this, authCode);
|
||||
|
||||
// TODO migrate account format to json
|
||||
//MinecraftAccount acc = new MinecraftAccount();
|
||||
@ -82,7 +83,6 @@ public class MicrosoftAuthTask extends AsyncTask<String, Void, Object> {
|
||||
profilePath.setIsMojangAccount(false);
|
||||
}
|
||||
|
||||
|
||||
MCProfile.build(profilePath);
|
||||
|
||||
return profilePath;
|
||||
@ -91,6 +91,10 @@ public class MicrosoftAuthTask extends AsyncTask<String, Void, Object> {
|
||||
}
|
||||
}
|
||||
|
||||
public void publishProgressPublic() {
|
||||
super.publishProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Void[] p1) {
|
||||
super.onProgressUpdate(p1);
|
||||
|
@ -29,11 +29,12 @@ import java.util.UUID;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import android.os.*;
|
||||
|
||||
|
||||
|
||||
public class Msa {
|
||||
|
||||
/*
|
||||
private static final String loginUrl = "https://login.live.com/oauth20_authorize.srf" +
|
||||
"?client_id=00000000402b5328" +
|
||||
"&response_type=code" +
|
||||
@ -41,31 +42,32 @@ public class Msa {
|
||||
"&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf";
|
||||
|
||||
private static final String redirectUrlSuffix = "https://login.live.com/oauth20_desktop.srf?code=";
|
||||
|
||||
*/
|
||||
private static final String authTokenUrl = "https://login.live.com/oauth20_token.srf";
|
||||
|
||||
private static final String xblAuthUrl = "https://user.auth.xboxlive.com/user/authenticate";
|
||||
|
||||
private static final String xstsAuthUrl = "https://xsts.auth.xboxlive.com/xsts/authorize";
|
||||
|
||||
private static final String mcLoginUrl = "https://api.minecraftservices.com/authentication/login_with_xbox";
|
||||
|
||||
private static final String mcStoreUrl = "https://api.minecraftservices.com/entitlements/mcstore";
|
||||
|
||||
private static final String mcProfileUrl = "https://api.minecraftservices.com/minecraft/profile";
|
||||
|
||||
private MicrosoftAuthTask task;
|
||||
|
||||
public String mcName;
|
||||
public String mcToken;
|
||||
public String mcUuid;
|
||||
public boolean doesOwnGame;
|
||||
public Msa(String authCode) throws IOException, JSONException {
|
||||
|
||||
public Msa(MicrosoftAuthTask task, String authCode) throws IOException, JSONException {
|
||||
this.task = task;
|
||||
acquireAccessToken(authCode);
|
||||
}
|
||||
|
||||
public void acquireAccessToken(String authcode) throws IOException, JSONException {
|
||||
task.publishProgressPublic();
|
||||
|
||||
URL url = new URL(authTokenUrl);
|
||||
Log.i("MicroAuth","authCode= "+authcode);
|
||||
Map<Object, Object> data = new HashMap();/*Map.of(
|
||||
Map<Object, Object> data = new HashMap<>();/*Map.of(
|
||||
"client_id", "00000000402b5328",
|
||||
"code", authcode,
|
||||
"grant_type", "authorization_code",
|
||||
@ -103,16 +105,18 @@ public class Msa {
|
||||
acquireXBLToken(jo.getString("access_token"));
|
||||
}else{
|
||||
Log.i("MicroAuth","Error code: " + conn.getResponseCode() + ": "+conn.getResponseMessage());
|
||||
throw new RuntimeException("MSA Error: " + conn.getResponseCode() + ": " + conn.getResponseMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void acquireXBLToken(String accessToken) throws IOException, JSONException {
|
||||
task.publishProgressPublic();
|
||||
|
||||
URL url = new URL(xblAuthUrl);
|
||||
|
||||
Map<Object, Object> data = new HashMap();
|
||||
Map<Object, Object> properties = new HashMap();
|
||||
Map<Object, Object> data = new HashMap<>();
|
||||
Map<Object, Object> properties = new HashMap<>();
|
||||
properties.put("AuthMethod", "RPS");
|
||||
properties.put("SiteName", "user.auth.xboxlive.com");
|
||||
properties.put("RpsTicket", accessToken);
|
||||
@ -154,13 +158,16 @@ public class Msa {
|
||||
acquireXsts(jo.getString("Token"));
|
||||
}else{
|
||||
Log.i("MicroAuth","Error code: " + conn.getResponseCode() + ": "+conn.getResponseMessage());
|
||||
throw new RuntimeException("MSA Error: " + conn.getResponseCode() + ": " + conn.getResponseMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void acquireXsts(String xblToken) throws IOException, JSONException {
|
||||
task.publishProgressPublic();
|
||||
|
||||
URL url = new URL(xstsAuthUrl);
|
||||
Map<Object, Object> data = new HashMap();
|
||||
Map<Object, Object> properties = new HashMap();
|
||||
Map<Object, Object> data = new HashMap<>();
|
||||
Map<Object, Object> properties = new HashMap<>();
|
||||
properties.put("SandboxId", "RETAIL");
|
||||
properties.put("UserTokens",Collections.singleton(xblToken));
|
||||
data.put("Properties",properties);
|
||||
@ -202,13 +209,16 @@ public class Msa {
|
||||
acquireMinecraftToken(uhs,jo.getString("Token"));
|
||||
}else{
|
||||
Log.i("MicroAuth","Error code: " + conn.getResponseCode() + ": "+conn.getResponseMessage());
|
||||
throw new RuntimeException("MSA Error: " + conn.getResponseCode() + ": " + conn.getResponseMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void acquireMinecraftToken(String xblUhs, String xblXsts) throws IOException, JSONException {
|
||||
task.publishProgressPublic();
|
||||
|
||||
URL url = new URL(mcLoginUrl);
|
||||
|
||||
Map<Object, Object> data = new HashMap();
|
||||
Map<Object, Object> data = new HashMap<>();
|
||||
data.put("identityToken", "XBL3.0 x=" + xblUhs + ";" + xblXsts);
|
||||
|
||||
String req = ofJSONData(data);
|
||||
@ -240,9 +250,12 @@ public class Msa {
|
||||
|
||||
}else{
|
||||
Log.i("MicroAuth","Error code: " + conn.getResponseCode() + ": "+conn.getResponseMessage());
|
||||
throw new RuntimeException("MSA Error: " + conn.getResponseCode() + ": " + conn.getResponseMessage());
|
||||
}
|
||||
}
|
||||
private void checkMcStore(String mcAccessToken) throws IOException, JSONException {
|
||||
task.publishProgressPublic();
|
||||
|
||||
URL url = new URL(mcStoreUrl);
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
conn.setRequestProperty("Authorization", "Bearer " + mcAccessToken);
|
||||
@ -264,6 +277,7 @@ public class Msa {
|
||||
}
|
||||
}else{
|
||||
Log.i("MicroAuth","Error code: " + conn.getResponseCode() + ": "+conn.getResponseMessage());
|
||||
throw new RuntimeException("MSA Error: " + conn.getResponseCode() + ": " + conn.getResponseMessage());
|
||||
}
|
||||
/*
|
||||
HttpRequest request = HttpRequest.newBuilder(uri)
|
||||
@ -280,6 +294,8 @@ public class Msa {
|
||||
}
|
||||
|
||||
private void checkMcProfile(String mcAccessToken) throws IOException, JSONException {
|
||||
task.publishProgressPublic();
|
||||
|
||||
URL url = new URL(mcProfileUrl);
|
||||
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
@ -309,14 +325,12 @@ public class Msa {
|
||||
Log.i("MicroAuth","Error code: " + conn.getResponseCode() + ": "+conn.getResponseMessage());
|
||||
Log.i("MicroAuth","It seems that this Microshit Account does not own the game.");
|
||||
doesOwnGame = false;
|
||||
throw new RuntimeException("MSA Error: " + conn.getResponseCode() + ": " + conn.getResponseMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static String ofJSONData(Map<Object, Object> data) {
|
||||
return new JSONObject(data).toString();
|
||||
|
||||
}
|
||||
|
||||
public static String ofFormData(Map<Object, Object> data) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user