How to authenticate a League of Legends account via code (C#)
Why do I need this?
If you are willing to create a massive authenticator for League of Legends maybe this post will help you.
Any recommendation before start? Keep in mind these important region codes:
Brazil = "br"
Europe Nordic & East = "eun1"
Europe West = "euw1"
Japan = "jp1"
Korea = "kr"
Latin America North = "la1"
Latin America South = "la2"
North America = "na2"
Ocenia = "oc1"
Turkey = "tr"
Russia = "ru"
Pbe = "pbe1"
I highly suggest you to work with tasks while you're validating (authenticating) accounts.
Another optional suggestion is that you setup a proxy before going to request an authentication (in this guide the code doesn't have any proxy procedure before requesting an authentication, as the main topic is just to authenticate an account).
Source Code & Usage
Code:
using System.Net;
using System(dot)IO;
private async Task<bool> Authenticate(string username, string password, string region)
{
bool canLogin;
WebResponse response = null;
try
{
//Setting the payload to send for the authentication.
string payload = string.Format("payload=user={0},password={1}", username, password);
//Creating the web request, I highly suggest you to work with proxy before creating the request.
WebRequest request = WebRequest.Create(string.Format("https://lqak.{0}.lol.riotgames.com/login-queue/rest/queues/lol/authenticate", region));
if (request != null)
{
//Method "POST", because we will send information and we will get a response of the website.
request.Method = "POST";
//Wait the code to stablish a request stream ...
using (Stream outputStream = await request.GetRequestStreamAsync())
{
//Send the payload to the stream connection between the request and the authentication link!
outputStream.Write(Encoding.ASCII.GetBytes(payload), 0, Encoding.ASCII.GetByteCount(payload));
outputStream.Close(); //Close the stream.
}
}
else
{
//Couldn't make a request, obviously if I reached this part of the code it means that I couldn't validate the account.
return canLogin = false;
}
//Wait the code to stablish a response from the payload we send to the request.
response = await request.GetResponseAsync();
//If response has any content it (usually) means that you can login into the account.
if (response.ContentLength > 0) return canLogin = true;
else return canLogin = false;
}
catch (Exception e)
{
//Some weird ass error occurred when trying to validate the account (maybe the password was not the right one)
//If you want to know what happened type: e.Message (it will return a string trying to say what error happened).
return canLogin = false;
}
finally
{
if (response != null) response.Close(); //Close the response.
}
}
Code:
//Initialize the authentication procedure.
var t = new Task(async () =>
{
//Self explanatory ...
if (await Authenticate("dummy Username", "myPasswordIsFake", "la1")) Console.WriteLine("Account was succefully authentificated.");
else Console.WriteLine("Account couldn't been authenticated.");
});
t.Start(); //Start the task.
t.Wait(); //Wait for it to finish.
Proof/Video
Credits
I have recycle my own code from an authenticator I had made before. I just recoded, updated and improved the code.