/// <summary> /// A Function to authenticate a player to Mojang's API. Username and Password must be valid. If the process was succesfull then you can access LastResponse to get any infromation available. /// </summary> /// <param name="username">The userame or email to Authenticate</param> /// <param name="password">The user's password for the current account</param> /// <param name="guid">A guid for the current machine</param> /// <returns>Returns true if the Authentication proccess was succefull.</returns> public static async Task <bool> Try(string username, string password, string guid) { var jsonRequest = new AuthenticateJSON { username = username, password = password, requestUser = true, clientToken = guid, agent = new Agent { name = "Minecraft", version = 1 } }; string responseString; try { responseString = await NetConnector.MakeRequest(jsonRequest, "https://authserver.mojang.com/authenticate"); } catch { return(false); } lastResponse = JsonConvert.DeserializeObject <APIResponse>(responseString); return(true); }
public static async Task <string> Authenticate(string username, string password) { var vjson = new AuthenticateJSON { username = username, password = password, clientToken = Settings.Default.clientToken, requestUser = true, agent = new Agent { name = "Minecraft", version = 1 } }; HttpClient client = new HttpClient(); var content = new StringContent(JsonConvert.SerializeObject(vjson), Encoding.UTF8, "application/json"); var response = await client.PostAsync("https://authserver.mojang.com/authenticate", content); var responseString = await response.Content.ReadAsStringAsync(); return(responseString); }
public Authenticate(Uri server, AuthenticateJSON json) { opHost = server; hOp = HTTPOperation.POST; this.json = json; }