Search in sources :

Example 1 with AuthRequest

use of net.technicpack.minecraftcore.mojang.auth.request.AuthRequest in project LauncherV3 by TechnicPack.

the class MojangAuthenticator method loginNewUser.

public MojangUser loginNewUser(String username, String password) throws AuthenticationException {
    AuthRequest request = new AuthRequest(username, password, clientToken);
    String data = MojangUtils.getGson().toJson(request);
    AuthResponse response;
    try {
        String returned = postJson(AUTH_SERVER + "authenticate", data);
        response = MojangUtils.getGson().fromJson(returned, AuthResponse.class);
        if (response == null) {
            throw new ResponseException("Auth Error", "Invalid credentials. Invalid username or password.");
        }
        if (response.hasError()) {
            throw new ResponseException(response.getError(), response.getErrorMessage());
        }
    } catch (ResponseException e) {
        throw e;
    } catch (IOException e) {
        throw new AuthenticationException("An error was raised while attempting to communicate with " + AUTH_SERVER + ".", e);
    }
    return new MojangUser(username, response);
}
Also used : AuthRequest(net.technicpack.minecraftcore.mojang.auth.request.AuthRequest) ResponseException(net.technicpack.launchercore.exception.ResponseException) AuthenticationException(net.technicpack.launchercore.exception.AuthenticationException) IOException(java.io.IOException) AuthResponse(net.technicpack.minecraftcore.mojang.auth.response.AuthResponse)

Aggregations

IOException (java.io.IOException)1 AuthenticationException (net.technicpack.launchercore.exception.AuthenticationException)1 ResponseException (net.technicpack.launchercore.exception.ResponseException)1 AuthRequest (net.technicpack.minecraftcore.mojang.auth.request.AuthRequest)1 AuthResponse (net.technicpack.minecraftcore.mojang.auth.response.AuthResponse)1