Skip to content

Commit

Permalink
Replace MCAuth with RK_01 MinecraftAuth (#795)
Browse files Browse the repository at this point in the history
* Initial work on moving over mcauth

* Initial work on importing MinecraftAuth

* Make compile

* Remove extra headers code

* Switch to different http utils

* Merge changes

* Cleanup

* Remove unused exceptions and constructors

* Implement proxies

* Fixup proxy stuff

* Cleanup

* Remove SR license header

* Remove custom exceptions

* Move auth into main module

Auth has become so small that it's not worth keeping separate

* Make ProxyInfo be part of network again

* Fix indent

* Allow null id and name in GameProfile

* Fix remaining logs

* Make texture checker more accurate

* Fix spaces

* Update dependencies

* Remove usage of var

* Use faster approach for reading raw uuids.
  • Loading branch information
AlexProgrammerDE authored Jun 17, 2024
1 parent 5624d77 commit 471e92e
Show file tree
Hide file tree
Showing 29 changed files with 904 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.geysermc.mcprotocollib.auth.example;

import net.raphimc.minecraftauth.MinecraftAuth;
import net.raphimc.minecraftauth.step.java.StepMCProfile;
import net.raphimc.minecraftauth.step.java.StepMCToken;
import net.raphimc.minecraftauth.step.java.session.StepFullJavaSession;
import net.raphimc.minecraftauth.step.msa.StepCredentialsMsaCode;
import org.geysermc.mcprotocollib.auth.GameProfile;
import org.geysermc.mcprotocollib.auth.SessionService;
import org.geysermc.mcprotocollib.network.ProxyInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MinecraftAuthTest {
private static final Logger log = LoggerFactory.getLogger(MinecraftAuthTest.class);
private static final String EMAIL = "[email protected]";
private static final String PASSWORD = "Password";
private static final boolean REQUIRE_SECURE_TEXTURES = true;

private static final ProxyInfo PROXY = null;

public static void main(String[] args) {
auth();
}

private static void auth() {
SessionService service = new SessionService();
service.setProxy(PROXY);

StepFullJavaSession.FullJavaSession fullJavaSession;
try {
fullJavaSession = MinecraftAuth.JAVA_CREDENTIALS_LOGIN.getFromInput(
MinecraftAuth.createHttpClient(),
new StepCredentialsMsaCode.MsaCredentials(EMAIL, PASSWORD));
} catch (Exception e) {
throw new RuntimeException(e);
}

StepMCProfile.MCProfile mcProfile = fullJavaSession.getMcProfile();
StepMCToken.MCToken mcToken = mcProfile.getMcToken();
GameProfile profile = new GameProfile(mcProfile.getId(), mcProfile.getName());
try {
service.fillProfileProperties(profile);

log.info("Selected Profile: {}", profile);
log.info("Selected Profile Textures: {}", profile.getTextures(REQUIRE_SECURE_TEXTURES));
log.info("Access Token: {}", mcToken.getAccessToken());
log.info("Expire Time: {}", mcToken.getExpireTimeMs());
} catch (Exception e) {
log.error("Failed to get properties and textures of selected profile {}.", profile, e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.geysermc.mcprotocollib.protocol.example;

import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.auth.exception.request.RequestException;
import com.github.steveice10.mc.auth.service.AuthenticationService;
import com.github.steveice10.mc.auth.service.MojangAuthenticationService;
import com.github.steveice10.mc.auth.service.SessionService;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.raphimc.minecraftauth.MinecraftAuth;
import net.raphimc.minecraftauth.step.java.StepMCProfile;
import net.raphimc.minecraftauth.step.java.StepMCToken;
import net.raphimc.minecraftauth.step.java.session.StepFullJavaSession;
import net.raphimc.minecraftauth.step.msa.StepCredentialsMsaCode;
import org.geysermc.mcprotocollib.auth.GameProfile;
import org.geysermc.mcprotocollib.auth.SessionService;
import org.geysermc.mcprotocollib.network.ProxyInfo;
import org.geysermc.mcprotocollib.network.Server;
import org.geysermc.mcprotocollib.network.Session;
Expand Down Expand Up @@ -36,7 +38,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.Proxy;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
Expand All @@ -51,7 +52,7 @@ public class MinecraftProtocolTest {
private static final String HOST = "127.0.0.1";
private static final int PORT = 25565;
private static final ProxyInfo PROXY = null;
private static final Proxy AUTH_PROXY = Proxy.NO_PROXY;
private static final ProxyInfo AUTH_PROXY = null;
private static final String USERNAME = "Username";
private static final String PASSWORD = "Password";

Expand Down Expand Up @@ -177,19 +178,21 @@ private static void status() {
private static void login() {
MinecraftProtocol protocol;
if (VERIFY_USERS) {
StepFullJavaSession.FullJavaSession fullJavaSession;
try {
AuthenticationService authService = new MojangAuthenticationService();
authService.setUsername(USERNAME);
authService.setPassword(PASSWORD);
authService.setProxy(AUTH_PROXY);
authService.login();

protocol = new MinecraftProtocol(authService.getSelectedProfile(), authService.getAccessToken());
log.info("Successfully authenticated user.");
} catch (RequestException e) {
log.error("Failed to authenticate user.", e);
return;
fullJavaSession = MinecraftAuth.JAVA_CREDENTIALS_LOGIN.getFromInput(
MinecraftAuth.createHttpClient(),
new StepCredentialsMsaCode.MsaCredentials(USERNAME, PASSWORD));
} catch (Exception e) {
throw new RuntimeException(e);
}

StepMCProfile.MCProfile mcProfile = fullJavaSession.getMcProfile();
StepMCToken.MCToken mcToken = mcProfile.getMcToken();
protocol = new MinecraftProtocol(
new GameProfile(mcProfile.getId(), mcProfile.getName()),
mcToken.getAccessToken());
log.info("Successfully authenticated user.");
} else {
protocol = new MinecraftProtocol(USERNAME);
}
Expand Down
8 changes: 6 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ metadata.format.version = "1.1"

adventure = "4.15.0"
cloudburstnbt = "3.0.0.Final"
mcauthlib = "e5b0bcc"
slf4j = "2.0.9"
math = "2.0"
fastutil-maps = "8.5.3"
netty = "4.1.103.Final"
netty-io_uring = "0.0.24.Final"
gson = "2.11.0"
minecraftauth = "4.0.2"
checkerframework = "3.42.0"
junit = "5.8.2"

Expand All @@ -24,7 +25,6 @@ adventure-text-serializer-gson = { module = "net.kyori:adventure-text-serializer
adventure-text-serializer-json-legacy-impl = { module = "net.kyori:adventure-text-serializer-json-legacy-impl", version.ref = "adventure" }

cloudburstnbt = { module = "org.cloudburstmc:nbt", version.ref = "cloudburstnbt" }
mcauthlib = { module = "com.github.GeyserMC:mcauthlib", version.ref = "mcauthlib" }

slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" }
Expand All @@ -39,6 +39,10 @@ fastutil-int2int-maps = { module = "com.nukkitx.fastutil:fastutil-int-int-maps",
netty-all = { module = "io.netty:netty-all", version.ref = "netty" }
netty-incubator-transport-native-io_uring = { module = "io.netty.incubator:netty-incubator-transport-native-io_uring", version.ref = "netty-io_uring" }

gson = { module = "com.google.code.gson:gson", version.ref = "gson" }

minecraftauth = { module = "net.raphimc:MinecraftAuth", version.ref = "minecraftauth" }

checkerframework-qual = { module = "org.checkerframework:checker-qual", version.ref = "checkerframework" }

junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
Expand Down
7 changes: 6 additions & 1 deletion protocol/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ description = "MCProtocolLib is a simple library for communicating with Minecraf
dependencies {
// Minecraft related libraries
api(libs.cloudburstnbt)
api(libs.mcauthlib)

// Gson
api(libs.gson)

// MinecraftAuth for authentication
api(libs.minecraftauth)

// Slf4j
api(libs.slf4j.api)
Expand Down
Loading

0 comments on commit 471e92e

Please sign in to comment.