From df9031c47f8e97d8e2df3177093271a458f27267 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 1 May 2023 02:43:32 +0200 Subject: Initial commit --- MatrixRoomUtils.Core/Responses/LoginResponse.cs | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 MatrixRoomUtils.Core/Responses/LoginResponse.cs (limited to 'MatrixRoomUtils.Core/Responses/LoginResponse.cs') 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 GetProfile() + { + var hc = new HttpClient(); + var resp = await hc.GetAsync($"{HomeServer}/_matrix/client/r0/profile/{UserId}"); + var data = await resp.Content.ReadFromJsonAsync(); + if(!resp.IsSuccessStatusCode) Console.WriteLine("Profile: " + data.ToString()); + return data.Deserialize(); + } + public async Task GetCanonicalHomeserverUrl() + { + return await MatrixAccount.ResolveHomeserverFromWellKnown(HomeServer); + } +} \ No newline at end of file -- cgit 1.4.1