tgstation-server 6.12.3
The /tg/station 13 server suite
Loading...
Searching...
No Matches
AuthenticatedGraphQLServerClient.cs
Go to the documentation of this file.
1using System;
2using System.Net.Http.Headers;
3using System.Threading.Tasks;
4
5using Microsoft.Extensions.Logging;
6
7using StrawberryShake;
8
10
12{
15 {
18
22 readonly Func<string, IRestServerClient>? getRestClientForToken;
23
28
37 IGraphQLClient graphQLClient,
39 ILogger<GraphQLServerClient> logger,
42 {
43 this.restClient = restClient ?? throw new ArgumentNullException(nameof(restClient));
44 }
45
57 IGraphQLClient graphQLClient,
59 ILogger<GraphQLServerClient> logger,
60 Action<AuthenticationHeaderValue> setAuthenticationHeader,
61 AuthenticationHeaderValue? basicCredentialsHeader,
62 IOperationResult<ILoginResult> loginResult,
63 Func<string, IRestServerClient> getRestClientForToken)
64 : base(
67 logger,
70 loginResult)
71 {
72 this.getRestClientForToken = getRestClientForToken ?? throw new ArgumentNullException(nameof(getRestClientForToken));
73 restClient = getRestClientForToken(loginResult.Data!.Login.LoginResult!.Bearer.EncodedToken);
74 }
75
77 public sealed override ValueTask DisposeAsync()
78#pragma warning disable CA2012 // Use ValueTasks correctly
80 base.DisposeAsync(),
81 restClient!.DisposeAsync());
82#pragma warning restore CA2012 // Use ValueTasks correctly
83
85 protected sealed override async ValueTask<AuthenticationHeaderValue> CreateUpdatedAuthenticationHeader(string bearer)
86 {
87 var baseTask = base.CreateUpdatedAuthenticationHeader(bearer);
88 if (restClient != null)
89 await restClient.DisposeAsync().ConfigureAwait(false);
90
91 if (getRestClientForToken != null)
93
94 return await baseTask.ConfigureAwait(false);
95 }
96 }
97}
AuthenticatedGraphQLServerClient(IGraphQLClient graphQLClient, IAsyncDisposable serviceProvider, ILogger< GraphQLServerClient > logger, IRestServerClient restClient)
Initializes a new instance of the AuthenticatedGraphQLServerClient class.
AuthenticatedGraphQLServerClient(IGraphQLClient graphQLClient, IAsyncDisposable serviceProvider, ILogger< GraphQLServerClient > logger, Action< AuthenticationHeaderValue > setAuthenticationHeader, AuthenticationHeaderValue? basicCredentialsHeader, IOperationResult< ILoginResult > loginResult, Func< string, IRestServerClient > getRestClientForToken)
Initializes a new instance of the AuthenticatedGraphQLServerClient class.
override async ValueTask< AuthenticationHeaderValue > CreateUpdatedAuthenticationHeader(string bearer)
Create a AuthenticationHeaderValue from a given bearer token.A new AuthenticationHeaderValue.
readonly? Func< string, IRestServerClient > getRestClientForToken
A Func<T, TResult> that takes a bearer token as input and outputs a ITransferClient that uses it.
readonly IAsyncDisposable serviceProvider
The IAsyncDisposable to be DisposeAsync'd with the GraphQLServerClient.
readonly ILogger< GraphQLServerClient > logger
The ILogger for the GraphQLServerClient.
readonly IGraphQLClient graphQLClient
The IGraphQLClient for the GraphQLServerClient.
readonly? Action< AuthenticationHeaderValue > setAuthenticationHeader
The Action<T> which sets the AuthenticationHeaderValue for HTTP request in the current async context.
readonly? AuthenticationHeaderValue basicCredentialsHeader
The AuthenticationHeaderValue containing the authenticated user's password credentials.
Extension methods for the ValueTask and ValueTask<TResult> classes.
static async ValueTask WhenAll(IEnumerable< ValueTask > tasks)
Fully await a given list of tasks .
Main client for communicating with a server.
ITransferClient Transfer
Access the ITransferClient.
For transferring data Streams.