Thread: Invision Power API - How to get my server to login through my forums

Results 1 to 4 of 4
  1. #1 Invision Power API - How to get my server to login through my forums 
    Registered Member
    Join Date
    Aug 2020
    Posts
    2
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    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??
    Reply With Quote  
     

  2. #2  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Asking for help on a leaked server?
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Aug 2020
    Posts
    2
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    No just a complicated one
    Reply With Quote  
     

  4. #4  
    ¦¦¦ RuneTimes ¦¦¦

    RainDropzZ's Avatar
    Join Date
    Oct 2010
    Posts
    389
    Thanks given
    31
    Thanks received
    108
    Rep Power
    556
    You could just do it with an MySQL querry in the users database of IPB
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. how to get this client to connect to my server
    By OodlesOfNoodles in forum Help
    Replies: 1
    Last Post: 11-11-2011, 08:25 PM
  2. Replies: 3
    Last Post: 04-27-2010, 02:47 AM
  3. how do i add my server to vps.
    By R4nger 0wnz in forum Help
    Replies: 3
    Last Post: 12-27-2009, 09:43 PM
  4. How To Get @rune-server.org?
    By Delifed in forum Forum Related Help
    Replies: 7
    Last Post: 11-27-2009, 10:32 PM
  5. how do i get my server to run
    By bosley in forum Tutorials
    Replies: 10
    Last Post: 04-29-2008, 11:45 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •