From b189173b34be9cdf06e592472c60e31911a0c2ab Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Tue, 9 Feb 2021 02:21:56 +0000 Subject: [PATCH] Use cached avatar in MicrosoftLoginService --- .../launcher/auth/MicrosoftLoginService.java | 13 +++++++++---- .../launcher/auth/YggdrasilLoginService.java | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/launcher/src/main/java/com/skcraft/launcher/auth/MicrosoftLoginService.java b/launcher/src/main/java/com/skcraft/launcher/auth/MicrosoftLoginService.java index 3d418fc..476fd5d 100644 --- a/launcher/src/main/java/com/skcraft/launcher/auth/MicrosoftLoginService.java +++ b/launcher/src/main/java/com/skcraft/launcher/auth/MicrosoftLoginService.java @@ -38,7 +38,7 @@ public class MicrosoftLoginService implements LoginService { form.add("code", code); }); - Profile session = performLogin(response.getAccessToken()); + Profile session = performLogin(response.getAccessToken(), null); session.setRefreshToken(response.getRefreshToken()); return session; @@ -52,7 +52,7 @@ public class MicrosoftLoginService implements LoginService { form.add("refresh_token", savedSession.getRefreshToken()); }); - Profile session = performLogin(response.getAccessToken()); + Profile session = performLogin(response.getAccessToken(), savedSession); session.setRefreshToken(response.getRefreshToken()); return session; @@ -77,14 +77,19 @@ public class MicrosoftLoginService implements LoginService { } } - private Profile performLogin(String microsoftToken) + private Profile performLogin(String microsoftToken, SavedSession previous) throws IOException, InterruptedException, AuthenticationException { XboxAuthorization xboxAuthorization = XboxTokenAuthorizer.authorizeWithXbox(microsoftToken); McAuthResponse auth = MinecraftServicesAuthorizer.authorizeWithMinecraft(xboxAuthorization); McProfileResponse profile = MinecraftServicesAuthorizer.getUserProfile(auth); Profile session = new Profile(auth, profile); - session.setAvatarImage(VisageSkinService.fetchSkinHead(profile.getUuid())); + if (previous != null && previous.getAvatarImage() != null) { + session.setAvatarImage(previous.getAvatarImage()); + } else { + session.setAvatarImage(VisageSkinService.fetchSkinHead(profile.getUuid())); + } + return session; } diff --git a/launcher/src/main/java/com/skcraft/launcher/auth/YggdrasilLoginService.java b/launcher/src/main/java/com/skcraft/launcher/auth/YggdrasilLoginService.java index e83248e..be78e63 100644 --- a/launcher/src/main/java/com/skcraft/launcher/auth/YggdrasilLoginService.java +++ b/launcher/src/main/java/com/skcraft/launcher/auth/YggdrasilLoginService.java @@ -58,10 +58,10 @@ public class YggdrasilLoginService implements LoginService { AuthenticateResponse response = req.returnContent().asJson(AuthenticateResponse.class); Profile profile = response.getSelectedProfile(); - if (previous == null || previous.getAvatarImage() == null) { - profile.setAvatarImage(VisageSkinService.fetchSkinHead(profile.getUuid())); - } else { + if (previous != null && previous.getAvatarImage() != null) { profile.setAvatarImage(previous.getAvatarImage()); + } else { + profile.setAvatarImage(VisageSkinService.fetchSkinHead(profile.getUuid())); } return profile;