1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

fix token refresh logic

This commit is contained in:
Kyle Spearrin 2019-05-30 23:06:02 -04:00
parent 35804e10cf
commit 621f43c5cd

View File

@ -84,7 +84,7 @@ namespace Bit.Core.Services
}
_nextAuthAttempt = null;
if(!string.IsNullOrWhiteSpace(AccessToken) && !TokenExpired())
if(!string.IsNullOrWhiteSpace(AccessToken) && !TokenNeedsRefresh())
{
return true;
}
@ -151,7 +151,7 @@ namespace Bit.Core.Services
}
}
protected bool TokenExpired()
protected bool TokenNeedsRefresh(int minutes = 5)
{
var decoded = DecodeToken();
var exp = decoded?["exp"];
@ -161,7 +161,7 @@ namespace Bit.Core.Services
}
var expiration = CoreHelpers.FromEpocSeconds(exp.Value<long>());
return DateTime.UtcNow < expiration;
return DateTime.UtcNow.AddMinutes(-1 * minutes) > expiration;
}
protected JObject DecodeToken()