1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-27 12:46:22 +01:00

Fix launcher not prompting for re-login if refresh token expired

This commit is contained in:
Henry Le Grys 2024-10-26 03:57:03 +01:00
parent d27c74688a
commit 669e3f53fa
2 changed files with 22 additions and 13 deletions

View File

@ -87,7 +87,7 @@ public class MicrosoftLoginService implements LoginService {
.expectResponseCodeOr(200, (req) -> { .expectResponseCodeOr(200, (req) -> {
TokenError error = req.returnContent().asJson(TokenError.class); TokenError error = req.returnContent().asJson(TokenError.class);
return new AuthenticationException(error.errorDescription); return new AuthenticationException(error.errorDescription, true);
}) })
.returnContent() .returnContent()
.asJson(TokenResponse.class); .asJson(TokenResponse.class);

View File

@ -102,7 +102,7 @@ public class AccountSelectDialog extends JDialog {
} }
}); });
addMicrosoftButton.addActionListener(ev -> attemptMicrosoftLogin()); addMicrosoftButton.addActionListener(ev -> attemptMicrosoftLogin(SharedLocale.tr("login.microsoft.seeBrowser")));
offlineButton.addActionListener(ev -> offlineButton.addActionListener(ev ->
setResult(new OfflineSession(launcher.getProperties().getProperty("offlinePlayerName")))); setResult(new OfflineSession(launcher.getProperties().getProperty("offlinePlayerName"))));
@ -145,8 +145,7 @@ public class AccountSelectDialog extends JDialog {
dispose(); dispose();
} }
private void attemptMicrosoftLogin() { private void attemptMicrosoftLogin(String status) {
String status = SharedLocale.tr("login.microsoft.seeBrowser");
SettableProgress progress = new SettableProgress(status, -1); SettableProgress progress = new SettableProgress(status, -1);
ListenableFuture<?> future = launcher.getExecutor().submit(() -> { ListenableFuture<?> future = launcher.getExecutor().submit(() -> {
@ -181,15 +180,9 @@ public class AccountSelectDialog extends JDialog {
@Override @Override
public void onFailure(Throwable t) { public void onFailure(Throwable t) {
if (t instanceof AuthenticationException) { if (t instanceof AuthenticationException && ((AuthenticationException) t).isInvalidatedSession()) {
if (((AuthenticationException) t).isInvalidatedSession()) { // Just need to log in again
// Just need to log in again relogin(session, t.getLocalizedMessage());
LoginDialog.ReloginDetails details = new LoginDialog.ReloginDetails(session.getUsername(),
SharedLocale.tr("login.relogin", t.getLocalizedMessage()));
Session newSession = LoginDialog.showLoginRequest(AccountSelectDialog.this, launcher, details);
setResult(newSession);
}
} else { } else {
SwingHelper.showErrorDialog(AccountSelectDialog.this, t.getLocalizedMessage(), SharedLocale.tr("errorTitle"), t); SwingHelper.showErrorDialog(AccountSelectDialog.this, t.getLocalizedMessage(), SharedLocale.tr("errorTitle"), t);
} }
@ -200,6 +193,22 @@ public class AccountSelectDialog extends JDialog {
SharedLocale.tr("login.loggingInStatus")); SharedLocale.tr("login.loggingInStatus"));
} }
/**
* Re-login to an expired session
*/
private void relogin(SavedSession session, String message) {
if (session.getType() == UserType.MICROSOFT) {
this.attemptMicrosoftLogin(message);
} else {
LoginDialog.ReloginDetails details = new LoginDialog.ReloginDetails(session.getUsername(),
SharedLocale.tr("login.relogin", message));
Session newSession = LoginDialog.showLoginRequest(AccountSelectDialog.this, launcher, details);
launcher.getAccounts().update(newSession.toSavedSession());
setResult(newSession);
}
}
@RequiredArgsConstructor @RequiredArgsConstructor
private static class RestoreSessionCallable implements Callable<Session>, ProgressObservable { private static class RestoreSessionCallable implements Callable<Session>, ProgressObservable {
private final LoginService service; private final LoginService service;