Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Dec 9, 2024
1 parent 8ad8afd commit 1fdd721
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jackhuang.hmcl.Metadata;
import org.jackhuang.hmcl.auth.Account;
import org.jackhuang.hmcl.auth.ServerResponseMalformedException;
import org.jackhuang.hmcl.auth.littleskin.LittleSkinAccount;
import org.jackhuang.hmcl.auth.microsoft.MicrosoftAccount;
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
import org.jackhuang.hmcl.auth.offline.Skin;
Expand Down Expand Up @@ -355,7 +356,7 @@ public static void bindAvatar(Canvas canvas, YggdrasilService service, UUID uuid
}

public static void bindAvatar(Canvas canvas, Account account) {
if (account instanceof YggdrasilAccount || account instanceof MicrosoftAccount || account instanceof OfflineAccount)
if (account instanceof YggdrasilAccount || account instanceof MicrosoftAccount || account instanceof LittleSkinAccount || account instanceof OfflineAccount)
fxAvatarBinding(canvas, skinBinding(account));
else {
unbindAvatar(canvas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public abstract class Account implements Observable {

/**
* @return the character name
*
*/
public abstract String getCharacter();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,24 @@
*/
package org.jackhuang.hmcl.auth.littleskin;

import javafx.beans.binding.ObjectBinding;
import org.jackhuang.hmcl.auth.AuthInfo;
import org.jackhuang.hmcl.auth.AuthenticationException;
import org.jackhuang.hmcl.auth.OAuthAccount;
import org.jackhuang.hmcl.auth.ServerResponseMalformedException;
import org.jackhuang.hmcl.auth.yggdrasil.Texture;
import org.jackhuang.hmcl.auth.yggdrasil.TextureType;
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilService;
import org.jackhuang.hmcl.util.javafx.BindingMapping;

import java.nio.file.Path;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

import static org.jackhuang.hmcl.util.logging.Logger.LOG;

/**
* @author Glavo
*/
Expand Down Expand Up @@ -98,6 +106,19 @@ public AuthInfo playOffline() {
return session.toAuthInfo();
}

@Override
public ObjectBinding<Optional<Map<TextureType, Texture>>> getTextures() {
return BindingMapping.of(service.getProfileRepository().binding(getUUID()))
.map(profile -> profile.flatMap(it -> {
try {
return YggdrasilService.getTextures(it);
} catch (ServerResponseMalformedException e) {
LOG.warning("Failed to parse texture payload", e);
return Optional.empty();
}
}));
}

@Override
public boolean canUploadSkin() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import com.google.gson.JsonParseException;
import org.jackhuang.hmcl.auth.*;
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorProvider;
import org.jackhuang.hmcl.auth.yggdrasil.CompleteGameProfile;
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilService;
import org.jackhuang.hmcl.util.JWTToken;
import org.jackhuang.hmcl.util.javafx.ObservableOptionalCache;

import java.nio.file.Path;
import java.util.UUID;
Expand All @@ -40,12 +42,17 @@ public final class LittleSkinService extends OAuthService {
"https://open.littleskin.cn/oauth/token"
);
private static final String SCOPE = "openid offline_access User.Read Player.ReadWrite Yggdrasil.PlayerProfiles.Select Yggdrasil.Server.Join";
private static final YggdrasilService YGGDRASIL_SERVICE = new YggdrasilService(new AuthlibInjectorProvider(API_ROOT));

private final YggdrasilService yggdrasilService = new YggdrasilService(new AuthlibInjectorProvider(API_ROOT));

public LittleSkinService(OAuth.Callback callback) {
super(OAUTH, SCOPE, callback);
}

public ObservableOptionalCache<UUID, CompleteGameProfile, AuthenticationException> getProfileRepository() {
return yggdrasilService.getProfileRepository();
}

private static LittleSkinSession fromResult(OAuth.Result result) throws JsonParseException {
LittleSkinIdToken idToken = JWTToken.parse(LittleSkinIdToken.class, result.getIdToken()).getPayload();
idToken.validate();
Expand Down Expand Up @@ -75,10 +82,10 @@ public boolean validate(LittleSkinSession session) throws AuthenticationExceptio
return false;
}

return YGGDRASIL_SERVICE.validate(session.getAccessToken(), null);
return yggdrasilService.validate(session.getAccessToken(), null);
}

public void uploadSkin(UUID uuid, String accessToken, boolean isSlim, Path file) throws AuthenticationException, UnsupportedOperationException {
YGGDRASIL_SERVICE.uploadSkin(uuid, accessToken, isSlim, file);
yggdrasilService.uploadSkin(uuid, accessToken, isSlim, file);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import org.jackhuang.hmcl.auth.AuthenticationException;
import org.jackhuang.hmcl.auth.OAuthService;
import org.jackhuang.hmcl.auth.ServerDisconnectException;
import org.jackhuang.hmcl.auth.ServerResponseMalformedException;
import org.jackhuang.hmcl.util.StringUtils;
Expand Down Expand Up @@ -57,8 +56,6 @@ public class YggdrasilService {
private final YggdrasilProvider provider;
private final ObservableOptionalCache<UUID, CompleteGameProfile, AuthenticationException> profileRepository;

private final OAuthService oAuthService = null; // TODO

public YggdrasilService(YggdrasilProvider provider) {
this.provider = provider;
this.profileRepository = new ObservableOptionalCache<>(
Expand Down

0 comments on commit 1fdd721

Please sign in to comment.