Search in sources :

Example 1 with YggdrasilUserAuthentication

use of com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication in project MinecraftForge by MinecraftForge.

the class Yggdrasil method login.

public static void login(Map<String, String> args) {
    if (!args.containsKey("--username") || !args.containsKey("--password"))
        return;
    YggdrasilUserAuthentication auth = (YggdrasilUserAuthentication) new YggdrasilAuthenticationService(Proxy.NO_PROXY, "1").createUserAuthentication(Agent.MINECRAFT);
    auth.setUsername(args.get("--username"));
    auth.setPassword(args.remove("--password"));
    try {
        auth.logIn();
    } catch (AuthenticationException e) {
        LogManager.getLogger("FMLTWEAK").error("-- Login failed!  " + e.getMessage());
        Throwables.propagate(e);
        // don't set other variables
        return;
    }
    args.put("--username", auth.getSelectedProfile().getName());
    args.put("--uuid", auth.getSelectedProfile().getId().toString().replace("-", ""));
    args.put("--accessToken", auth.getAuthenticatedToken());
    args.put("--userProperties", auth.getUserProperties().toString());
}
Also used : AuthenticationException(com.mojang.authlib.exceptions.AuthenticationException) YggdrasilAuthenticationService(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService) YggdrasilUserAuthentication(com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication)

Example 2 with YggdrasilUserAuthentication

use of com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication in project Wurst-MC-1.12 by Wurst-Imperium.

the class LoginManager method login.

public static String login(String email, String password) {
    YggdrasilUserAuthentication auth = (YggdrasilUserAuthentication) new YggdrasilAuthenticationService(Proxy.NO_PROXY, "").createUserAuthentication(Agent.MINECRAFT);
    auth.setUsername(email);
    auth.setPassword(password);
    try {
        auth.logIn();
        Minecraft.getMinecraft().session = new Session(auth.getSelectedProfile().getName(), auth.getSelectedProfile().getId().toString(), auth.getAuthenticatedToken(), "mojang");
        return "";
    } catch (AuthenticationUnavailableException e) {
        return "�4�lCannot contact authentication server!";
    } catch (AuthenticationException e) {
        e.printStackTrace();
        if (e.getMessage().contains("Invalid username or password.") || e.getMessage().toLowerCase().contains("account migrated"))
            return "�4�lWrong password!";
        else
            return "�4�lCannot contact authentication server!";
    } catch (NullPointerException e) {
        return "�4�lWrong password!";
    }
}
Also used : AuthenticationUnavailableException(com.mojang.authlib.exceptions.AuthenticationUnavailableException) AuthenticationException(com.mojang.authlib.exceptions.AuthenticationException) YggdrasilAuthenticationService(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService) YggdrasilUserAuthentication(com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication) Session(net.minecraft.util.Session)

Aggregations

AuthenticationException (com.mojang.authlib.exceptions.AuthenticationException)2 YggdrasilAuthenticationService (com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService)2 YggdrasilUserAuthentication (com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication)2 AuthenticationUnavailableException (com.mojang.authlib.exceptions.AuthenticationUnavailableException)1 Session (net.minecraft.util.Session)1