Skip to content

Commit cb6b0eb

Browse files
committed
Adds an early token renewal to avoid possibility of token being valid at time of check, but invalid by the time an actual call is made less than a second later
1 parent 83e6c7f commit cb6b0eb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/I8Beef.Ecobee/Client.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ await _tokenReadLock.WaitAsync()
190190
throw new NullReferenceException("Auth token storage delegate failed to provide token.");
191191
}
192192

193-
if (DateTime.Compare(DateTime.Now, storedAuthToken.TokenExpiration) >= 0)
193+
// If token expires within 30 seconds, renew to avoid possible subsecond expiration
194+
if (DateTime.Compare(DateTime.Now.AddSeconds(30), storedAuthToken.TokenExpiration) >= 0)
194195
{
195196
var requestMessage = new HttpRequestMessage(HttpMethod.Post, _baseUri + "token?grant_type=refresh_token&refresh_token=" + storedAuthToken.RefreshToken + "&client_id=" + _appKey);
196197
requestMessage.Headers.ExpectContinue = false;

0 commit comments

Comments
 (0)