using System.Net.Http.Json; using System.Text.Json.Nodes; using System.Text.Json.Serialization; using ArcaneLibs.Extensions; using LibMatrix.Responses; namespace LibMatrix.Homeservers; public class UserInteractiveAuthClient { public UserInteractiveAuthClient(RemoteHomeserver hs) { Homeserver = hs; } [JsonIgnore] public RemoteHomeserver Homeserver { get; } private LoginResponse? _guestLogin; public async Task GetAvailableFlowsAsync(bool enableRegister = false, bool enableGuest = false) { // var resp = await Homeserver.ClientHttpClient.GetAsync("/_matrix/client/v3/login"); // var data = await resp.Content.ReadFromJsonAsync(); // if (!resp.IsSuccessStatusCode) Console.WriteLine("LoginFlows: " + await resp.Content.ReadAsStringAsync()); // var loginFlows = data; // // try { // var req = new HttpRequestMessage(HttpMethod.Post, "/_matrix/client/v3/register") { // Content = new StringContent("{}") // }; // var resp2 = await Homeserver.ClientHttpClient.SendUnhandledAsync(req, CancellationToken.None); // var data2 = await resp2.Content.ReadFromJsonAsync(); // if (!resp.IsSuccessStatusCode) Console.WriteLine("RegisterFlows: " + data2.ToJson()); // // return data; // } // catch (MatrixException e) { // if (e is { ErrorCode: "M_FORBIDDEN" }) return null; // throw; // } // catch (Exception e) { // Console.WriteLine(e); // throw; // } // // return new UIAStage1Client() { }; } private async Task GetRegisterFlowsAsync() { return null; } internal class RegisterFlowsResponse { [JsonPropertyName("session")] public string Session { get; set; } = null!; [JsonPropertyName("flows")] public List Flows { get; set; } = null!; [JsonPropertyName("params")] public JsonObject Params { get; set; } = null!; public class RegisterFlow { [JsonPropertyName("stages")] public List Stages { get; set; } = null!; } } internal class LoginFlowsResponse { [JsonPropertyName("flows")] public List Flows { get; set; } = null!; public class LoginFlow { [JsonPropertyName("type")] public string Type { get; set; } = null!; } } public interface IUIAStage { public IUIAStage? PreviousStage { get; } } public class UIAStage1Client : IUIAStage { public IUIAStage? PreviousStage { get; } // public LoginFlowsResponse LoginFlows { get; set; } } }