Q
Q
QWATRIX2019-10-09 17:57:14
API
QWATRIX, 2019-10-09 17:57:14

How to solve Mojang API authorization issue?

Wrote an authorization script to verify a Mojang account.

$post_data = array (
    "Username" => "[email protected]",
    "Password" => "Dominicc1599",
    "ClientToken" => "7c825a05-817a-4aad-939e-02c9dd3d923a"
);

$ch = curl_init("https://authserver.ely.by/auth/authenticate");

curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 4);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

$output = curl_exec($ch);

But the API throws an error: {"error":"IllegalArgumentException" , "errorMessage":"credentials can not be null."}
Documentation: https://docs.ely.by/ru/minecraft-auth.html
help me please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JhaoDa, 2019-10-09
@QWATRIX

If you read the original mojang.com doc, you can see that the guys from ely.by tore it up with fundamental mistakes:
- they forgot that the parameters must be passed in json (however, application/x-www-form-urlencodedit also works);
- for some reason they renamed all the parameters with a capital letter.
Request

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://authserver.ely.by/auth/authenticate",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS =>"{\n\t\"username\":\"[email protected]\",\n\t\"password\":\"Dominicc1599\",\n\t\"clientToken\":\"7c825a05-817a-4aad-939e-02c9dd3d923a\"\n}",
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);

gives a different answer:
{
    "error": "ForbiddenOperationException",
    "errorMessage": "Invalid credentials. Invalid email or password."
}

R
Randewoo, 2019-10-09
@Randewoo

So you have an array within an array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question