Skip to content

MicrosoftAuthenticator login functions doesn't seem to actually log in the player #43

Description

@theavgeekbee

Describe the bug
When running any login method in MicrosoftAuthenticator, the client doesn't seem to log in. I verified this by running the loginWithCredentials method with my own credentials, but no exception was thrown. When logging into singleplayer, I was still on the default Fabric profile of "Player###" and multiplayer yielded "Invalid Session".

To Reproduce
Steps to reproduce the behavior:

  1. In FabricMC, set up OpenAuth in Gradle normally.
  2. In the startup code, I put
MicrosoftAuthenticator auth = new MicrosoftAuthenticator();
try {
    MicrosoftAuthResult res = authenticator.loginWithCredentials("[email redacted]", password);
    MinecraftProfile prof = res.getProfile();
    System.out.println("Logged in as " + prof.getName() + " (" + prof.getId() + ")");
} catch (MicrosoftAuthenticationException e) {
    e.printStackTrace();
}
  1. I started FabricMC
  2. I saw "Logged in as ...", but in singleplayer, I got the default FabricMC username, and when I tried joining a server, I got "Invalid Session".

Expected behavior
I expected OpenAuth to actually set the session.

Desktop (please complete the following information, if Self-Hosted):

  • OS: Windows
  • Java version 17.0.9-termium
  • Version: Latest (1.6.1?)

Additional context
I found a solution to this problem by manually setting a session. In my alt manager class, I created the function login(), which logs in the player.

public static Session session;
public static void login() {
        File secret = new File(".secret");
        String password;
        try {
            password = Files.readString(secret.toPath());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        try {
            MicrosoftAuthResult res = authenticator.loginWithCredentials("[email redacted]", password);
            MinecraftProfile prof = res.getProfile();

            session = new Session(
                    prof.getName(),
                    getFormattedUUID(prof.getId()),
                    res.getAccessToken(),
                    Optional.empty(),
                    Optional.empty(),
                    Session.AccountType.MSA
            );
            System.out.println("Logged in as " + prof.getName() + " (" + prof.getId() + ")");
        } catch (MicrosoftAuthenticationException e) {
            throw new RuntimeException(e);
        }
    }

Then, I created a mixin:

@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
    @Inject(at = @At("HEAD"), method = "getSession()Lnet/minecraft/client/session/Session;", cancellable = true)
    public void getSession(CallbackInfoReturnable<Session> cir) {
        if (AltManager.session != null)
            cir.setReturnValue(AltManager.session);
    }
}

This solved my problem, except the skins don't load. This is probably due to the missing clientId and xuid fields that I set to Optional.empty() in this code. I'm not sure yet, but I think OpenAuth has these fields in the code. I hope that this could be implemented in the future.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions