I have a client that connects to SignalR. While reconnecting, it uses an old JWT token that has old expiry and continues to throw this error- IDX10223: Lifetime validation failed. The token is expired. ValidTo (UTC): ’02/18/2024 14:42:35′, Current time (UTC): ’04/25/2024 04:31:28′. The same old token is appearing for different instances of same application that tries to connect. But from my system, I dont see that issue. What might be the reason behind that ?
I have gone through the SignalR connect and token fetch procedure. The token is working for other kinds of tasks but fails for this one only. The SignalR build procedure is as follows-
using (LogContext.PushProperty(LogContextHelper.CustomProperties.CorrelationId, correlationId))
using (LogContext.PushProperty(LogContextHelper.CustomProperties.TenantId, tenantId))
using (LogContext.PushProperty(LogContextHelper.CustomProperties.InstanceId, instanceId))
{
_logger.Log("Connecting to hub....", EventLevel.LogAlways);
IRetryPolicy retryPolicy = _hubConnectionRetryPolicy.GetRetryIndefinitePolicy();
_hubConnection = new HubConnectionBuilder()
.WithUrl(_settings.OHSManagementServiceUrl, options =>
{
options.Transports = HttpTransportType.ServerSentEvents;
options.AccessTokenProvider = () =>
{
return Task.FromResult(FetchAccessToken().GetAwaiter().GetResult().Token);
};
})
.WithAutomaticReconnect(retryPolicy)
.Build();
_hubConnection.StartAsync().ContinueWith(t =>
{
if (!t.IsFaulted)
{
if (_hubConnection.State == HubConnectionState.Connected)
{
_logger.Log($"Connected to hub: Connection Id: {_hubConnection.ConnectionId}", EventLevel.LogAlways);
SendClientInfoToServer().GetAwaiter().GetResult();
}
else
{
_logger.Log("The Hub Connection state is not Connected.", EventLevel.Error);
}
}
else
{
_logger.LogException(t.Exception);
}
}).Wait();