Skip to content

Commit

Permalink
Adds an early token renewal to avoid possibility of token being valid…
Browse files Browse the repository at this point in the history
… at time of check, but invalid by the time an actual call is made less than a second later
  • Loading branch information
i8beef committed Feb 16, 2022
1 parent 83e6c7f commit cb6b0eb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/I8Beef.Ecobee/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ await _tokenReadLock.WaitAsync()
throw new NullReferenceException("Auth token storage delegate failed to provide token.");
}

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

0 comments on commit cb6b0eb

Please sign in to comment.