IServerClient's token can now be updated

This commit is contained in:
Jordan Brown
2018-10-13 09:19:40 -04:00
parent 08f6c48574
commit 8a475fba6f
2 changed files with 17 additions and 4 deletions
+2 -2
View File
@@ -16,9 +16,9 @@ namespace Tgstation.Server.Client
Uri Url { get; }
/// <summary>
/// The <see cref="Token"/> being used to access the server
/// The <see cref="Token"/> used to access the server
/// </summary>
Token Token { get; }
Token Token { get; set; }
/// <summary>
/// The connection timeout
+15 -2
View File
@@ -13,7 +13,15 @@ namespace Tgstation.Server.Client
public Uri Url => apiClient.Url;
/// <inheritdoc />
public Token Token { get; }
public Token Token
{
get => token;
set
{
token = value ?? throw new InvalidOperationException("Cannot set a null Token!");
apiClient.Headers = new ApiHeaders(apiClient.Headers.UserAgent, token.Bearer);
}
}
/// <inheritdoc />
public TimeSpan Timeout
@@ -36,6 +44,11 @@ namespace Tgstation.Server.Client
/// </summary>
readonly IApiClient apiClient;
/// <summary>
/// Backing field for <see cref="Token"/>
/// </summary>
Token token;
/// <summary>
/// Construct a <see cref="ServerClient"/>
/// </summary>
@@ -44,7 +57,7 @@ namespace Tgstation.Server.Client
public ServerClient(IApiClient apiClient, Token token)
{
this.apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient));
Token = token ?? throw new ArgumentNullException(nameof(token));
token = token ?? throw new ArgumentNullException(nameof(token));
if (Token.Bearer != apiClient.Headers.Token)
throw new ArgumentOutOfRangeException(nameof(token), token, "Provided token does not match apiClient headers!");