Здравствуйте, во-первых, извините за мой плохой английский. Мне нужна помощь в создании собственной системы аутентификации для roblox. Я использую roblox auth api: https://auth.roblox.com/docs#!/Authentication/post_v2_login, но я не могу получить действительный ответ от сервера. Я получаю код ошибки 400 "Требуется имя пользователя и пароль. Пожалуйста, попробуйте еще раз."
Я протестировал следующую структуру команд curl, она работает нормально:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{\"ctype": "Username", \"cvalue": "username", \"password": "password" \}' 'https://auth.roblox.com/v2/login'
мои сценарии c #:
IEnumerator request()
{
var content = "{ \"ctype\" : \"Username\" , \"cvalue\": \"username\", \"password\" : \"password\"}";
var encoding = new System.Text.UTF8Encoding();
var headers = new Hashtable ();
headers.Add("Content-Type", "application/json");
headers.Add("Accept", "application/json");
headers.Add ("X-CSRF-TOKEN", "sendfalsetokken");
//Send a request with a bad tokken to get a valid token from roblox system
var request = new WWW ("https://auth.roblox.com/v2/login", encoding.GetBytes (content), headers);
yield return request;
//I get a error 403 Token Validation Failed it's logic the token in headers is bad
Debug.Log (request.text);
//this foreach allow me to recover the token from roblox
foreach(KeyValuePair<string, string> entry in request.responseHeaders)
{
if (entry.Key == "X-CSRF-TOKEN") {
Tokken = entry.Value;
}
}
//And finally I resend a new post request with a correct token
headers = new Hashtable();
headers.Add("Content-Type", "application/json");
headers.Add("Accept", "application/json");
headers.Add ("X-CSRF-TOKEN", Tokken);
request = new WWW ("https://auth.roblox.com/v2/login", encoding.GetBytes (content), headers);
yield return request;
//And I get a error 400 Username and Password are required. Please try again. I don't know why ...
Debug.Log (request.text);
yield break;
}
спасибо за вашу помощь.