'How to get a Minecraft session ID?

I'm trying to make a Minecraft client and I cant figure out how to get a session ID to start the game. I've done some googling and cant find anyway to get it bar from this answer to Launch Minecraft from command line - username and password as prefix that doesn't work.



Solution 1:[1]

Minecraft mc = Minecraft.getMinecraft();

mc.getSession().getToken();

Solution 2:[2]

You can manually crash your game by holding down F3 + C. In the crash log will be your session id.

Solution 3:[3]

I made a little script that returns the session id.

def GetSessionID(Username, Password):
    # Url = f'https://login.minecraft.net?user={Username}&password={Password}&version=13'
    Url = "https://authserver.mojang.com/authenticate"
    # LoginInfo = requests.post(Url)
    # LoginInfoList = LoginInfo.split(':')
    # SessionID = LoginInfoList[3]
    token = str(uuid.uuid4())
    requestData = GetAuthenticationBody(Username, Password, token)
    response = requests.post(url=Url, json=requestData)
    responseData = response.json()

    SessionID = responseData['accessToken']
    return SessionID

    def GetAuthenticationBody(username, password, token):
        body = {
            "agent":  {
                "name": "Minecraft",
                "version": 1
            },
            "username": username,
            "password": password,
            "clientToken": token,
            "requestUser": True
        }
        return body

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pppery
Solution 2 pppery
Solution 3 pppery