Advertisement
FunGamesLeaks

FN_Api

Jul 8th, 2019
1,975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.03 KB | None | 0 0
  1. //FortniteApi/FortniteAPI.java
  2. package FortniteApi;
  3.  
  4. import java.io.IOException;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Date;
  9.  
  10. import org.json.simple.JSONObject;
  11. import org.json.simple.parser.JSONParser;
  12. import org.json.simple.parser.ParseException;
  13.  
  14. import okhttp3.OkHttpClient;
  15. import okhttp3.Request;
  16. import okhttp3.Request.Builder;
  17. import okhttp3.RequestBody;
  18. import okhttp3.Response;
  19.  
  20. public class FortniteAPI {
  21.     private static final String clientLauncherToken = "MzQ0NmNkNzI2OTRjNGE0NDg1ZDgxYjc3YWRiYjIxNDE6OTIwOWQ0YTVlMjVhNDU3ZmI5YjA3NDg5ZDMxM2I0MWE";
  22.     private static final String clientExchangeToken = "ZWM2ODRiOGM2ODdmNDc5ZmFkZWEzY2IyYWQ4M2Y1YzY6ZTFmMzFjMjExZjI4NDEzMTg2MjYyZDM3YTEzZmM4NGQ";
  23.     public String accountID = null;
  24.     private String accessToken;
  25.     private String accessCode;
  26.     private String exchangeToken;
  27.  
  28.     private String email;
  29.     private String password;
  30.     private Date tokenExpire;
  31.     private boolean loggedIn = false;
  32.    
  33.     public OkHttpClient httpClient = new OkHttpClient();
  34.  
  35.     public boolean loggedIn() {
  36.         return loggedIn;
  37.     }
  38.  
  39.     public static final String timeStampFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
  40.  
  41.     public boolean login(String username, String password)
  42.             throws IOException, ParseException, java.text.ParseException {
  43.         this.email = username;
  44.         this.password = password;
  45.         getAccessToken(username, password);
  46.         getAccessCode();
  47.         getExchangeToken();
  48.         if (accessToken != null && accessCode != null && exchangeToken != null) {
  49.             this.loggedIn = true;
  50.             return true;
  51.         } else {
  52.             return false;
  53.         }
  54.  
  55.     }
  56.  
  57.     public void refresh() throws IOException, ParseException, java.text.ParseException {
  58.         if (isTokenExpired()) {
  59.             getAccessToken(email, password);
  60.             getAccessCode();
  61.             getExchangeToken();
  62.             System.out.println("[Fortnite Api] Refreshed OAuth Token");
  63.         }
  64.     }
  65.  
  66.     public boolean isTokenExpired() {
  67.         long currentTime = System.currentTimeMillis();
  68.         // Refresh the token 60 seconds before it expires to be safe
  69.         if ((currentTime - 60000) >= this.tokenExpire.getTime()) {
  70.             return true;
  71.         } else {
  72.             return false;
  73.         }
  74.     }
  75.  
  76.     public String getEndpoint(String url) throws IOException {
  77.         try {
  78.             refresh();
  79.         } catch (java.text.ParseException e) {
  80.             // TODO Auto-generated catch block
  81.             e.printStackTrace();
  82.         } catch (ParseException e) {
  83.             // TODO Auto-generated catch block
  84.             e.printStackTrace();
  85.         }
  86.  
  87.         Builder b = new Builder();
  88.         b.url(url);
  89.         b.addHeader("X-EpicGames-Language", "en");
  90.         b.addHeader("Authorization", "bearer " + exchangeToken);
  91.         Request r = b.build();
  92.         Response response = httpClient.newCall(r).execute();
  93.         String res = response.body().string();
  94.         response.close();
  95.         return res;
  96.  
  97.     }
  98.  
  99.     public String getEndpointPOST(String url, String encoding, String postArgs) throws IOException {
  100.         try {
  101.             refresh();
  102.         } catch (java.text.ParseException e) {
  103.             // TODO Auto-generated catch block
  104.             e.printStackTrace();
  105.         } catch (ParseException e) {
  106.             // TODO Auto-generated catch block
  107.             e.printStackTrace();
  108.         }
  109.  
  110.         Builder b = new Builder();
  111.         b.url(url);
  112.         b.addHeader("X-EpicGames-Language", "en");
  113.         b.addHeader("Authorization", "bearer " + exchangeToken);
  114.         b.method("POST", RequestBody.create(okhttp3.MediaType.parse(encoding), postArgs));
  115.         Request r = b.build();
  116.         Response response = httpClient.newCall(r).execute();
  117.         String res = response.body().string();
  118.         response.close();
  119.         return res;
  120.  
  121.     }
  122.  
  123.     public String getLocker() throws IOException, ParseException, java.text.ParseException {
  124.         String requestURL = "https://fortnite-public-service-prod11.ol.epicgames.com/fortnite/api/game/v2/profile/"
  125.                 + accountID + "/client/QueryProfile?profileId=athena&rvn=-1";
  126.         return this.getEndpointPOST(requestURL, "application/json", "{}");
  127.     }
  128.  
  129.     public String lookupAccountName(String name) throws ParseException, IOException, java.text.ParseException {
  130.         String res = this.getEndpoint(
  131.                 "https://persona-public-service-prod06.ol.epicgames.com/persona/api/public/account/lookup?q=" + name);
  132.         JSONParser jsonParser = new JSONParser();
  133.         Object data = jsonParser.parse(res);
  134.         if (data instanceof JSONObject) {
  135.             JSONObject json = (JSONObject) data;
  136.             String requestedAccountID = (String) json.get("id");
  137.             return requestedAccountID;
  138.         } else {
  139.             throw new ParseException(0);
  140.         }
  141.     }
  142.  
  143.     private String getAccessToken(String username, String password)
  144.             throws IOException, ParseException, java.text.ParseException {
  145.  
  146.  
  147.         Builder b = new Builder();
  148.         b.url(new URL(Endpoints.clientLauncherTokenURL));
  149.         b.method("POST", RequestBody.create(okhttp3.MediaType.parse("application/x-www-form-urlencoded"),
  150.                 "grant_type=password&username=" + username + "&password=" + password));
  151.         b.addHeader("grant_type", "password");
  152.         b.addHeader("username", username);
  153.         b.addHeader("password", password);
  154.         b.addHeader("includePerms", "true");
  155.         b.addHeader("Authorization", "basic " + clientLauncherToken);
  156.         b.addHeader("Content-Type", "application/x-www-form-urlencoded");
  157.         b.addHeader("Content-Length", "0");
  158.  
  159.         Request r = b.build();
  160.         Response response = httpClient.newCall(r).execute();
  161.         JSONParser jsonParser = new JSONParser();
  162.         Object data = jsonParser.parse(response.body().string());
  163.         if (data instanceof JSONObject) {
  164.             JSONObject jsonData = (JSONObject) data;
  165.             String token = (String) jsonData.get("access_token");
  166.             this.accessToken = token;
  167.             return token;
  168.         } else {
  169.             throw new ParseException(0);
  170.         }
  171.     }
  172.  
  173.     private String getAccessCode() throws IOException, ParseException {
  174.         Builder b = new Builder();
  175.         b.url(new URL(Endpoints.clientLauncherAccessCode));
  176.         b.addHeader("Authorization", "bearer " + accessToken);
  177.         Request r = b.build();
  178.         Response response = httpClient.newCall(r).execute();
  179.         JSONParser jsonParser = new JSONParser();
  180.         Object data = jsonParser.parse(response.body().string());
  181.         if (data instanceof JSONObject) {
  182.             JSONObject jsonData = (JSONObject) data;
  183.             String accessCode = (String) jsonData.get("code");
  184.             this.accessCode = accessCode;
  185.             return accessCode;
  186.         } else {
  187.             throw new ParseException(0);
  188.         }
  189.  
  190.     }
  191.  
  192.     private String getExchangeToken() throws IOException, ParseException {
  193.         Builder b = new Builder();
  194.         b.url(new URL(Endpoints.clientExchangeToken));
  195.         b.addHeader("Authorization", "basic " + clientExchangeToken);
  196.         b.addHeader("Content-Type", "application/x-www-form-urlencoded");
  197.         b.addHeader("grant_type", "exchange_code");
  198.         b.addHeader("exchange_code", this.accessCode);
  199.         b.addHeader("includePerms", "true");
  200.         b.addHeader("token_type", "eg1");
  201.         b.method("POST", RequestBody.create(okhttp3.MediaType.parse("application/x-www-form-urlencoded"),
  202.                 "grant_type=exchange_code&exchange_code=" + this.accessCode));
  203.         Request r = b.build();
  204.         Response response = httpClient.newCall(r).execute();
  205.         JSONParser jsonParser = new JSONParser();
  206.         Object data = jsonParser.parse(response.body().string());
  207.         if (data instanceof JSONObject) {
  208.             JSONObject jsonData = (JSONObject) data;
  209.             String exToken = (String) jsonData.get("access_token");
  210.             this.accountID = (String) jsonData.get("account_id");
  211.             String expiresAt = (String) jsonData.get("expires_at");
  212.             SimpleDateFormat dateFormat = new SimpleDateFormat(this.timeStampFormat);
  213.             try {
  214.                 this.tokenExpire = dateFormat.parse(expiresAt);
  215.             } catch (java.text.ParseException e) {
  216.                 // TODO Auto-generated catch block
  217.                 e.printStackTrace();
  218.             }
  219.             this.exchangeToken = exToken;
  220.             return exToken;
  221.         } else {
  222.             throw new ParseException(0);
  223.         }
  224.  
  225.     }
  226. }
  227.  
  228. //FortniteApi/Endpoints.java
  229. package FortniteApi;
  230.  
  231. public class Endpoints {
  232.     //Auth
  233.     public static final String clientLauncherTokenURL = "https://account-public-service-prod03.ol.epicgames.com/account/api/oauth/token";
  234.     public static final String clientLauncherAccessCode = "https://account-public-service-prod03.ol.epicgames.com/account/api/oauth/exchange";
  235.     public static final String clientExchangeToken = "https://account-public-service-prod03.ol.epicgames.com/account/api/oauth/token";
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement