|
25 | 25 | import org.jackhuang.hmcl.auth.OAuth; |
26 | 26 | import org.jackhuang.hmcl.auth.ServerDisconnectException; |
27 | 27 | import org.jackhuang.hmcl.auth.ServerResponseMalformedException; |
28 | | -import org.jackhuang.hmcl.auth.yggdrasil.*; |
| 28 | +import org.jackhuang.hmcl.auth.yggdrasil.CompleteGameProfile; |
| 29 | +import org.jackhuang.hmcl.auth.yggdrasil.RemoteAuthenticationException; |
| 30 | +import org.jackhuang.hmcl.auth.yggdrasil.Texture; |
| 31 | +import org.jackhuang.hmcl.auth.yggdrasil.TextureType; |
29 | 32 | import org.jackhuang.hmcl.util.StringUtils; |
30 | 33 | import org.jackhuang.hmcl.util.gson.*; |
31 | 34 | import org.jackhuang.hmcl.util.io.*; |
@@ -245,7 +248,16 @@ private static MinecraftProfileResponse getMinecraftProfile(String tokenType, St |
245 | 248 | .createConnection(); |
246 | 249 | int responseCode = conn.getResponseCode(); |
247 | 250 | if (responseCode == HTTP_NOT_FOUND) { |
248 | | - throw new NoMinecraftJavaEditionProfileException(); |
| 251 | + MinecraftLicense license = HttpRequest.GET("https://api.minecraftservices.com/entitlements/license") |
| 252 | + .authorization(tokenType, accessToken) |
| 253 | + .getJson(MinecraftLicense.class); |
| 254 | + boolean hasMinecraftLicense = license != null && license.items() != null && license.items().stream() |
| 255 | + .anyMatch(item -> "game_minecraft".equals(item.name())); |
| 256 | + if (!hasMinecraftLicense) { |
| 257 | + throw new MinecraftJavaEditionLicenseNotFoundException(); |
| 258 | + } else { |
| 259 | + throw new MinecraftJavaEditionProfileNotFoundException(); |
| 260 | + } |
249 | 261 | } else if (responseCode != 200) { |
250 | 262 | throw new ResponseCodeException("https://api.minecraftservices.com/minecraft/profile", responseCode); |
251 | 263 | } |
@@ -324,7 +336,10 @@ public String getRedirect() { |
324 | 336 | public final static class XBox400Exception extends AuthenticationException { |
325 | 337 | } |
326 | 338 |
|
327 | | - public final static class NoMinecraftJavaEditionProfileException extends AuthenticationException { |
| 339 | + public final static class MinecraftJavaEditionProfileNotFoundException extends AuthenticationException { |
| 340 | + } |
| 341 | + |
| 342 | + public final static class MinecraftJavaEditionLicenseNotFoundException extends AuthenticationException { |
328 | 343 | } |
329 | 344 |
|
330 | 345 | public final static class NoXuiException extends AuthenticationException { |
@@ -425,6 +440,21 @@ public static class MinecraftProfileResponseCape { |
425 | 440 |
|
426 | 441 | } |
427 | 442 |
|
| 443 | + @JsonSerializable |
| 444 | + public record MinecraftLicense( |
| 445 | + @SerializedName("items") List<MinecraftLicenseItem> items, |
| 446 | + @SerializedName("signature") String signature, |
| 447 | + @SerializedName("keyId") String keyId |
| 448 | + ) { |
| 449 | + } |
| 450 | + |
| 451 | + @JsonSerializable |
| 452 | + public record MinecraftLicenseItem( |
| 453 | + @SerializedName("name") String name, |
| 454 | + @SerializedName("signature") String signature |
| 455 | + ) { |
| 456 | + } |
| 457 | + |
428 | 458 | public static class MinecraftProfileResponse extends MinecraftErrorResponse implements Validation { |
429 | 459 | @SerializedName("id") |
430 | 460 | UUID id; |
|
0 commit comments