com.github.steveice10.mc.auth.exception.request.InvalidCredentialsException Java Examples
The following examples show how to use
com.github.steveice10.mc.auth.exception.request.InvalidCredentialsException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuthenticationService.java From Visage with MIT License | 6 votes |
/** * Logs the service in. * * @throws RequestException If an error occurs while making the request. */ public void login() throws RequestException { if(this.username == null || this.username.equals("")) { throw new InvalidCredentialsException("Invalid username."); } else { if(this.accessToken != null && !this.accessToken.equals("")) { this.loginWithToken(); } else { if(this.password == null || this.password.equals("")) { throw new InvalidCredentialsException("Invalid password."); } this.loginWithPassword(); } } }
Example #2
Source File: HTTP.java From MCAuthLib with MIT License | 6 votes |
private static void checkForError(JsonElement response) throws RequestException { if(response.isJsonObject()) { JsonObject object = response.getAsJsonObject(); if(object.has("error")) { String error = object.get("error").getAsString(); String cause = object.has("cause") ? object.get("cause").getAsString() : ""; String errorMessage = object.has("errorMessage") ? object.get("errorMessage").getAsString() : ""; if(!error.equals("")) { if(error.equals("ForbiddenOperationException")) { if(cause != null && cause.equals("UserMigratedException")) { throw new UserMigratedException(errorMessage); } else { throw new InvalidCredentialsException(errorMessage); } } else { throw new RequestException(errorMessage); } } } } }
Example #3
Source File: AuthenticationService.java From Visage with MIT License | 5 votes |
private void loginWithPassword() throws RequestException { if(this.username == null || this.username.isEmpty()) { throw new InvalidCredentialsException("Invalid username."); } else if(this.password == null || this.password.isEmpty()) { throw new InvalidCredentialsException("Invalid password."); } else { AuthenticationRequest request = new AuthenticationRequest(this.username, this.password, this.clientToken); AuthenticationResponse response = HTTP.makeRequest(this.proxy, AUTHENTICATE_URL, request, AuthenticationResponse.class); if(response.clientToken.equals(this.clientToken)) { if(response.user != null && response.user.id != null) { this.id = response.user.id; } else { this.id = this.username; } this.loggedIn = true; this.accessToken = response.accessToken; this.profiles = response.availableProfiles != null ? Arrays.asList(response.availableProfiles) : Collections.<GameProfile>emptyList(); this.selectedProfile = response.selectedProfile; this.properties.clear(); if(response.user != null && response.user.properties != null) { this.properties.addAll(response.user.properties); } } else { throw new RequestException("Server requested we change our client token. Don't know how to handle this!"); } } }
Example #4
Source File: AuthenticationService.java From Visage with MIT License | 5 votes |
private void loginWithToken() throws RequestException { if(this.id == null || this.id.isEmpty()) { if(this.username == null || this.username.isEmpty()) { throw new InvalidCredentialsException("Invalid uuid and username."); } this.id = this.username; } if(this.accessToken == null || this.accessToken.equals("")) { throw new InvalidCredentialsException("Invalid access token."); } else { RefreshRequest request = new RefreshRequest(this.clientToken, this.accessToken, null); RefreshResponse response = HTTP.makeRequest(this.proxy, REFRESH_URL, request, RefreshResponse.class); if(response.clientToken.equals(this.clientToken)) { if(response.user != null && response.user.id != null) { this.id = response.user.id; } else { this.id = this.username; } this.loggedIn = true; this.accessToken = response.accessToken; this.profiles = response.availableProfiles != null ? Arrays.asList(response.availableProfiles) : Collections.<GameProfile>emptyList(); this.selectedProfile = response.selectedProfile; this.properties.clear(); if(response.user != null && response.user.properties != null) { this.properties.addAll(response.user.properties); } } else { throw new RequestException("Server requested we change our client token. Don't know how to handle this!"); } } }
Example #5
Source File: HTTP.java From Visage with MIT License | 5 votes |
/** * Makes an HTTP request. * * @param proxy Proxy to use when making the request. * @param url URL to make the request to. * @param input Input to provide in the request. * @param clazz Class to provide the response as. * @param <T> Type to provide the response as. * @return The response of the request. * @throws RequestException If an error occurs while making the request. */ public static <T> T makeRequest(Proxy proxy, String url, Object input, Class<T> clazz) throws RequestException { JsonElement response = null; try { String jsonString = input == null ? performGetRequest(proxy, url) : performPostRequest(proxy, url, GSON.toJson(input), "application/json"); response = GSON.fromJson(jsonString, JsonElement.class); } catch(Exception e) { throw new ServiceUnavailableException("Could not make request to '" + url + "'.", e); } if(response != null) { if(response.isJsonObject()) { JsonObject object = response.getAsJsonObject(); if(object.has("error")) { String error = object.get("error").getAsString(); String cause = object.has("cause") ? object.get("cause").getAsString() : ""; String errorMessage = object.has("errorMessage") ? object.get("errorMessage").getAsString() : ""; if(!error.equals("")) { if(error.equals("ForbiddenOperationException")) { if(cause != null && cause.equals("UserMigratedException")) { throw new UserMigratedException(errorMessage); } else { throw new InvalidCredentialsException(errorMessage); } } else { throw new RequestException(errorMessage); } } } } if(clazz != null) { return GSON.fromJson(response, clazz); } } return null; }