là je crois tenir quelque chose j’ai regardé sur spigotMC (ce post), et j’ai trouvé ce code-là :
| private final static String authserver = "https://authserver.mojang.com"; |
| |
| public static String authenticate(String username, String password) throws Exception { |
| |
| String genClientToken = UUID.randomUUID().toString(); |
| |
| |
| String payload = "{\"agent\": {\"name\": \"Minecraft\",\"version\": 1},\"username\": \"" + username |
| + "\",\"password\": \"" + password + "\",\"clientToken\": \"" + genClientToken + "\"}"; |
| |
| String output = postReadURL(payload, new URL(authserver + "/authenticate")); |
| |
| |
| String authBeg = "{\"accessToken\":\""; |
| String authEnd = "\",\"clientToken\":\""; |
| String clientEnd = "\",\"selectedProfile\""; |
| |
| |
| String authtoken = getStringBetween(output, authBeg, authEnd); |
| return authtoken; |
| } |
| |
| private static String postReadURL(String payload, URL url) throws Exception { |
| HttpsURLConnection con = (HttpsURLConnection) (url.openConnection()); |
| |
| con.setReadTimeout(15000); |
| con.setConnectTimeout(15000); |
| con.setRequestMethod("POST"); |
| con.setRequestProperty("Content-Type", "application/json"); |
| con.setDoInput(true); |
| con.setDoOutput(true); |
| OutputStream out = con.getOutputStream(); |
| out.write(payload.getBytes("UTF-8")); |
| out.close(); |
| BufferedReader in = new BufferedReader(new tStreamReader(con.getInputStream())); |
| String output = ""; |
| String line = null; |
| while ((line = in.readLine()) != null) { |
| output += line; |
| in.close(); |
| } |
| return output; |
| } |
| |
| private static String getStringBetween(String base, String begin, String end) { |
| Pattern patbeg = Pattern.compile(Pattern.quote(begin)); |
| Pattern patend = Pattern.compile(Pattern.quote(end)); |
| |
| int resbeg = 0; |
| int resend = base.length() - 1; |
| |
| Matcher matbeg = patbeg.matcher(base); |
| |
| if (matbeg.find()) resbeg = matbeg.end(); |
| |
| Matcher matend = patend.matcher(base); |
| |
| if (matend.find()) |
| resend = matend.start(); |
| |
| return base.substring(resbeg, resend); |
| } |
il doit y avoir un moyen de le retranscrire en bash je pense, ou de créer un script (en python par exemple)
EDIT : ou même de l’ajouter à un code, car on peut créer un script bash avec java (il faut que je revoie ça), et ça devrait marcher avec des variables (j’espère)