58 lines
1.7 KiB
C#
Raw Normal View History

2025-02-22 12:19:42 +03:00
using CmlLib.Core;
using CmlLib.Core.Auth;
using XboxAuthNet.Game.Msal;
using CmlLib.Core.Auth.Microsoft;
2025-02-22 12:19:42 +03:00
namespace Plombir;
static public class Utils
{
public static async Task<List<string>> GetAllMcVersions()
{
return await Task.Run(async () =>
{
var ln = new MinecraftLauncher();
var result = new List<string>();
foreach (var x in await ln.GetAllVersionsAsync())
{
result.Add(x.Name);
}
return result;
});
}
/*
2025-02-25 18:32:10 +03:00
ID is approved, we are so ready.
*/
public static async Task<MSession>? GetLicensedSession()
{
try
{
var app = await MsalClientHelper.BuildApplicationWithCache(
"d87c436c-aad0-46ea-b392-b53b3ed787b1"
);
var loginHandler = JELoginHandlerBuilder.BuildDefault();
2025-02-22 12:19:42 +03:00
var authenticator = loginHandler.CreateAuthenticatorWithNewAccount(default);
2025-02-26 17:04:42 +03:00
authenticator.AddMsalOAuth(app, msal => msal.SystemBrowser());
// authenticator.AddMsalOAuth(app, msal => msal.DeviceCode(deviceCode =>
// {
// Console.WriteLine(deviceCode.Message);
// return Task.CompletedTask;
// }));
// Im too lazy to implement this type of auth
authenticator.AddMsalOAuth(app, msal => msal.Silent());
authenticator.AddXboxAuthForJE(xbox => xbox.Basic());
authenticator.AddJEAuthenticator();
return await authenticator.ExecuteForLauncherAsync();
}
catch (Exception e)
{
throw new Exception($"Failed to authentificate! {e}");
}
}
2025-02-22 12:19:42 +03:00
}