private void refreshIfRequired()

in core/src/main/java/com/google/cloud/sql/core/DefaultAccessTokenSupplier.java [143:158]


  private void refreshIfRequired(GoogleCredentials credentials) throws IOException {
    // if the token does not exist, or if the token expires in less than 4 minutes, refresh it.
    if (credentials.getAccessToken() == null) {
      logger.debug("Current IAM AuthN Token is not set. Refreshing the token.");
      credentials.refresh();
    } else if (credentials.getAccessToken().getExpirationTime() != null
        && credentials
            .getAccessToken()
            .getExpirationTime()
            .toInstant()
            .minus(DEFAULT_REFRESH_BUFFER)
            .isBefore(Instant.now())) {
      logger.debug("Current IAM AuthN Token expires in less than 4 minutes. Refreshing the token.");
      credentials.refresh();
    }
  }