Skip to content

Commit

Permalink
By refering the commit GeyserMC#4147, revert the mojang login function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shanwer committed Dec 24, 2023
1 parent a0d6048 commit 110051a
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 38 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/org/geysermc/geyser/GeyserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,11 @@ private void startInstance() {
}

if (config.getRemote().authType() == AuthType.ONLINE) {
if (config.getUserAuths() != null && !config.getUserAuths().isEmpty()) {
getLogger().warning("The 'userAuths' config section is now deprecated, and will be removed in the near future! " +
"Please migrate to the new 'saved-user-logins' config option: " +
"https://wiki.geysermc.org/geyser/understanding-the-config/");
}
// May be written/read to on multiple threads from each GeyserSession as well as writing the config
savedRefreshTokens = new ConcurrentHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import java.nio.file.Path;
import java.util.List;
import java.util.Map;

public interface GeyserConfiguration {
/**
Expand All @@ -52,6 +53,8 @@ public interface GeyserConfiguration {

List<String> getSavedUserLogins();

Map<String, ? extends IUserAuthenticationInfo> getUserAuths();

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
boolean isCommandSuggestions();

Expand All @@ -76,10 +79,6 @@ public interface GeyserConfiguration {

boolean isAllowThirdPartyEars();

String getAuthBaseUri();

String getSessionBaseUri();

String getShowCooldown();

boolean isShowCoordinates();
Expand Down Expand Up @@ -146,6 +145,8 @@ interface IRemoteConfiguration extends RemoteServer {

void setPort(int port);

boolean isPasswordAuthentication();

boolean isUseProxyProtocol();

boolean isForwardHost();
Expand All @@ -159,8 +160,17 @@ default int protocolVersion() {
}

void setAuthType(AuthType authType);


}

interface IUserAuthenticationInfo {
String getEmail();

String getPassword();

boolean isMicrosoftAccount();
}
interface IMetricsInfo {

boolean isEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

Expand All @@ -67,6 +68,8 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration

public abstract Path getFloodgateKeyPath();

private Map<String, UserAuthenticationInfo> userAuths;

@JsonProperty("command-suggestions")
private boolean commandSuggestions = true;

Expand Down Expand Up @@ -276,6 +279,10 @@ public boolean resolveSrv() {
return false;
}

@Getter
@JsonProperty("allow-password-authentication")
private boolean passwordAuthentication = true;

@Getter
@JsonProperty("use-proxy-protocol")
private boolean useProxyProtocol = false;
Expand All @@ -285,6 +292,19 @@ public boolean resolveSrv() {
private boolean forwardHost = false;
}

@Getter
@JsonIgnoreProperties(ignoreUnknown = true) // DO NOT REMOVE THIS! Otherwise, after we remove microsoft-account configs will not load
public static class UserAuthenticationInfo implements IUserAuthenticationInfo {
@AsteriskSerializer.Asterisk()
private String email;

@AsteriskSerializer.Asterisk()
private String password;

@JsonProperty("microsoft-account")
private boolean microsoftAccount = false;
}

@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
public static class MetricsInfo implements IMetricsInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.geysermc.geyser.api.pack.PackCodec;
import org.geysermc.geyser.api.pack.ResourcePack;
import org.geysermc.geyser.api.pack.ResourcePackManifest;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.event.type.SessionLoadResourcePacksEventImpl;
import org.geysermc.geyser.pack.GeyserResourcePack;
import org.geysermc.geyser.registry.BlockRegistries;
Expand Down Expand Up @@ -261,6 +262,15 @@ private boolean couldLoginUserByName(String bedrockUsername) {
return true;
}
}
if (geyser.getConfig().getUserAuths() != null) {
GeyserConfiguration.IUserAuthenticationInfo info = geyser.getConfig().getUserAuths().get(bedrockUsername);

if (info != null) {
geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.auth.stored_credentials", session.getAuthData().name()));
session.authenticate(info.getEmail(), info.getPassword());
return true;
}
}
PendingMicrosoftAuthentication.AuthenticationTask task = geyser.getPendingMicrosoftAuthentication().getTask(session.getAuthData().xuid());
if (task != null) {
return task.getAuthentication().isDone() && session.onMicrosoftLoginComplete(task);
Expand Down
22 changes: 0 additions & 22 deletions core/src/main/java/org/geysermc/geyser/session/GeyserSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -736,11 +736,6 @@ public void authenticate(String username,String password){
if (password != null && !password.isEmpty()) {
AuthenticationService authenticationService = new MojangAuthenticationService();

String authBaseUri = geyser.getConfig().getAuthBaseUri();
if (!authBaseUri.isEmpty()) {
if (!authBaseUri.endsWith("/")) authBaseUri += "/";
authenticationService.setBaseUri(authBaseUri);
}
authenticationService.setUsername(username);
authenticationService.setPassword(password);
authenticationService.login();
Expand Down Expand Up @@ -787,20 +782,13 @@ public void authenticateWithRefreshToken(String refreshToken) {

CompletableFuture.supplyAsync(() -> {
MsaAuthenticationService service = new MsaAuthenticationService(GeyserImpl.OAUTH_CLIENT_ID);

service.setRefreshToken(refreshToken);
try {
service.login();
} catch (RequestException e) {
geyser.getLogger().error("Error while attempting to use refresh token for " + bedrockUsername() + "!", e);
return Boolean.FALSE;
}
AuthenticationService authenticationService = new MojangAuthenticationService();
String authBaseUri = geyser.getConfig().getAuthBaseUri();
if (!authBaseUri.isEmpty()) {
if (!authBaseUri.endsWith("/")) authBaseUri += "/";
authenticationService.setBaseUri(authBaseUri);
}
GameProfile profile = service.getSelectedProfile();
if (profile == null) {
// Java account is offline
Expand Down Expand Up @@ -941,16 +929,6 @@ private void connectDownstream() {
downstream = new LocalSession(this.remoteServer.address(), this.remoteServer.port(),
geyser.getBootstrap().getSocketAddress(), upstream.getAddress().getAddress().getHostAddress(),
this.protocol, this.protocol.createHelper());

String sessionBaseUri = geyser.getConfig().getSessionBaseUri();
if (!sessionBaseUri.isEmpty()) {
if (!sessionBaseUri.endsWith("/")) sessionBaseUri += "/";
if (!sessionBaseUri.endsWith("session/minecraft/")) sessionBaseUri += "session/minecraft/";

SessionService sessionService = new SessionService();
sessionService.setBaseUri(sessionBaseUri);
downstream.setFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
}
this.downstream = new DownstreamSession(downstream);
} else {
downstream = new TcpClientSession(this.remoteServer.address(), this.remoteServer.port(), this.protocol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
import org.cloudburstmc.protocol.bedrock.util.ChainValidationResult;
import org.cloudburstmc.protocol.bedrock.util.ChainValidationResult.IdentityData;
import org.cloudburstmc.protocol.bedrock.util.EncryptionUtils;
import org.geysermc.cumulus.form.CustomForm;
import org.geysermc.cumulus.form.ModalForm;
import org.geysermc.cumulus.form.SimpleForm;
import org.geysermc.cumulus.response.SimpleFormResponse;
import org.geysermc.cumulus.response.result.FormResponseResult;
import org.geysermc.cumulus.response.result.ValidFormResponseResult;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.auth.AuthData;
import org.geysermc.geyser.session.auth.BedrockClientData;
Expand Down Expand Up @@ -135,20 +137,31 @@ public static void buildAndShowLoginWindow(GeyserSession session) {
// Set DoDaylightCycle to false so the time doesn't accelerate while we're here
session.setDaylightCycle(false);

GeyserConfiguration config = session.getGeyser().getConfig();
boolean isPasswordAuthEnabled = config.getRemote().isPasswordAuthentication();

session.sendForm(
SimpleForm.builder()
.translator(GeyserLocale::getPlayerLocaleString, session.locale())
.title("geyser.auth.login.form.notice.title")
.content("geyser.auth.login.form.notice.desc")
.optionalButton("geyser.auth.login.form.notice.btn_login.mojang", isPasswordAuthEnabled)
.button("geyser.auth.login.form.notice.btn_login.microsoft")
.button("geyser.auth.login.form.notice.btn_disconnect")
.closedOrInvalidResultHandler(() -> buildAndShowLoginWindow(session))
.validResultHandler((response) -> {
if (response.clickedButtonId() == 0) {
if (response.clickedButtonId() == 0){
buildAndShowLoginDetailsWindow(session);
return;
}

if (response.clickedButtonId() == 1) {
session.authenticateWithMicrosoftCode();
return;
}



session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.form.disconnect", session.locale()));
}));
}
Expand Down Expand Up @@ -199,6 +212,18 @@ private static BiConsumer<SimpleForm, FormResponseResult<SimpleFormResponse>> au
}
};
}
public static void buildAndShowLoginDetailsWindow(GeyserSession session) {
session.sendForm(
CustomForm.builder()
.translator(GeyserLocale::getPlayerLocaleString, session.locale())
.title("geyser.auth.login.form.details.title")
.label("geyser.auth.login.form.details.desc")
.input("geyser.auth.login.form.details.email", "[email protected]", "")
.input("geyser.auth.login.form.details.pass", "123456", "")
.invalidResultHandler(() -> buildAndShowLoginDetailsWindow(session))
.closedResultHandler(() -> buildAndShowLoginWindow(session))
.validResultHandler((response) -> session.authenticate(response.next(), response.next())));
}

/**
* Shows the code that a user must input into their browser
Expand Down
11 changes: 0 additions & 11 deletions core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,6 @@ debug-mode: false
# OptiFine capes, LabyMod capes, 5Zig capes and MinecraftCapes
allow-third-party-capes: false

# Set a custom base URI for the authentication server.
# Should look similar to the following: https://authserver.example.com/
# You don't need this, unless you run your own auth server.
# Leave empty to use the official auth servers.
auth-base-uri: ""
# Set a custom base URI for the session server.
# Should look similar to the following: https://session.example.com/
# You don't need this, unless you run your own session server.
# Leave empty to use the official session servers.
session-base-uri: ""

# Allow third party deadmau5 ears to be visible. Currently allowing:
# MinecraftCapes
allow-third-party-ears: false
Expand Down

0 comments on commit 110051a

Please sign in to comment.