I'm trying to authenticate a user though XboxLive and I'm having some trouble I'm following this article and I cant get past the first step it always returns 400: Bad Request
I did some digging and some people have said to put d= before the accessToken but this didn't help.
public void getXboxLiveToken() throws IOException{
if (this.accessTokenJson == null) getAccessToken();
Header[] headers = new Header[2];
headers[0] = applicationJsonContentTypeHeader;
headers[1] = applicationAcceptJsonHeader;
HttpPost httpPost = new HttpPost(SIGNIN_XBL_URL);
httpPost.setHeaders(headers);
String jsonString = this.gson.toJson(new SignIntoXBLJson(this.accessTokenJson.getAccessToken()));
StringEntity requestEntity = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
httpPost.setEntity(requestEntity);
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
byte[] responseBytes = response.getEntity().getContent().readAllBytes();
System.out.println(response.getStatusLine().getStatusCode() + ": " + response.getStatusLine().getReasonPhrase());
System.out.println(new String(responseBytes));
}
}
Json
{
"Properties": {
"AuthMethod": "RPS",
"SiteName": "user.auth.xboxlive.com",
"RspTicket": "d=<Access Token>"
},
"ReplyingParty": "http://auth.xboxlive.com",
"TokenType": "JWT"
}
It also took me some time to figure it out, but I ended up finding this article: Mojang API Documentation which sums it up quite well.
The request needs to be a
'POST'request with urlhttps://user.auth.xboxlive.com/user/authenticatehaving the headers:Content-Type: application/jsonAccept: application/jsonAnd with the following body:
the result should be similar to this:
The solution I ended up implementing look like this:
I'm using the Unirest library which greatly simplifies the code