Merge pull request #2970 from octo/ff/oauth
authorPavel Rochnyak <pavel2000@ngs.ru>
Thu, 25 Oct 2018 05:05:29 +0000 (12:05 +0700)
committerGitHub <noreply@github.com>
Thu, 25 Oct 2018 05:05:29 +0000 (12:05 +0700)
src/utils_oauth.c: Renew OAuth tokens 30 seconds before they expire.

src/utils_oauth.c

index 35533be..d804b51 100644 (file)
@@ -425,9 +425,10 @@ static int new_token(oauth_t *auth) /* {{{ */
 
 static int renew_token(oauth_t *auth) /* {{{ */
 {
-  /* TODO(octo): Make sure that we get a new token 60 seconds or so before the
-   * old one expires. */
-  if (auth->valid_until > cdtime())
+  /* Renew OAuth token 30 seconds *before* it expires. */
+  cdtime_t const slack = TIME_T_TO_CDTIME_T(30);
+
+  if (auth->valid_until > (cdtime() + slack))
     return 0;
 
   return new_token(auth);