Skip to content

API Guide: Login

Tomas Jasek edited this page Aug 28, 2017 · 21 revisions

Summary

This API Guide will conclude how to login using mclauncher-api. To start with any login, you need to get a profile. Either load it or get it from GUI text fields, it's up to you. On this page, I assume you've loaded a profile to profile variable. Everything you learn on this page is obtaining the Session object.

Deciding on which login system you should use

Minecraft contains 2 login systems. First one is the legacy login and the other one is called yggdrassil. Yggdrassil is newer, so I recommend you use it.

Logging in using Yggdrassil

Yggdrassil supports 2 types of logging in:

  1. Using password
  2. Using session ID

Session ID usage is however limited, since session IDs expire through time(idk how long is one session), which is why password login always works and session ID login doesn't. However, for both logins, you need to do the same stuff.

YDLoginService loginService = new YDLoginService();
loginService.load(Platform.getCurrentPlatform().getWorkingDirectory());
ISession session = loginService.login(profile);

You should try to perform session ID login first, because it's faster and if it fails, you can do password login. The type of login depends on type of your profile variable. For LegacyProfile, YDLoginSystem will always do password login and for YDProfile, YDLoginSystem will always do session ID login. If you want to do password based login say from data from a text field, you need to create a LegacyProfile with that username and password and then pass the profile to YDLoginService.login method.

Also, if you loaded the profile from a file, you will want to overwrite your file with the profile you passed into the login method. That's because your new session ID will be used for next login.

PLEASE NOTE: If you're testing login and actually type your password in .java source file, please make sure to save the source file as UTF-8, otherwise you might get a Bad Request error from Mojang server. I recommend loading your password from a UTF-8 plain text file in case you really want to test like this...

Logging in legacy style

Legacy login with the API is extremely simple. All you need to do is this:

LegacyLoginService loginService = new LegacyLoginService();
ISession session = loginService.login(profile);

Working with the API




  • Login - Logging in with password or session ID



Clone this wiki locally