diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-09-29 19:38:00 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-09-29 19:38:00 +0200 |
commit | 46df5b8e335754f1582fc4d41d9546808ed8ee66 (patch) | |
tree | 29fed832bed495f1bd233c37275cb560c19f34cf /LibMatrix/Responses/LoginResponse.cs | |
parent | Add more stuff, add unit tests (diff) | |
download | LibMatrix-46df5b8e335754f1582fc4d41d9546808ed8ee66.tar.xz |
Unit tests, small refactors
Diffstat (limited to 'LibMatrix/Responses/LoginResponse.cs')
-rw-r--r-- | LibMatrix/Responses/LoginResponse.cs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/LibMatrix/Responses/LoginResponse.cs b/LibMatrix/Responses/LoginResponse.cs index 175f337..eb53c0a 100644 --- a/LibMatrix/Responses/LoginResponse.cs +++ b/LibMatrix/Responses/LoginResponse.cs @@ -1,19 +1,30 @@ using System.Text.Json.Serialization; +using LibMatrix.Homeservers; +using LibMatrix.Services; namespace LibMatrix.Responses; public class LoginResponse { [JsonPropertyName("access_token")] - public string AccessToken { get; set; } + public string AccessToken { get; set; } = null!; [JsonPropertyName("device_id")] - public string DeviceId { get; set; } + public string DeviceId { get; set; } = null!; + + private string? _homeserver; [JsonPropertyName("home_server")] - public string Homeserver { get; set; } + public string Homeserver { + get => _homeserver ?? UserId.Split(':', 2).Last(); + protected init => _homeserver = value; + } [JsonPropertyName("user_id")] - public string UserId { get; set; } + public string UserId { get; set; } = null!; + + public async Task<AuthenticatedHomeserverGeneric> GetAuthenticatedHomeserver(string? proxy = null) { + return new AuthenticatedHomeserverGeneric(proxy ?? await new HomeserverResolverService().ResolveHomeserverFromWellKnown(Homeserver), AccessToken); + } } public class LoginRequest { [JsonPropertyName("type")] |