Properly save auth chain

This commit is contained in:
AlexProgrammerDE 2024-07-18 12:38:18 +02:00
parent add31d1f62
commit ed795b25db
2 changed files with 11 additions and 8 deletions

View file

@ -849,14 +849,14 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
return false;
}
task.cleanup(); // player is online -> remove pending authentication immediately
return task.getAuthentication().handle((response, ex) -> {
return task.getAuthentication().handle((result, ex) -> {
if (ex != null) {
geyser.getLogger().error("Failed to log in with Microsoft code!", ex);
disconnect(ex.toString());
return false;
}
StepMCProfile.MCProfile mcProfile = response.getMcProfile();
StepMCProfile.MCProfile mcProfile = result.session().getMcProfile();
StepMCToken.MCToken mcToken = mcProfile.getMcToken();
this.protocol = new MinecraftProtocol(
@ -871,8 +871,8 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
return false;
}
// Save our refresh token for later use
geyser.saveAuthChain(bedrockUsername(), mcToken.getXblXsts().getInitialXblSession().getMsaToken().getRefreshToken());
// Save our auth chain for later use
geyser.saveAuthChain(bedrockUsername(), GSON.toJson(result.step().toJson(result.session())));
return true;
}).join();
}

View file

@ -99,7 +99,7 @@ public class PendingMicrosoftAuthentication {
private final String userKey;
private final int timeoutSec;
@Getter
private CompletableFuture<StepFullJavaSession.FullJavaSession> authentication;
private CompletableFuture<StepChainResult> authentication;
private AuthenticationTask(String userKey, int timeoutSec) {
this.userKey = userKey;
@ -123,11 +123,11 @@ public class PendingMicrosoftAuthentication {
authentications.invalidate(userKey);
}
public CompletableFuture<StepFullJavaSession.FullJavaSession> performLoginAttempt(boolean offlineAccess, Consumer<StepMsaDeviceCode.MsaDeviceCode> deviceCodeConsumer) {
public CompletableFuture<StepChainResult> performLoginAttempt(boolean offlineAccess, Consumer<StepMsaDeviceCode.MsaDeviceCode> deviceCodeConsumer) {
return authentication = CompletableFuture.supplyAsync(() -> {
try {
return AUTH_FLOW.apply(offlineAccess, timeoutSec)
.getFromInput(AUTH_CLIENT, new StepMsaDeviceCode.MsaDeviceCodeCallback(deviceCodeConsumer));
StepFullJavaSession step = AUTH_FLOW.apply(offlineAccess, timeoutSec);
return new StepChainResult(step, step.getFromInput(AUTH_CLIENT, new StepMsaDeviceCode.MsaDeviceCodeCallback(deviceCodeConsumer)));
} catch (Exception e) {
throw new CompletionException(e);
}
@ -153,4 +153,7 @@ public class PendingMicrosoftAuthentication {
super(userKey, timeoutSec);
}
}
public record StepChainResult(StepFullJavaSession step, StepFullJavaSession.FullJavaSession session) {
}
}