mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-13 06:39:54 -04:00
[MSA] Remove unnecessary step + Only refresh when token expires
This commit is contained in:
parent
08863de824
commit
f0ef0bddd2
@ -595,7 +595,7 @@ public class PojavLoginActivity extends BaseActivity {
|
||||
Log.e("Account","Stop torturing me sempai");
|
||||
return;
|
||||
}
|
||||
if (acc.isMicrosoft){
|
||||
if (acc.isMicrosoft && System.currentTimeMillis() > acc.expiresAt){
|
||||
new MicrosoftAuthTask(PojavLoginActivity.this, authListener)
|
||||
.execute("true", acc.msaRefreshToken);
|
||||
} else {
|
||||
|
@ -46,7 +46,7 @@ public class MicrosoftAuthTask extends AsyncTask<String, Void, Object> {
|
||||
build.setMessage(ctx.get().getString(R.string.global_waiting));
|
||||
build.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
build.setCancelable(false);
|
||||
build.setMax(6);
|
||||
build.setMax(5);
|
||||
build.show();
|
||||
}
|
||||
|
||||
@ -80,6 +80,7 @@ public class MicrosoftAuthTask extends AsyncTask<String, Void, Object> {
|
||||
acc.profileId = msa.mcUuid;
|
||||
acc.isMicrosoft = true;
|
||||
acc.msaRefreshToken = msa.msRefreshToken;
|
||||
acc.expiresAt = msa.expiresAt;
|
||||
acc.updateSkinFace();
|
||||
}
|
||||
acc.save();
|
||||
|
@ -18,7 +18,6 @@ public class Msa {
|
||||
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;
|
||||
@ -29,6 +28,7 @@ public class Msa {
|
||||
public String mcToken;
|
||||
public String mcUuid;
|
||||
public boolean doesOwnGame;
|
||||
public long expiresAt;
|
||||
|
||||
public Msa(MicrosoftAuthTask task, boolean isRefresh, String authCode) throws IOException, JSONException {
|
||||
this.task = task;
|
||||
@ -194,37 +194,16 @@ public class Msa {
|
||||
}
|
||||
|
||||
if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) {
|
||||
expiresAt = System.currentTimeMillis() + 86400000;
|
||||
JSONObject jo = new JSONObject(Tools.read(conn.getInputStream()));
|
||||
Log.i("MicroAuth","MC token: "+jo.getString("access_token"));
|
||||
mcToken = jo.getString("access_token");
|
||||
checkMcProfile(jo.getString("access_token"));
|
||||
checkMcStore(jo.getString("access_token"));
|
||||
|
||||
}else{
|
||||
throwResponseError(conn);
|
||||
}
|
||||
}
|
||||
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);
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setUseCaches(false);
|
||||
conn.connect();
|
||||
if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) {
|
||||
JSONObject jo = new JSONObject(Tools.read(conn.getInputStream()));
|
||||
JSONArray ja = jo.getJSONArray("items");
|
||||
Log.i("MicroAuth","Store Len = " + ja.length());
|
||||
for(int i = 0; i < ja.length(); i++) {
|
||||
String prod = ja.getJSONObject(i).getString("name");
|
||||
Log.i("MicroAuth","Product " + i +": " +prod);
|
||||
}
|
||||
}else{
|
||||
throwResponseError(conn);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkMcProfile(String mcAccessToken) throws IOException, JSONException {
|
||||
task.publishProgressPublic();
|
||||
@ -242,7 +221,7 @@ public class Msa {
|
||||
JSONObject jsonObject = new JSONObject(s);
|
||||
String name = (String) jsonObject.get("name");
|
||||
String uuid = (String) jsonObject.get("id");
|
||||
String uuidDashes = uuid .replaceFirst(
|
||||
String uuidDashes = uuid.replaceFirst(
|
||||
"(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5"
|
||||
);
|
||||
doesOwnGame = true;
|
||||
|
@ -21,6 +21,7 @@ public class MinecraftAccount
|
||||
public boolean isMicrosoft = false;
|
||||
public String msaRefreshToken = "0";
|
||||
public String skinFaceBase64;
|
||||
public long expiresAt;
|
||||
|
||||
void updateSkinFace(String uuid) {
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user