From 621f43c5cdad377855967b0b752a1e369d21963f Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 30 May 2019 23:06:02 -0400 Subject: [PATCH] fix token refresh logic --- .../Services/Implementations/BaseIdentityClientService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Core/Services/Implementations/BaseIdentityClientService.cs b/src/Core/Services/Implementations/BaseIdentityClientService.cs index 9a6da0060..2859ef45e 100644 --- a/src/Core/Services/Implementations/BaseIdentityClientService.cs +++ b/src/Core/Services/Implementations/BaseIdentityClientService.cs @@ -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()); - return DateTime.UtcNow < expiration; + return DateTime.UtcNow.AddMinutes(-1 * minutes) > expiration; } protected JObject DecodeToken()