adjust token handling

This commit is contained in:
rootdarkarchon
2023-10-24 22:31:34 +02:00
parent 82cca2e035
commit fc9953bb8d
2 changed files with 14 additions and 1 deletions

View File

@@ -89,6 +89,9 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
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);
}
@@ -103,6 +106,16 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
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)
{
bool renewal = forceRenew;