adjust token handling
This commit is contained in:
@@ -115,7 +115,7 @@ 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", await _tokenProvider.GetOrUpdateToken(ct!.Value).ConfigureAwait(false));
|
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _tokenProvider.GetToken());
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -89,6 +89,9 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
|||||||
|
|
||||||
if (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized)
|
if (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized)
|
||||||
{
|
{
|
||||||
|
Mediator.Publish(new NotificationMessage("Error refreshing token", "Your authentication token could not be renewed. Try reconnecting to Mare manually.",
|
||||||
|
Dalamud.Interface.Internal.Notifications.NotificationType.Error));
|
||||||
|
Mediator.Publish(new DisconnectedMessage());
|
||||||
throw new MareAuthFailureException(response);
|
throw new MareAuthFailureException(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +106,16 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string? GetToken()
|
||||||
|
{
|
||||||
|
if (_tokenCache.TryGetValue(CurrentIdentifier, out var token))
|
||||||
|
{
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidOperationException("No token present");
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<string?> GetOrUpdateToken(CancellationToken ct, bool forceRenew = false)
|
public async Task<string?> GetOrUpdateToken(CancellationToken ct, bool forceRenew = false)
|
||||||
{
|
{
|
||||||
bool renewal = forceRenew;
|
bool renewal = forceRenew;
|
||||||
|
|||||||
Reference in New Issue
Block a user