Search in sources :

Example 1 with ResponseException

use of net.technicpack.launchercore.exception.ResponseException in project LauncherV3 by TechnicPack.

the class LoginFrame method newMojangLogin.

private void newMojangLogin(String name) {
    try {
        MojangUser newUser;
        newUser = userModel.getMojangAuthenticator().loginNewUser(name, new String(this.password.getPassword()));
        userModel.addUser(newUser);
        userModel.setCurrentUser(newUser);
        setCurrentUser(newUser);
    } catch (ResponseException e) {
        showMessageDialog(this, e.getMessage(), e.getError(), ERROR_MESSAGE);
    } catch (AuthenticationException e) {
        // TODO: What else is uncaught here?
        showMessageDialog(this, e.getMessage(), "Authentication error", ERROR_MESSAGE);
        e.printStackTrace();
    }
}
Also used : ResponseException(net.technicpack.launchercore.exception.ResponseException) AuthenticationException(net.technicpack.launchercore.exception.AuthenticationException) MojangUser(net.technicpack.minecraftcore.mojang.auth.MojangUser)

Example 2 with ResponseException

use of net.technicpack.launchercore.exception.ResponseException 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)

Example 3 with ResponseException

use of net.technicpack.launchercore.exception.ResponseException in project LauncherV3 by TechnicPack.

the class MojangAuthenticator method requestRefresh.

public AuthResponse requestRefresh(MojangUser mojangUser) throws AuthenticationException {
    RefreshRequest refreshRequest = new RefreshRequest(mojangUser.getAccessToken(), mojangUser.getClientToken());
    String data = MojangUtils.getGson().toJson(refreshRequest);
    AuthResponse response;
    try {
        String returned = postJson(AUTH_SERVER + "refresh", data);
        response = MojangUtils.getGson().fromJson(returned, AuthResponse.class);
        if (response == null) {
            throw new SessionException("Session Error. Try logging in again.");
        }
        if (response.hasError()) {
            throw new ResponseException(response.getError(), response.getErrorMessage());
        }
    } catch (IOException e) {
        throw new AuthenticationException("An error was raised while attempting to communicate with " + AUTH_SERVER + ".", e);
    }
    return response;
}
Also used : RefreshRequest(net.technicpack.minecraftcore.mojang.auth.request.RefreshRequest) ResponseException(net.technicpack.launchercore.exception.ResponseException) AuthenticationException(net.technicpack.launchercore.exception.AuthenticationException) SessionException(net.technicpack.launchercore.exception.SessionException) IOException(java.io.IOException) AuthResponse(net.technicpack.minecraftcore.mojang.auth.response.AuthResponse)

Aggregations

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