Search in sources :

Example 1 with SessionException

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

the class MicrosoftAuthenticator method refreshSession.

public void refreshSession(MicrosoftUser user) throws AuthenticationException {
    // Refresh the OAuth token (should last 90 inactive days, indefinitely otherwise).
    // If it fails then we bail.
    Credential credential = loadExistingCredential(user.getUsername());
    if (credential == null) {
        throw new SessionException("Microsoft login expired or is invalid");
    }
    try {
        if (!credential.refreshToken()) {
            // Refresh request failed
            throw new SessionException("Microsoft login expired or is invalid");
        }
    } catch (IOException e) {
        // A 4xx was received
        throw new SessionException("Microsoft login expired or is invalid", e);
    }
    // Store the updated credential in the filesystem
    updateCredentialStore(user.getUsername(), credential);
    // Request the Xbox token
    XboxResponse xboxResponse = authenticateXbox(credential);
    // Request the XSTS token
    XboxResponse xstsResponse = authenticateXSTS(xboxResponse.token);
    // Request the Mojang token and store it (in memory)
    XboxMinecraftResponse xboxMinecraftResponse = authenticateMinecraftXbox(xstsResponse);
    user.updateAuthToken(xboxMinecraftResponse);
}
Also used : SessionException(net.technicpack.launchercore.exception.SessionException) IOException(java.io.IOException)

Example 2 with SessionException

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

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