mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-13 14:51:51 -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");
|
Log.e("Account","Stop torturing me sempai");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (acc.isMicrosoft){
|
if (acc.isMicrosoft && System.currentTimeMillis() > acc.expiresAt){
|
||||||
new MicrosoftAuthTask(PojavLoginActivity.this, authListener)
|
new MicrosoftAuthTask(PojavLoginActivity.this, authListener)
|
||||||
.execute("true", acc.msaRefreshToken);
|
.execute("true", acc.msaRefreshToken);
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,7 +46,7 @@ public class MicrosoftAuthTask extends AsyncTask<String, Void, Object> {
|
|||||||
build.setMessage(ctx.get().getString(R.string.global_waiting));
|
build.setMessage(ctx.get().getString(R.string.global_waiting));
|
||||||
build.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
build.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||||
build.setCancelable(false);
|
build.setCancelable(false);
|
||||||
build.setMax(6);
|
build.setMax(5);
|
||||||
build.show();
|
build.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +80,7 @@ public class MicrosoftAuthTask extends AsyncTask<String, Void, Object> {
|
|||||||
acc.profileId = msa.mcUuid;
|
acc.profileId = msa.mcUuid;
|
||||||
acc.isMicrosoft = true;
|
acc.isMicrosoft = true;
|
||||||
acc.msaRefreshToken = msa.msRefreshToken;
|
acc.msaRefreshToken = msa.msRefreshToken;
|
||||||
|
acc.expiresAt = msa.expiresAt;
|
||||||
acc.updateSkinFace();
|
acc.updateSkinFace();
|
||||||
}
|
}
|
||||||
acc.save();
|
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 xblAuthUrl = "https://user.auth.xboxlive.com/user/authenticate";
|
||||||
private static final String xstsAuthUrl = "https://xsts.auth.xboxlive.com/xsts/authorize";
|
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 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 static final String mcProfileUrl = "https://api.minecraftservices.com/minecraft/profile";
|
||||||
|
|
||||||
private MicrosoftAuthTask task;
|
private MicrosoftAuthTask task;
|
||||||
@ -29,6 +28,7 @@ public class Msa {
|
|||||||
public String mcToken;
|
public String mcToken;
|
||||||
public String mcUuid;
|
public String mcUuid;
|
||||||
public boolean doesOwnGame;
|
public boolean doesOwnGame;
|
||||||
|
public long expiresAt;
|
||||||
|
|
||||||
public Msa(MicrosoftAuthTask task, boolean isRefresh, String authCode) throws IOException, JSONException {
|
public Msa(MicrosoftAuthTask task, boolean isRefresh, String authCode) throws IOException, JSONException {
|
||||||
this.task = task;
|
this.task = task;
|
||||||
@ -194,37 +194,16 @@ public class Msa {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) {
|
if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) {
|
||||||
|
expiresAt = System.currentTimeMillis() + 86400000;
|
||||||
JSONObject jo = new JSONObject(Tools.read(conn.getInputStream()));
|
JSONObject jo = new JSONObject(Tools.read(conn.getInputStream()));
|
||||||
Log.i("MicroAuth","MC token: "+jo.getString("access_token"));
|
Log.i("MicroAuth","MC token: "+jo.getString("access_token"));
|
||||||
mcToken = jo.getString("access_token");
|
mcToken = jo.getString("access_token");
|
||||||
checkMcProfile(jo.getString("access_token"));
|
checkMcProfile(jo.getString("access_token"));
|
||||||
checkMcStore(jo.getString("access_token"));
|
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
throwResponseError(conn);
|
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 {
|
private void checkMcProfile(String mcAccessToken) throws IOException, JSONException {
|
||||||
task.publishProgressPublic();
|
task.publishProgressPublic();
|
||||||
@ -242,7 +221,7 @@ public class Msa {
|
|||||||
JSONObject jsonObject = new JSONObject(s);
|
JSONObject jsonObject = new JSONObject(s);
|
||||||
String name = (String) jsonObject.get("name");
|
String name = (String) jsonObject.get("name");
|
||||||
String uuid = (String) jsonObject.get("id");
|
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"
|
"(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5"
|
||||||
);
|
);
|
||||||
doesOwnGame = true;
|
doesOwnGame = true;
|
||||||
|
@ -21,6 +21,7 @@ public class MinecraftAccount
|
|||||||
public boolean isMicrosoft = false;
|
public boolean isMicrosoft = false;
|
||||||
public String msaRefreshToken = "0";
|
public String msaRefreshToken = "0";
|
||||||
public String skinFaceBase64;
|
public String skinFaceBase64;
|
||||||
|
public long expiresAt;
|
||||||
|
|
||||||
void updateSkinFace(String uuid) {
|
void updateSkinFace(String uuid) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user