2

In the minecraft authentication page, users send an https post request with a specific format to get a response, which I believe I have used correctly. However, I am getting a Method Not Allowed error, meaning that the server received something other than a post request, which isn't true.

The server variable:

final String server = "https://authserver.mojang.com/authenticate";

Here is how my payload is sent:

Gson gson = new Gson();

CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(server);
StringEntity postingString = new StringEntity(gson.toJson(payload));
post.setEntity(postingString);
post.setHeader("content-type", "application/json");
HttpResponse response = (HttpResponse) httpClient.execute(post);

this.authResponse = response.toString();

This is the NEW full response message I an receiving:

HttpResponseProxy{HTTP/1.1 400 Bad Request [Content-Type: application/json, Content-Length: 655, Connection: keep-alive, Accept-Ranges: bytes, Date: Mon, 01 Jan 2018 15:28:36 GMT, Server: Restlet-Framework/2.3.10, Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept, X-Cache: Error from cloudfront, Via: 1.1 6046e14e05d9aeb3ea5b4dd85091e9a6.cloudfront.net (CloudFront), X-Amz-Cf-Id: 4wciQ7Mp6OExfWnU3C9frmifhqWQT5_vpQRvUbXPrDy-O-nJqPWtWQ==] ResponseEntityProxy{[Content-Type: application/json,Content-Length: 655,Chunked: false]}}

The contents of my request look like this:

{
"agent": {                              
    "name": "Minecraft",                
    "version": 1                        

},
"username": "my username",      

"password": "my password"
}

Clearer Error Response Message:

{"error":"JsonMappingException","errorMessage":"Can not construct instance of com.mojang.yggdrasil.auth.dataaccess.memcached.throttling.captcha.CaptchaCredentials: no String-argument constructor/factory method to deserialize from String value ('{\n    \"agent\": {                              \n        \"name\": \"Minecraft\",                \n        \"version\": 1                        \n                                            \n    },\n    \"username\": \"my username\",      \n                                            \n    \"password\": \"my password\"\n}')\n at [Source: HttpInputOverHTTP@5e25d803; line: 1, column: 1]"}
Gamer818
  • 102
  • 11
  • "_meaning that the server received something other than a post request_" No. It **did** receive a POST request, but this endpoint only accepts GET requests. – Ivar Jan 01 '18 at 15:10
  • @Ivar I don't quite get what you mean, how would I come about submitting my json content to the server then? – Gamer818 Jan 01 '18 at 15:14
  • The documentation indeed talks about using a POST request. A `405 Method Not Allowed` is required to return a "Allow" header with the allowed request methods. In your case it only allows GET. Maybe you are using the wrong endpoint? – Ivar Jan 01 '18 at 15:18
  • Ah thanks, I changed the endpoint. However, I am now getting `Bad Request` for some reason, please check my edited code. – Gamer818 Jan 01 '18 at 15:22
  • I didn't mean that you have to set an allow header. The server returning it has to. And it did if you look at the response message you provided. (it says `Allow: GET`). That's how I knew that it only accepted a GET request. It would be helpful if you also add the part of the code where you set the endpoint. (Where is the `server` variable created?) – Ivar Jan 01 '18 at 15:27
  • The server variable is final and created at the top of the code, I just added the variable in the edit and the new response message i am getting. – Gamer818 Jan 01 '18 at 15:29
  • Instead of calling the `response.toString();`, try to get the response body and see if it has a better error message. (See https://stackoverflow.com/a/13742322 for how). – Ivar Jan 01 '18 at 15:34
  • I used the first method shown in the link, and it now shows a much clearer error message, it's in my edit. – Gamer818 Jan 01 '18 at 15:42
  • 3
    But it appears that you called this function a bit too often and that you now need to use a captcha. It doesn't say anything about it in the documentation. You could try again after some time. It might work fine after that. – Ivar Jan 01 '18 at 15:46

1 Answers1

0

Just use OpenMCAuthenticator

It just solves all problem, even sessions.

Arkyo
  • 307
  • 1
  • 2
  • 13
  • I doubt using that program would solve my problem, since we're both getting information from mojang's API – Gamer818 Mar 07 '18 at 05:47
  • 1
    I use it and I got no problems at all. The class is static so I don't even have to worry about messing with instances – Arkyo Mar 07 '18 at 10:29