I have it mostly set up already I'm just having problems connecting to it. There's a file called InvisionPowerAPI in my source
Code:
package io.ruin.api.utils;
import com.google.api.client.http.*;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonObjectParser;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.common.collect.Maps;
import com.google.common.reflect.TypeToken;
import io.ruin.api.protocol.web.login.LoginResponse;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
public class InvisionPowerAPI {
public static final String API_TOKEN = "0b3cab37991a0c7e21e45320749e9f51";
private static final String API_URL = "https://runesque.live/forum/api/index.php?";
private static final String LOGIN_AUTH_URL = "https://runesque.live/forum/verifyuser";
private static final String LOGIN_AUTH_TOKEN = "429dcff5ad9cf52cc59466cbeb1c75abf9df170f68e2454e";
private static final Type RESPONSE_TYPE = new TypeToken<Map<String, Object>>() {}.getType();
static HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
static JsonFactory JSON_FACTORY = new JacksonFactory();
public static Map<String, Object> getRequest(String apiPath, Map<String, String> params) throws IOException {
HttpRequestFactory requestFactory = getFactory();
String paramUrl = (apiPath.endsWith("/") ? "&" : "/&") + params.entrySet().stream().map((entry) -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.joining("&"));
GenericUrl url = new GenericUrl(API_URL + apiPath + paramUrl);
//log.info("Attempting to send API call to {}", url.build());
HttpRequest request = requestFactory.buildGetRequest(url);
request.getHeaders().setBasicAuthentication(API_TOKEN, "");
return (Map<String, Object>) request
.execute()
.parseAs(RESPONSE_TYPE);
}
public static Map<String, Object> postRequest(String apiPath, Map<String, Object> postVariables) throws IOException {
HttpRequestFactory requestFactory = getFactory();
GenericUrl url = new GenericUrl(API_URL + apiPath);
HttpRequest request = requestFactory.buildPostRequest(url, new UrlEncodedContent(postVariables));
request.getHeaders().setContentType("application/x-www-form-urlencoded");
request.getHeaders().setBasicAuthentication(API_TOKEN, "");
return (Map<String, Object>) request
.execute()
.parseAs(RESPONSE_TYPE);
}
public static Map<String, Object> postAuth(Map<String, Object> postVariables) throws IOException {
HttpRequestFactory requestFactory = getFactory();
postVariables.put("token", LOGIN_AUTH_TOKEN);
GenericUrl url = new GenericUrl(LOGIN_AUTH_URL);
HttpRequest request = requestFactory.buildPostRequest(url, new UrlEncodedContent(postVariables));
//request.getHeaders().setContentType("application/json");
request.getHeaders().setContentType("application/x-www-form-urlencoded");
//log.info("Attempting to send Login AUTH call to {}", url.build());
//log.info("Post request data is {}", ((UrlEncodedContent)request.getContent()).getData());
return (Map<String, Object>) request
.execute()
.parseAs(RESPONSE_TYPE);
}
public static LoginResponse attemptLogin(String email, String password) throws IOException {
HttpRequestFactory requestFactory = getFactory();
Map<String, Object> postVariables = Maps.newConcurrentMap();
postVariables.put("token", LOGIN_AUTH_TOKEN);
postVariables.put("email", email);
postVariables.put("password", password);
GenericUrl url = new GenericUrl(LOGIN_AUTH_URL);
HttpRequest request = requestFactory.buildPostRequest(url, new UrlEncodedContent(postVariables));
//request.getHeaders().setContentType("application/json");
request.getHeaders().setContentType("application/x-www-form-urlencoded");
//log.info("Attempting to send Login AUTH call to {}", url.build());
//log.info("Post request data is {}", ((UrlEncodedContent)request.getContent()).getData());
return new LoginResponse((Map<String, Object>) request
.execute()
.parseAs(RESPONSE_TYPE));
}
private static HttpRequestFactory getFactory(){
return HTTP_TRANSPORT.createRequestFactory(
(HttpRequest request) -> {
request.setParser(new JsonObjectParser(JSON_FACTORY));
});
}
}
I understand how to get this working for the most part the hardest part im struggling with is the AUTH_LINK and AUTH_TOKEN the api link and token are in the admin panel in the ips forum suite.. however in that same acp ive tried making an oauth client because i assumed thats how this works but every time i try to log in i get this error and cant
Code:
[central-server #1] INFO io.ruin.central.network.WorldDecoder - World decoder opcode 1
[ForkJoinPool.commonPool-worker-1] INFO io.ruin.central.model.world.WorldLogin - Login attempt! 1222564717
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: (GZIPInputStream); line: 1, column: 2]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1804)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:693)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:591)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2630)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:832)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:729)
at com.google.api.client.json.jackson2.JacksonParser.nextToken(JacksonParser.java:52)
at com.google.api.client.json.JsonParser.startParsing(JsonParser.java:215)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:360)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:337)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:79)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:450)
at io.ruin.api.utils.InvisionPowerAPI.attemptLogin(InvisionPowerAPI.java:92)
at io.ruin.central.model.world.WorldLogin.lambda$new$0(WorldLogin.java:35)
at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1640)
at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1632)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175)
[central-server #1] INFO io.ruin.central.network.WorldDecoder - World decoder opcode 2
[central-server #1] INFO io.ruin.central.network.WorldDecoder - Attempting to log out player with session id 1222564717
The error is the confusing part as i dont understand whats going on with the '<' or whatever error in the JSON parsing.. am i giving it the wrong auth link or token or something??? is my oauth client not configured right??