I'm trying to create a simple custom minecraft launcher for myself and some friends. I don't need the code to start minecraft, just the actual line of code to login. For example, to my knowledge, you used to be able to use:
string netResponse = httpGET("https://login.minecraft.net/session?name=<USERNAME>&session=<SESSION ID>" + username + "&password=" + password + "&version=" + clientVer);
I'm aware there is no longer a https://login.minecraft.net, meaning this code won't work. This is about all I need to continue, only the place to connect to login, and the variables to include. Thanks, if any additional info is needed, give a comment.
You need to make a JSON POST request to https://authserver.mojang.com/authenticate and heres my method of getting an access token (which you can use to play the game)
Code:
string ACCESS_TOKEN;
public string GetAccessToken()
{
return ACCESS_TOKEN;
}
public void ObtainAccessToken(string username, string password)
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://authserver.mojang.com/authenticate");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{\"agent\":{\"name\":\"Minecraft\",\"version\":1},\"username\":\""+username+"\",\"password\":\""+password+"\",\"clientToken\":\"6c9d237d-8fbf-44ef-b46b-0b8a854bf391\"}";
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
ACCESS_TOKEN = result;
}
}
}
Declare these aswell:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;
And if you haven't already, refrence System.Web.Extentions
I tested this with C# winforms and it works :)
Thanks,
DMP9
The login server is now https://authserver.mojang.com/authenticate
, and it uses JSON-formatted info.
Use this format for the JSON request:
{"agent": { "name": "Minecraft", "version": 1 }, "username": "example", "password": "hunter2"}
Here is a full implementation for logging in.