4141import lombok .experimental .Accessors ;
4242import net .kyori .adventure .key .Key ;
4343import net .kyori .adventure .text .Component ;
44- import net .raphimc .minecraftauth .responsehandler .exception .MinecraftRequestException ;
45- import net .raphimc .minecraftauth .step .java .StepMCProfile ;
46- import net .raphimc .minecraftauth .step .java .StepMCToken ;
47- import net .raphimc .minecraftauth .step .java .session .StepFullJavaSession ;
44+ import net .raphimc .minecraftauth .java .JavaAuthManager ;
45+ import net .raphimc .minecraftauth .java .exception .MinecraftProfileNotFoundException ;
46+ import net .raphimc .minecraftauth .java .model .MinecraftProfile ;
47+ import net .raphimc .minecraftauth .java .model .MinecraftToken ;
48+ import net .raphimc .minecraftauth .util .MinecraftAuth4To5Migrator ;
4849import org .checkerframework .checker .index .qual .NonNegative ;
4950import org .checkerframework .checker .index .qual .Positive ;
5051import org .checkerframework .checker .nullness .qual .MonotonicNonNull ;
113114import org .geysermc .geyser .GeyserImpl ;
114115import org .geysermc .geyser .api .bedrock .camera .CameraData ;
115116import org .geysermc .geyser .api .bedrock .camera .CameraShake ;
116- import org .geysermc .geyser .input .InputLocksFlag ;
117117import org .geysermc .geyser .api .connection .GeyserConnection ;
118118import org .geysermc .geyser .api .entity .EntityData ;
119119import org .geysermc .geyser .api .entity .type .GeyserEntity ;
143143import org .geysermc .geyser .event .type .SessionDisconnectEventImpl ;
144144import org .geysermc .geyser .impl .camera .CameraDefinitions ;
145145import org .geysermc .geyser .impl .camera .GeyserCameraData ;
146+ import org .geysermc .geyser .input .InputLocksFlag ;
146147import org .geysermc .geyser .inventory .Inventory ;
147148import org .geysermc .geyser .inventory .InventoryHolder ;
148149import org .geysermc .geyser .inventory .LecternContainer ;
196197import org .geysermc .geyser .util .InventoryUtils ;
197198import org .geysermc .geyser .util .LoginEncryptionUtils ;
198199import org .geysermc .geyser .util .MathUtils ;
199- import org .geysermc .geyser .util .MinecraftAuthLogger ;
200200import org .geysermc .mcprotocollib .auth .GameProfile ;
201201import org .geysermc .mcprotocollib .network .BuiltinFlags ;
202202import org .geysermc .mcprotocollib .network .ClientSession ;
@@ -925,23 +925,28 @@ public void authenticateWithAuthChain(String authChain) {
925925 loggingIn = true ;
926926
927927 CompletableFuture .supplyAsync (() -> {
928- StepFullJavaSession step = PendingMicrosoftAuthentication .AUTH_FLOW .apply (true , 30 );
929- StepFullJavaSession .FullJavaSession response ;
928+ JavaAuthManager authManager ;
929+ MinecraftProfile mcProfile ;
930+ MinecraftToken mcToken ;
930931 try {
931- response = step .refresh (MinecraftAuthLogger .INSTANCE , PendingMicrosoftAuthentication .AUTH_CLIENT , step .fromJson (GSON .fromJson (authChain , JsonObject .class )));
932+ JsonObject parsedAuthChain = GSON .fromJson (authChain , JsonObject .class );
933+ if (parsedAuthChain .has ("mcProfile" )) { // Old Minecraft v4 auth chain
934+ parsedAuthChain = MinecraftAuth4To5Migrator .migrateJavaSave (parsedAuthChain , GeyserImpl .OAUTH_CONFIG );
935+ }
936+
937+ authManager = JavaAuthManager .fromJson (PendingMicrosoftAuthentication .AUTH_CLIENT , parsedAuthChain );
938+ mcProfile = authManager .getMinecraftProfile ().getUpToDate ();
939+ mcToken = authManager .getMinecraftToken ().getUpToDate ();
932940 } catch (Exception e ) {
933941 geyser .getLogger ().error ("Error while attempting to use auth chain for " + bedrockUsername () + "!" , e );
934942 return Boolean .FALSE ;
935943 }
936944
937- StepMCProfile .MCProfile mcProfile = response .getMcProfile ();
938- StepMCToken .MCToken mcToken = mcProfile .getMcToken ();
939-
940945 protocol = new MinecraftProtocol (
941946 new GameProfile (mcProfile .getId (), mcProfile .getName ()),
942- mcToken .getAccessToken ()
947+ mcToken .getToken ()
943948 );
944- geyser .saveAuthChain (bedrockUsername (), GSON .toJson (step .toJson (response )));
949+ geyser .saveAuthChain (bedrockUsername (), GSON .toJson (JavaAuthManager .toJson (authManager )));
945950 return Boolean .TRUE ;
946951 }).whenComplete ((successful , ex ) -> {
947952 if (this .closed ) {
@@ -1009,9 +1014,7 @@ public boolean onMicrosoftLoginComplete(PendingMicrosoftAuthentication.Authentic
10091014 return task .getAuthentication ().handle ((result , ex ) -> {
10101015 if (ex != null ) {
10111016 geyser .getLogger ().error ("Failed to log in with Microsoft code!" , ex );
1012- if (ex instanceof CompletionException ce
1013- && ce .getCause () instanceof MinecraftRequestException mre
1014- && mre .getResponse ().getStatusCode () == 404 ) {
1017+ if (ex instanceof CompletionException ce && ce .getCause () instanceof MinecraftProfileNotFoundException ) {
10151018 // Player is trying to join with a Microsoft account that doesn't have Java Edition purchased
10161019 disconnect (GeyserLocale .getPlayerLocaleString ("geyser.network.remote.invalid_account" , locale ()));
10171020 } else {
@@ -1020,12 +1023,12 @@ public boolean onMicrosoftLoginComplete(PendingMicrosoftAuthentication.Authentic
10201023 return false ;
10211024 }
10221025
1023- StepMCProfile . MCProfile mcProfile = result .session ().getMcProfile ();
1024- StepMCToken . MCToken mcToken = mcProfile . getMcToken ();
1026+ MinecraftProfile mcProfile = result .getMinecraftProfile ().getCached ();
1027+ MinecraftToken mcToken = result . getMinecraftToken (). getCached ();
10251028
10261029 this .protocol = new MinecraftProtocol (
10271030 new GameProfile (mcProfile .getId (), mcProfile .getName ()),
1028- mcToken .getAccessToken ()
1031+ mcToken .getToken ()
10291032 );
10301033
10311034 try {
@@ -1036,7 +1039,7 @@ public boolean onMicrosoftLoginComplete(PendingMicrosoftAuthentication.Authentic
10361039 }
10371040
10381041 // Save our auth chain for later use
1039- geyser .saveAuthChain (bedrockUsername (), GSON .toJson (result . step (). toJson (result . session () )));
1042+ geyser .saveAuthChain (bedrockUsername (), GSON .toJson (JavaAuthManager . toJson (result )));
10401043 return true ;
10411044 }).getNow (false );
10421045 }
0 commit comments