Skip to content
Snippets Groups Projects

fix: Add skew time to Drupal token refresh

1 file
+ 7
1
Compare changes
  • Side-by-side
  • Inline
@@ -38,6 +38,8 @@ import com.github.scribejava.core.oauth.OAuth20Service;
public class DefaultDrupalTokenService implements DrupalTokenService {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDrupalTokenService.class);
private static final long MINUTE_IN_MILLIS = 60000;
@Inject
OAuth2SecurityConfig config;
@@ -64,7 +66,7 @@ public class DefaultDrupalTokenService implements DrupalTokenService {
// lock on the class instance to stop multiple threads from requesting new
// tokens at the same time
synchronized (this) {
if (accessToken == null || System.currentTimeMillis() >= expirationTime) {
if (accessToken == null || isExpiredOrExpiresSoon(expirationTime)) {
// clear access token
this.accessToken = null;
try {
@@ -86,4 +88,8 @@ public class DefaultDrupalTokenService implements DrupalTokenService {
}
return accessToken;
}
private boolean isExpiredOrExpiresSoon(long time) {
return System.currentTimeMillis() >= time || (time - System.currentTimeMillis() <= MINUTE_IN_MILLIS);
}
}
Loading