headlessmc icon indicating copy to clipboard operation
headlessmc copied to clipboard

Microsoft login expires every 3 days, clearing all credentials

Open tiehu opened this issue 10 months ago • 7 comments

After logging into my Microsoft account using the login command (via the browser link https://www.microsoft.com/link?otc=...), the login consistently fails every 3 days (very precisely, always 3 days apart) with the following error:

[08:10:09] [main/INFO] [MinecraftAuth]: Authenticating with Xbox Live using SISU...
[08:10:15] [main/SEVERE] [AbstractLaunchProcessLifecycle]: Couldn't launch fabric-loader-0.16.13-1.21.4: status: 401 Unauthorized, error: 2148916276, error message: Unknown error
me.earth.headlessmc.api.command.CommandException: status: 401 Unauthorized, error: 2148916276, error message: Unknown error
        at me.earth.headlessmc.launcher.command.LaunchCommand.getAccount(LaunchCommand.java:95)
        at me.earth.headlessmc.launcher.command.LaunchCommand$ClientLaunchProcessLifecycle.getAccount(LaunchCommand.java:56)
        at me.earth.headlessmc.launcher.command.AbstractLaunchProcessLifecycle.runProcess(AbstractLaunchProcessLifecycle.java:114)
        at me.earth.headlessmc.launcher.command.AbstractLaunchProcessLifecycle.run(AbstractLaunchProcessLifecycle.java:60)
        at me.earth.headlessmc.launcher.command.LaunchCommand.execute(LaunchCommand.java:42)
        at me.earth.headlessmc.launcher.command.LaunchCommand.execute(LaunchCommand.java:20)
        at me.earth.headlessmc.launcher.command.FindByCommand.execute(FindByCommand.java:42)
        at me.earth.headlessmc.api.command.CommandContextImpl.executeCommand(CommandContextImpl.java:54)
        at me.earth.headlessmc.api.command.CommandContextImpl.execute(CommandContextImpl.java:33)
        at me.earth.headlessmc.api.command.line.CommandLine.lambda$new$0(CommandLine.java:45)
        at me.earth.headlessmc.jline.JLineCommandLineReader.read(JLineCommandLineReader.java:84)
        at me.earth.headlessmc.api.command.line.CommandLine.read(CommandLine.java:83)
        at me.earth.headlessmc.launcher.Main.runHeadlessMc(Main.java:61)
        at me.earth.headlessmc.launcher.Main.main(Main.java:20)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:569)
        at me.earth.headlessmc.wrapper.Main.main(Main.java:35)

Couldn't launch fabric-loader-0.16.13-1.21.4: status: 401 Unauthorized, error: 2148916276, error message: Unknown error

At the same time, all stored credentials in the HeadlessMC/auth/.account.json file are cleared, forcing me to perform the login process again.

I suspect this is related to the token refresh mechanism. I am using HeadlessMC to perform a series of automated tasks through scripts and crontab jobs, so I would really appreciate a solution that does not require manual intervention (or at least not this frequently).

Thank you very much for your work on this project!

tiehu avatar Jun 13 '25 04:06 tiehu

By the way, I've also noticed that sometimes when there is network instability (e.g., an HTTP connect timed out error), all stored account credentials are also cleared immediately. I'm not sure if this is intended behavior, but it makes recovery harder in cases of temporary connection issues.

tiehu avatar Jun 13 '25 04:06 tiehu

Odd, will look into it. Usually the refresh token is valid for quite a while, so 3 days is odd.

3arthqu4ke avatar Jun 13 '25 06:06 3arthqu4ke

Odd, will look into it. Usually the refresh token is valid for quite a while, so 3 days is odd.

Did you find a solution? I have this problem also.

att131 avatar Jun 30 '25 15:06 att131

Okay, I added the following line to my automation script:

cp ./HeadlessMC/auth/.accounts.json.bak ./HeadlessMC/auth/.accounts.json

That means I first made a backup of the .accounts.json file, and before each automated script execution, I restore it from the backup. This workaround has resolved the issue for me.

I haven't looked into the source code, but I suspect that the program might be erroneously storing or clearing the account credentials in some way, which leads to the periodic login expiration. The reason it expires every three days could be that the program attempts to refresh the token every three days, but something goes wrong during that process—possibly related to the mechanism that clears the .accounts.json file.

tiehu avatar Jul 28 '25 10:07 tiehu

Ok, removal of other accounts is caused by this line https://github.com/headlesshq/headlessmc/blob/85b399865477a41fc5744a65a00c8d451c6a4906/headlessmc-launcher/src/main/java/io/github/headlesshq/headlessmc/launcher/auth/AccountManager.java#L59-L60 Which removes the account if it fails to refresh it.

I'll first add an option to not remove it on failure, and to just launch the game if the refresh fails. However, this won't solve the root problem. How often are you relaunching your game? Have you tried the hmc-specifics? They refresh your account in game.

okafke avatar Nov 16 '25 15:11 okafke

#356 will not close this issue, the account refresh failure every 3 days still needs to be investigated.

okafke avatar Nov 16 '25 15:11 okafke

You can test this with the artifacts from this workflow: https://github.com/headlesshq/headlessmc/actions/runs/19407782732

okafke avatar Nov 16 '25 20:11 okafke