Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions Plugins/RSBot.General/Components/RuSroAuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public static async Task<bool> Auth()
return false;
}

Log.Debug(selectedAccount?.Username);

string username = selectedAccount.Username;
string password = selectedAccount.Password;

Expand Down Expand Up @@ -119,6 +117,11 @@ public static async Task<string> TokenResponse(string username, string password)
var parameters = new List<KeyValuePair<string, string>>();
string refreshToken = GlobalConfig.Get<string>("RSBot.RuSro.refreshToken");
string accessToken = GlobalConfig.Get<string>("RSBot.RuSro.accessToken");
string sessionId = GlobalConfig.Get<string>("RSBot.RuSro.sessionId");
string endpoint = "https://launcherbff.ru.4game.com/connect/token";

HttpContent tokenRequestContent = null;

if (
!string.IsNullOrEmpty(refreshToken)
&& !string.IsNullOrEmpty(accessToken)
Expand All @@ -135,27 +138,36 @@ public static async Task<string> TokenResponse(string username, string password)
parameters.Add(new KeyValuePair<string, string>("secure", "true"));
parameters.Add(new KeyValuePair<string, string>("grant_type", "password"));
}
var tokenRequestContent = new FormUrlEncodedContent(parameters);
tokenRequestContent = new FormUrlEncodedContent(parameters);

var hwid = GlobalConfig.Get<string>("RSBot.RuSro.hwid", randomHwid);
var launcherId = GlobalConfig.Get<string>("RSBot.RuSro.launcherid", randomLauncherId);

if (!string.IsNullOrEmpty(sessionId) && string.IsNullOrEmpty(refreshToken) && string.IsNullOrEmpty(accessToken))
{
//Instead of POST application/json with sessionId to https://launcherbff.ru.4game.com/api/guard/accesscodes/resend
hwid = randomHwid;
launcherId = randomLauncherId;
}

GlobalConfig.Set("RSBot.RuSro.hwid", hwid);
GlobalConfig.Set("RSBot.RuSro.launcherid", launcherId);
GlobalConfig.Save();

Log.Debug($"HWID: {hwid}");
Log.Debug($"Launcher ID: {launcherId}");

client.DefaultRequestHeaders.Remove("Hardware-Id");
client.DefaultRequestHeaders.Remove("Launcher-Id");
client.DefaultRequestHeaders.Add("Hardware-Id", hwid);
client.DefaultRequestHeaders.Add("Launcher-Id", launcherId);

var tokenResponse = await client.PostAsync(
"https://launcherbff.ru.4game.com/connect/token",
tokenRequestContent
);
var tokenResponseContent = await tokenResponse.Content.ReadAsStringAsync();
return tokenResponseContent;
using (tokenRequestContent)
{
var tokenResponse = await client.PostAsync(endpoint, tokenRequestContent);
var tokenResponseContent = await tokenResponse.Content.ReadAsStringAsync();
return tokenResponseContent;
}
}

private static async Task<string> GetAccessTokenAsync(string username, string password)
Expand Down
Loading