[MSA] Bug fix: Cancel button gives "Login success"

This commit is contained in:
khanhduytran0 2020-12-09 18:39:19 +07:00
parent 4e1a4e223d
commit aa417be5a6
4 changed files with 80 additions and 5 deletions

View File

@ -25,7 +25,7 @@ public class RefreshTokenTask extends AsyncTask<String, Void, Throwable> {
@Override
public void onPreExecute() {
build = new ProgressDialog(ctx);
build.setMessage("Refreshing");
build.setMessage(ctx.getString(R.string.global_waiting));
build.setProgressStyle(ProgressDialog.STYLE_SPINNER);
build.setCancelable(false);
build.show();
@ -37,7 +37,7 @@ public class RefreshTokenTask extends AsyncTask<String, Void, Throwable> {
this.profilePath = MCProfile.load(args[0]);
int responseCode = 400;
responseCode = this.authenticator.validate(profilePath.getAccessToken()).statusCode;
if (400 <= responseCode) {
if (responseCode >= 200 && responseCode < 300) {
RefreshResponse response = this.authenticator.refresh(profilePath.getAccessToken(), UUID.fromString(profilePath.getClientID()));
// if (response == null) {
// throw new NullPointerException("Response is null?");

View File

@ -12,7 +12,7 @@ public class NetworkResponse
}
public void throwExceptionIfNeed(String msg) {
if (statusCode >= 400) {
if (statusCode < 200 || statusCode >= 300) {
throw new RuntimeException(msg);
}
}

View File

@ -314,9 +314,11 @@ public class PojavLoginActivity extends BaseActivity
if (data != null && data.getScheme().equals("ms-xal-00000000402b5328") && data.getHost().equals("auth")) {
String error = data.getQueryParameter("error");
String error_description = data.getQueryParameter("error_description");
if (error != null && !error_description.startsWith("The user has denied access to the scope requested by the client application")) {
if (error != null) {
// "The user has denied access to the scope requested by the client application": user pressed Cancel button, skip it
Toast.makeText(this, "Error: " + error + ": " + error_description, Toast.LENGTH_LONG).show();
if (!error_description.startsWith("The user has denied access to the scope requested by the client application")) {
Toast.makeText(this, "Error: " + error + ": " + error_description, Toast.LENGTH_LONG).show();
}
} else {
String code = data.getQueryParameter("code");
Toast.makeText(this, "Logged in to Microsoft account, but NYI", Toast.LENGTH_LONG).show();

View File

@ -0,0 +1,73 @@
package net.kdt.pojavlaunch.authenticator.microsoft;
import android.app.*;
import android.content.*;
import android.os.*;
import com.kdt.mojangauth.*;
import com.kdt.mojangauth.yggdrasil.*;
import java.util.*;
import net.kdt.pojavlaunch.*;
public class MicrosoftAuthenticator extends AsyncTask<String, Void, Throwable> {
private YggdrasilAuthenticator authenticator = new YggdrasilAuthenticator();
//private Gson gson = new Gson();
private RefreshListener listener;
private Context ctx;
private ProgressDialog build;
public MicrosoftAuthenticator(Context ctx, RefreshListener listener) {
this.ctx = ctx;
this.listener = listener;
}
@Override
public void onPreExecute() {
build = new ProgressDialog(ctx);
build.setMessage(ctx.getString(R.string.global_waiting));
build.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
build.setCancelable(false);
build.show();
}
@Override
public Throwable doInBackground(String... args) {
try {
MCProfile.Builder profilePath = MCProfile.load(args[0]);
String authCode = args[1];
publishProgress();
/*
profilePath.setClientID(response.clientToken.toString());
profilePath.setAccessToken(response.accessToken);
profilePath.setUsername(response.selectedProfile.name);
profilePath.setProfileID(response.selectedProfile.id);
MCProfile.build(profilePath);
*/
return null;
} catch (Throwable e) {
return e;
}
}
@Override
protected void onProgressUpdate(Void[] p1) {
super.onProgressUpdate(p1);
build.setProgress(build.getProgress() + 1);
}
@Override
public void onPostExecute(Throwable result) {
build.dismiss();
if (result == null) {
listener.onSuccess();
} else {
listener.onFailed(result);
}
}
}