Remove Auth V1 fallback, allow auth redirect
This commit is contained in:
@@ -28,7 +28,13 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
_serverManager = serverManager;
|
_serverManager = serverManager;
|
||||||
_dalamudUtil = dalamudUtil;
|
_dalamudUtil = dalamudUtil;
|
||||||
_httpClient = new();
|
_httpClient = new(
|
||||||
|
new HttpClientHandler
|
||||||
|
{
|
||||||
|
AllowAutoRedirect = true,
|
||||||
|
MaxAutomaticRedirections = 5
|
||||||
|
}
|
||||||
|
);
|
||||||
var ver = Assembly.GetExecutingAssembly().GetName().Version;
|
var ver = Assembly.GetExecutingAssembly().GetName().Version;
|
||||||
Mediator = mareMediator;
|
Mediator = mareMediator;
|
||||||
Mediator.Subscribe<DalamudLogoutMessage>(this, (_) =>
|
Mediator.Subscribe<DalamudLogoutMessage>(this, (_) =>
|
||||||
@@ -75,25 +81,15 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
|||||||
new("charaIdent", await _dalamudUtil.GetPlayerNameHashedAsync().ConfigureAwait(false)),
|
new("charaIdent", await _dalamudUtil.GetPlayerNameHashedAsync().ConfigureAwait(false)),
|
||||||
]), token).ConfigureAwait(false);
|
]), token).ConfigureAwait(false);
|
||||||
|
|
||||||
if (result.StatusCode == HttpStatusCode.NotFound)
|
if (!result.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
tokenUri = MareAuth.AuthFullPath(new Uri(_serverManager.CurrentApiUrl
|
Mediator.Publish(new NotificationMessage("Error refreshing token", "Your authentication token could not be renewed. Try reconnecting manually.", NotificationType.Error));
|
||||||
.Replace("wss://", "https://", StringComparison.OrdinalIgnoreCase)
|
Mediator.Publish(new DisconnectedMessage());
|
||||||
.Replace("ws://", "http://", StringComparison.OrdinalIgnoreCase)));
|
|
||||||
result = await _httpClient.PostAsync(tokenUri, new FormUrlEncodedContent([
|
|
||||||
new("auth", auth),
|
|
||||||
new("charaIdent", await _dalamudUtil.GetPlayerNameHashedAsync().ConfigureAwait(false)),
|
|
||||||
]), token).ConfigureAwait(false);
|
|
||||||
|
|
||||||
var textResponse = await result.Content.ReadAsStringAsync(token).ConfigureAwait(false) ?? string.Empty;
|
var textResponse = await result.Content.ReadAsStringAsync(token).ConfigureAwait(false) ?? string.Empty;
|
||||||
result.EnsureSuccessStatusCode();
|
throw new MareAuthFailureException(textResponse);
|
||||||
_tokenCache[identifier] = textResponse;
|
|
||||||
_wellKnownCache[_serverManager.CurrentApiUrl] = null;
|
|
||||||
return textResponse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = await result.Content.ReadFromJsonAsync<AuthReplyDto>(token).ConfigureAwait(false) ?? new();
|
var response = await result.Content.ReadFromJsonAsync<AuthReplyDto>(token).ConfigureAwait(false) ?? new();
|
||||||
result.EnsureSuccessStatusCode();
|
|
||||||
_tokenCache[identifier] = response.Token;
|
_tokenCache[identifier] = response.Token;
|
||||||
_wellKnownCache[_serverManager.CurrentApiUrl] = response.WellKnown;
|
_wellKnownCache[_serverManager.CurrentApiUrl] = response.WellKnown;
|
||||||
return response.Token;
|
return response.Token;
|
||||||
@@ -109,6 +105,7 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
|||||||
{
|
{
|
||||||
Mediator.Publish(new NotificationMessage("Error refreshing token", "Your authentication token could not be renewed. Try reconnecting manually.", NotificationType.Error));
|
Mediator.Publish(new NotificationMessage("Error refreshing token", "Your authentication token could not be renewed. Try reconnecting manually.", NotificationType.Error));
|
||||||
Mediator.Publish(new DisconnectedMessage());
|
Mediator.Publish(new DisconnectedMessage());
|
||||||
|
throw new MareAuthFailureException(ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
|
|||||||
Reference in New Issue
Block a user