about summary refs log tree commit diff
path: root/LibMatrix/Homeservers/UserInteractiveAuthClient.cs
blob: 8be2cb9fa8070c54e25b5cc395a40cec1ea65a12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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<UIAStage1Client> GetAvailableFlowsAsync(bool enableRegister = false, bool enableGuest = false) {
        // var resp = await Homeserver.ClientHttpClient.GetAsync("/_matrix/client/v3/login");
        // var data = await resp.Content.ReadFromJsonAsync<LoginFlowsResponse>();
        // 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<RegisterFlowsResponse>();
        //     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<RegisterFlowsResponse?> GetRegisterFlowsAsync() {
        return null;
    }

    internal class RegisterFlowsResponse {
        [JsonPropertyName("session")]
        public string Session { get; set; } = null!;

        [JsonPropertyName("flows")]
        public List<RegisterFlow> Flows { get; set; } = null!;

        [JsonPropertyName("params")]
        public JsonObject Params { get; set; } = null!;

        public class RegisterFlow {
            [JsonPropertyName("stages")]
            public List<string> Stages { get; set; } = null!;
        }
    }

    internal class LoginFlowsResponse {
        [JsonPropertyName("flows")]
        public List<LoginFlow> 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; }
    }
}