blob: eedc970a5c36aec18193ef025137486bdfd3fd5d (
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
|
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using MatrixRoomUtils.Authentication;
namespace MatrixRoomUtils.Responses;
public class LoginResponse
{
[JsonPropertyName("access_token")]
public string AccessToken { get; set; }
[JsonPropertyName("device_id")]
public string DeviceId { get; set; }
[JsonPropertyName("home_server")]
public string HomeServer { get; set; }
[JsonPropertyName("user_id")]
public string UserId { get; set; }
public async Task<ProfileResponse> GetProfile()
{
var hc = new HttpClient();
var resp = await hc.GetAsync($"{HomeServer}/_matrix/client/r0/profile/{UserId}");
var data = await resp.Content.ReadFromJsonAsync<JsonElement>();
if(!resp.IsSuccessStatusCode) Console.WriteLine("Profile: " + data.ToString());
return data.Deserialize<ProfileResponse>();
}
public async Task<string> GetCanonicalHomeserverUrl()
{
return await MatrixAccount.ResolveHomeserverFromWellKnown(HomeServer);
}
}
|