mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-30 08:33:19 +01:00
IServerClient's token can now be updated
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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!");
|
||||
|
||||
Reference in New Issue
Block a user