mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-24 12:16:28 +01:00
Fix launcher not prompting for re-login if refresh token expired
This commit is contained in:
parent
d27c74688a
commit
669e3f53fa
@ -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);
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user