mirror of
https://gitlab.com/nullmax17/PlombirLauncher.git
synced 2025-03-14 18:01:12 +03:00
58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
|
|
using CmlLib.Core;
|
|
using CmlLib.Core.Auth;
|
|
using XboxAuthNet.Game.Msal;
|
|
using CmlLib.Core.Auth.Microsoft;
|
|
|
|
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;
|
|
});
|
|
|
|
}
|
|
|
|
/*
|
|
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();
|
|
|
|
var authenticator = loginHandler.CreateAuthenticatorWithNewAccount(default);
|
|
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}");
|
|
}
|
|
}
|
|
}
|