mirror of
https://github.com/Caraxi/mare.client.git
synced 2025-12-13 23:44:15 +01:00
check for timezone
This commit is contained in:
parent
9e6108a4d6
commit
24960fd1ba
2 changed files with 23 additions and 2 deletions
|
|
@ -212,6 +212,12 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
|
||||||
Logger.LogInformation("Failed to establish connection, retrying");
|
Logger.LogInformation("Failed to establish connection, retrying");
|
||||||
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token).ConfigureAwait(false);
|
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
Logger.LogWarning(ex, "InvalidOperationException on connection");
|
||||||
|
ServerState = ServerState.Disconnected;
|
||||||
|
return;
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.LogWarning(ex, "Exception on Connection");
|
Logger.LogWarning(ex, "Exception on Connection");
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,16 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
||||||
_logger.LogTrace("GetNewToken: JWT {token}", response);
|
_logger.LogTrace("GetNewToken: JWT {token}", response);
|
||||||
_logger.LogDebug("GetNewToken: Valid until {date}, ValidClaim until {date}", jwtToken.ValidTo,
|
_logger.LogDebug("GetNewToken: Valid until {date}, ValidClaim until {date}", jwtToken.ValidTo,
|
||||||
new DateTime(long.Parse(jwtToken.Claims.Single(c => string.Equals(c.Type, "expiration_date", StringComparison.Ordinal)).Value), DateTimeKind.Utc));
|
new DateTime(long.Parse(jwtToken.Claims.Single(c => string.Equals(c.Type, "expiration_date", StringComparison.Ordinal)).Value), DateTimeKind.Utc));
|
||||||
|
if (jwtToken.ValidTo.Subtract(TimeSpan.FromHours(6).Add(TimeSpan.FromMinutes(1))) > DateTime.UtcNow)
|
||||||
|
{
|
||||||
|
_tokenCache.TryRemove(CurrentIdentifier, out _);
|
||||||
|
Mediator.Publish(new NotificationMessage("Invalid timezone", "The time zone of your computer is invalid. " +
|
||||||
|
"Mare will not function properly if the time zone is not set correctly. " +
|
||||||
|
"Please set your computers time zone correctly and keep it synchronized with the internet.",
|
||||||
|
Dalamud.Interface.Internal.Notifications.NotificationType.Error));
|
||||||
|
Mediator.Publish(new DisconnectedMessage());
|
||||||
|
throw new InvalidOperationException($"JwtToken is behind DateTime.UtcNow, DateTime.UtcNow is possibly wrong. DateTime.UtcNow is {DateTime.UtcNow}, JwtToken.ValidTo is {jwtToken.ValidTo}");
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,15 +132,20 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
||||||
if (_tokenCache.TryGetValue(CurrentIdentifier, out var token))
|
if (_tokenCache.TryGetValue(CurrentIdentifier, out var token))
|
||||||
{
|
{
|
||||||
var handler = new JwtSecurityTokenHandler();
|
var handler = new JwtSecurityTokenHandler();
|
||||||
var jwtToken = handler.ReadJwtToken(token);
|
var jwt = handler.ReadJwtToken(token);
|
||||||
if (jwtToken.ValidTo == DateTime.MinValue || jwtToken.ValidTo.Subtract(TimeSpan.FromMinutes(5)) > DateTime.UtcNow)
|
if (jwt.ValidTo == DateTime.MinValue || jwt.ValidTo.Subtract(TimeSpan.FromMinutes(5)) > DateTime.UtcNow)
|
||||||
{
|
{
|
||||||
_logger.LogTrace("GetOrUpdate: Returning token from cache");
|
_logger.LogTrace("GetOrUpdate: Returning token from cache");
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_logger.LogDebug("GetOrUpdate: Cached token requires renewal, token valid to: {valid}, UtcTime is {utcTime}", jwt.ValidTo, DateTime.UtcNow);
|
||||||
renewal = true;
|
renewal = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogDebug("GetOrUpdate: Did not find token in cache, requesting a new one");
|
||||||
|
}
|
||||||
|
|
||||||
_logger.LogTrace("GetOrUpdate: Getting new token");
|
_logger.LogTrace("GetOrUpdate: Getting new token");
|
||||||
return await GetNewToken(renewal, ct).ConfigureAwait(false);
|
return await GetNewToken(renewal, ct).ConfigureAwait(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue