Skip to content

Commit

Permalink
fix: only refresh if the token has expired.
Browse files Browse the repository at this point in the history
  • Loading branch information
hessjcg committed Jun 14, 2023
1 parent a53e83d commit 0285e3e
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,17 @@ private Certificate fetchEphemeralCertificate(
* @throws IOException when the credentials.refresh() has failed 3 times
*/
private void refreshWithRetry(OAuth2Credentials credentials) throws IOException {

// if the access token has not expired, do not attempt to refresh
AccessToken token = credentials.getAccessToken();
if( token == null || token.getExpirationTime().toInstant().isAfter(Instant.now()) ) {
return;
}

Callable<OAuth2Credentials> refresh =
() -> {
try {
credentials.refresh();
credentials.refreshIfExpired();
} catch (IllegalStateException e) {
throw new IllegalStateException(
String.format(
Expand Down

0 comments on commit 0285e3e

Please sign in to comment.