mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-23 12:05:44 +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) -> {
|
||||
TokenError error = req.returnContent().asJson(TokenError.class);
|
||||
|
||||
return new AuthenticationException(error.errorDescription);
|
||||
return new AuthenticationException(error.errorDescription, true);
|
||||
})
|
||||
.returnContent()
|
||||
.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 ->
|
||||
setResult(new OfflineSession(launcher.getProperties().getProperty("offlinePlayerName"))));
|
||||
@ -145,8 +145,7 @@ public class AccountSelectDialog extends JDialog {
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void attemptMicrosoftLogin() {
|
||||
String status = SharedLocale.tr("login.microsoft.seeBrowser");
|
||||
private void attemptMicrosoftLogin(String status) {
|
||||
SettableProgress progress = new SettableProgress(status, -1);
|
||||
|
||||
ListenableFuture<?> future = launcher.getExecutor().submit(() -> {
|
||||
@ -181,15 +180,9 @@ public class AccountSelectDialog extends JDialog {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
if (t instanceof AuthenticationException) {
|
||||
if (((AuthenticationException) t).isInvalidatedSession()) {
|
||||
// Just need to log in again
|
||||
LoginDialog.ReloginDetails details = new LoginDialog.ReloginDetails(session.getUsername(),
|
||||
SharedLocale.tr("login.relogin", t.getLocalizedMessage()));
|
||||
Session newSession = LoginDialog.showLoginRequest(AccountSelectDialog.this, launcher, details);
|
||||
|
||||
setResult(newSession);
|
||||
}
|
||||
if (t instanceof AuthenticationException && ((AuthenticationException) t).isInvalidatedSession()) {
|
||||
// Just need to log in again
|
||||
relogin(session, t.getLocalizedMessage());
|
||||
} else {
|
||||
SwingHelper.showErrorDialog(AccountSelectDialog.this, t.getLocalizedMessage(), SharedLocale.tr("errorTitle"), t);
|
||||
}
|
||||
@ -200,6 +193,22 @@ public class AccountSelectDialog extends JDialog {
|
||||
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
|
||||
private static class RestoreSessionCallable implements Callable<Session>, ProgressObservable {
|
||||
private final LoginService service;
|
||||
|
Loading…
Reference in New Issue
Block a user