private static LoginResult MicrosoftLogin(string email, string password, out SessionToken session) { session = new SessionToken() { ClientID = Guid.NewGuid().ToString().Replace("-", "") }; var ms = new XboxLive(); var mc = new MinecraftWithXbox(); try { var msaResponse = ms.UserLogin(email, password, ms.PreAuth()); var xblResponse = ms.XblAuthenticate(msaResponse); var xsts = ms.XSTSAuthenticate(xblResponse); // Might throw even password correct string accessToken = mc.LoginWithXbox(xsts.UserHash, xsts.Token); bool hasGame = mc.UserHasGame(accessToken); if (hasGame) { var profile = mc.GetUserProfile(accessToken); session.PlayerName = profile.UserName; session.PlayerID = profile.UUID; session.ID = accessToken; return(LoginResult.Success); } else { return(LoginResult.NotPremium); } } catch (Exception e) { ConsoleIO.WriteLineFormatted("§cMicrosoft authenticate failed: " + e.Message); if (Settings.DebugMessages) { ConsoleIO.WriteLineFormatted("§c" + e.StackTrace); } return(LoginResult.WrongPassword); // Might not always be wrong password } }
/// <summary> /// Sign-in to Microsoft Account without using browser. Only works if 2FA is disabled. /// Might not work well in some rare cases. /// </summary> /// <param name="email"></param> /// <param name="password"></param> /// <param name="session"></param> /// <returns></returns> private static LoginResult MicrosoftMCCLogin(string email, string password, out SessionToken session) { var ms = new XboxLive(); try { var msaResponse = ms.UserLogin(email, password, ms.PreAuth()); return(MicrosoftLogin(msaResponse, out session)); } catch (Exception e) { session = new SessionToken() { ClientID = Guid.NewGuid().ToString().Replace("-", "") }; ConsoleIO.WriteLineFormatted("§cMicrosoft authenticate failed: " + e.Message); if (Settings.DebugMessages) { ConsoleIO.WriteLineFormatted("§c" + e.StackTrace); } return(LoginResult.WrongPassword); // Might not always be wrong password } }