about summary refs log tree commit diff
path: root/LibMatrix/Responses/LoginResponse.cs
blob: 3962fa676564eaba67f4c57b93b06a6d54da3576 (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
using System.Text.Json.Serialization;
using LibMatrix.Homeservers;

namespace LibMatrix.Responses;

public class LoginResponse {
    [JsonPropertyName("access_token")]
    public string AccessToken { get; set; } = null!;

    [JsonPropertyName("device_id")]
    public string DeviceId { get; set; } = null!;

    private string? _homeserver;

    [JsonPropertyName("home_server")]
    public string Homeserver {
        get => _homeserver ?? UserId.Split(':', 2).Last();
        protected init => _homeserver = value;
    }

    [JsonPropertyName("user_id")]
    public string UserId { get; set; } = null!;

    public async Task<AuthenticatedHomeserverGeneric> GetAuthenticatedHomeserver(string? proxy = null) =>
        // var urls = await new HomeserverResolverService().ResolveHomeserverFromWellKnown(Homeserver);
        await AuthenticatedHomeserverGeneric.Create<AuthenticatedHomeserverGeneric>(Homeserver, AccessToken, proxy);
}

public class LoginRequest {
    [JsonPropertyName("type")]
    public string Type { get; set; } = "m.login.password";

    [JsonPropertyName("identifier")]
    public LoginIdentifier Identifier { get; set; } = new();

    [JsonPropertyName("password")]
    public string Password { get; set; } = "";

    [JsonPropertyName("initial_device_display_name")]
    public string InitialDeviceDisplayName { get; set; } = "Rory&::LibMatrix";

    public class LoginIdentifier {
        [JsonPropertyName("type")]
        public string Type { get; set; } = "m.id.user";

        [JsonPropertyName("user")]
        public string User { get; set; } = "";
    }
}