CmlLib / CmlLib.Core.Auth.Microsoft

Minecraft Login with Microsoft Xbox account
MIT License
22 stars 4 forks source link

Failed to log in: Invalid Session (Try restarting your game and the launcher) #20

Closed voidZiAD closed 7 months ago

voidZiAD commented 7 months ago

This issue stems from I'm guessing:

The session of the user eventually expires after logging in? if so, why? and how can I make sure that he doesn't have to log in every 24h or so?

This account is a Microsoft Account that I've bought minecraft java with, and I'm trying to join pvplegacy & hypixel but it's not working. The last time I logged in was yesterday. I'm currently still logged in, but when I launch the game and join β€” it doesn't let me connect and actually join the server.

I want to know how I can re-create a session for the user whether he has a Microsoft account or a Mojang account. It's simply not sustainable for me to ask the user to re-log in every day. It's annoying.

image

voidZiAD commented 7 months ago

I just attempted to do the following:

session = new MSession(Properties.Settings.Default.SessionInfo.Username, Properties.Settings.Default.SessionInfo.AccessToken, Properties.Settings.Default.SessionInfo.UUID);
Properties.Settings.Default.SessionInfo = session;
Properties.Settings.Default.Save();
var result = session.CheckIsValid;

But that didn't work, so I'm not sure what else will work

voidZiAD commented 7 months ago

okay, I fixed it. All I had to do was:

 var loginHandler = JELoginHandlerBuilder.BuildDefault();
 session = await loginHandler.Authenticate();
 Properties.Settings.Default.SessionInfo = session;  // Optional, I just need it in my case
 Properties.Settings.Default.Save(); // Optional, I just need it in my case

and for Mojang Legacy Accounts:

response = login.Authenticate("email", "password");

Refer to the docs if you had this issue and are reading this:

https://alphabs.gitbook.io/cmllib/cmllib.core/login-and-sessions/mojang-account https://alphabs.gitbook.io/cmllib/auth.microsoft/cmllib.core.auth.microsoft

it'd be cool to pin this as well looks like I'm just making issues to solve them myself πŸ˜‚

M1XT3NZ commented 7 months ago

Actually mojang accounts don’t really exist anymore πŸ€·β€β™‚οΈ

On Mon 29. Jan 2024 at 14:12, ZiAD @.***> wrote:

okay, I fixed it. All I had to do was:

var loginHandler = JELoginHandlerBuilder.BuildDefault(); session = await loginHandler.Authenticate(); Properties.Settings.Default.SessionInfo = session; // Optional, I just need it in my case Properties.Settings.Default.Save(); // Optional, I just need it in my case

and for Mojang Legacy Accounts:

response = login.Authenticate("email", "password");

Refer to the docs if you had this issue and are reading this:

https://alphabs.gitbook.io/cmllib/cmllib.core/login-and-sessions/mojang-account https://alphabs.gitbook.io/cmllib/auth.microsoft/cmllib.core.auth.microsoft

it'd be cool to pin this as well looks like I'm just making issues to solve them myself πŸ˜‚

β€” Reply to this email directly, view it on GitHub https://github.com/CmlLib/CmlLib.Core.Auth.Microsoft/issues/20#issuecomment-1914669183, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG75EZRDX2J3Z2B5TGINUE3YQ6N2RAVCNFSM6AAAAABCPMGVI6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJUGY3DSMJYGM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

voidZiAD commented 7 months ago

Oh. Well I guess the microsoft one still works at least

AlphaBs commented 7 months ago

you don't need to implement saving a session. the library already do this. all code you need is:

var loginHandler = JELoginHandlerBuilder.BuildDefault();
session = await loginHandler.Authenticate();

Authenticate() method loads saved accounts and try to authenticate with the most recently used account. and also refresh the tokens if the session is expired.

List saved accounts: https://alphabs.gitbook.io/cmllib/auth.microsoft/cmllib.core.auth.microsoft/jeloginhandler#list-accounts

voidZiAD commented 7 months ago

Oh. Bet! Thank you, I'll keep that in mind. Can you also please check my issue on CmlLib.Core?