From 440807e02393410327cd86d5ffa007dee98f8954 Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 19 Apr 2024 15:54:30 +0200 Subject: Partial User-Interactive Authentication, allow skipping homeserver typing --- LibMatrix/Homeservers/UserInteractiveAuthClient.cs | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 LibMatrix/Homeservers/UserInteractiveAuthClient.cs (limited to 'LibMatrix/Homeservers/UserInteractiveAuthClient.cs') diff --git a/LibMatrix/Homeservers/UserInteractiveAuthClient.cs b/LibMatrix/Homeservers/UserInteractiveAuthClient.cs new file mode 100644 index 0000000..8be2cb9 --- /dev/null +++ b/LibMatrix/Homeservers/UserInteractiveAuthClient.cs @@ -0,0 +1,85 @@ +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; } + } +} \ No newline at end of file -- cgit 1.4.1