mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-23 19:30:06 +02:00
feat: http header passing mechanism
This commit is contained in:
1 parent
64ad05dc92
commit
05059b0eda
6 files changed
+71
-13
No files matched your search
@@ -12,13 +12,16 @@ namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
{
|
||||
private readonly WotBlitzStatisticsProClient _client;
|
||||
private readonly INotificationsService _notificationsService;
|
||||
private readonly IWargamingAuthTokenHeaderHelper _wargamingAuthTokenHeaderHelper;
|
||||
|
||||
public GraphQlBackendService(
|
||||
WotBlitzStatisticsProClient client,
|
||||
INotificationsService notificationsService)
|
||||
INotificationsService notificationsService,
|
||||
IWargamingAuthTokenHeaderHelper wargamingAuthTokenHeaderHelper)
|
||||
{
|
||||
_client = client;
|
||||
_notificationsService = notificationsService;
|
||||
_wargamingAuthTokenHeaderHelper = wargamingAuthTokenHeaderHelper;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<IPlayerShortInfo>?> FindPlayers(string accountNick, RealmType realmType)
|
||||
@@ -57,11 +60,11 @@ namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Task CollectPlayerInfo(long accountId, RealmType realmType, string accessToken)
|
||||
public async Task CollectPlayerInfo(long accountId, RealmType realmType, string accessToken)
|
||||
{
|
||||
// ToDo: Call mutation with accessToken in the context
|
||||
|
||||
return _client.UpdatePlayer.ExecuteAsync(accountId, realmType, RequestLanguage.En);
|
||||
_wargamingAuthTokenHeaderHelper.WargamingToken = accessToken;
|
||||
var result = await _client.UpdatePlayer.ExecuteAsync(accountId, realmType, RequestLanguage.En);
|
||||
CheckErrors(result.Errors);
|
||||
}
|
||||
|
||||
private RequestLanguage GetLanguage()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
{
|
||||
public interface IWargamingAuthTokenHeaderHelper
|
||||
{
|
||||
string? WargamingToken { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
{
|
||||
public class WargamingAuthTokenHeaderHandler: DelegatingHandler
|
||||
{
|
||||
private readonly IWargamingAuthTokenHeaderHelper _wargamingAuthTokenHeaderHelper;
|
||||
|
||||
public WargamingAuthTokenHeaderHandler(IWargamingAuthTokenHeaderHelper wargamingAuthTokenHeaderHelper)
|
||||
{
|
||||
_wargamingAuthTokenHeaderHelper = wargamingAuthTokenHeaderHelper;
|
||||
}
|
||||
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_wargamingAuthTokenHeaderHelper.WargamingToken))
|
||||
{
|
||||
request.Headers.Add("WargamingToken", _wargamingAuthTokenHeaderHelper.WargamingToken);
|
||||
}
|
||||
return base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
{
|
||||
public class WargamingAuthTokenHeaderHelper : IWargamingAuthTokenHeaderHelper
|
||||
{
|
||||
public string? WargamingToken { get; set; } = null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user