diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-05-01 02:43:32 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-05-01 02:43:32 +0200 |
commit | df9031c47f8e97d8e2df3177093271a458f27267 (patch) | |
tree | 4e81dec4048c6e76a928ef69c905560d7c173fdf /MatrixRoomUtils.Core/Responses/LoginResponse.cs | |
download | MatrixUtils-df9031c47f8e97d8e2df3177093271a458f27267.tar.xz |
Initial commit
Diffstat (limited to 'MatrixRoomUtils.Core/Responses/LoginResponse.cs')
-rw-r--r-- | MatrixRoomUtils.Core/Responses/LoginResponse.cs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Core/Responses/LoginResponse.cs b/MatrixRoomUtils.Core/Responses/LoginResponse.cs new file mode 100644 index 0000000..eedc970 --- /dev/null +++ b/MatrixRoomUtils.Core/Responses/LoginResponse.cs @@ -0,0 +1,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); + } +} \ No newline at end of file |