mirror of
https://github.com/Caraxi/mare.client.git
synced 2025-12-13 23:04:16 +01:00
get identifier async
This commit is contained in:
parent
91c7cc5fc8
commit
97a263f845
2 changed files with 8 additions and 6 deletions
|
|
@ -149,7 +149,8 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
|
||||||
private async Task<HttpResponseMessage> SendRequestInternalAsync(HttpRequestMessage requestMessage,
|
private async Task<HttpResponseMessage> SendRequestInternalAsync(HttpRequestMessage requestMessage,
|
||||||
CancellationToken? ct = null, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead)
|
CancellationToken? ct = null, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead)
|
||||||
{
|
{
|
||||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _tokenProvider.GetToken());
|
var token = await _tokenProvider.GetToken().ConfigureAwait(false);
|
||||||
|
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||||
|
|
||||||
if (requestMessage.Content != null && requestMessage.Content is not StreamContent && requestMessage.Content is not ByteArrayContent)
|
if (requestMessage.Content != null && requestMessage.Content is not StreamContent && requestMessage.Content is not ByteArrayContent)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -131,13 +131,14 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JwtIdentifier? GetIdentifier()
|
private async Task<JwtIdentifier?> GetIdentifier()
|
||||||
{
|
{
|
||||||
JwtIdentifier jwtIdentifier;
|
JwtIdentifier jwtIdentifier;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var playerIdentifier = await _dalamudUtil.GetPlayerNameHashedAsync().ConfigureAwait(false);
|
||||||
jwtIdentifier = new(_serverManager.CurrentApiUrl,
|
jwtIdentifier = new(_serverManager.CurrentApiUrl,
|
||||||
_dalamudUtil.GetPlayerNameHashedAsync().GetAwaiter().GetResult(),
|
playerIdentifier,
|
||||||
_serverManager.GetSecretKey(out _)!);
|
_serverManager.GetSecretKey(out _)!);
|
||||||
_lastJwtIdentifier = jwtIdentifier;
|
_lastJwtIdentifier = jwtIdentifier;
|
||||||
}
|
}
|
||||||
|
|
@ -157,9 +158,9 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
||||||
return jwtIdentifier;
|
return jwtIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? GetToken()
|
public async Task<string?> GetToken()
|
||||||
{
|
{
|
||||||
JwtIdentifier? jwtIdentifier = GetIdentifier();
|
JwtIdentifier? jwtIdentifier = await GetIdentifier().ConfigureAwait(false);
|
||||||
if (jwtIdentifier == null) return null;
|
if (jwtIdentifier == null) return null;
|
||||||
|
|
||||||
if (_tokenCache.TryGetValue(jwtIdentifier, out var token))
|
if (_tokenCache.TryGetValue(jwtIdentifier, out var token))
|
||||||
|
|
@ -172,7 +173,7 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
||||||
|
|
||||||
public async Task<string?> GetOrUpdateToken(CancellationToken ct)
|
public async Task<string?> GetOrUpdateToken(CancellationToken ct)
|
||||||
{
|
{
|
||||||
JwtIdentifier? jwtIdentifier = GetIdentifier();
|
JwtIdentifier? jwtIdentifier = await GetIdentifier().ConfigureAwait(false);
|
||||||
if (jwtIdentifier == null) return null;
|
if (jwtIdentifier == null) return null;
|
||||||
|
|
||||||
bool renewal = false;
|
bool renewal = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue