Skip to content

Commit 80348ff

Browse files
authored
Increase margin for installation token expiration check (#108)
1 parent 0203cfd commit 80348ff

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/com/spotify/github/v3/clients/GitHubClient.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -66,6 +66,8 @@
6666
*/
6767
public class GitHubClient {
6868

69+
private static final int EXPIRY_MARGIN_IN_MINUTES = 3;
70+
6971
private Tracer tracer = NoopTracer.INSTANCE;
7072

7173
static final Consumer<Response> IGNORE_RESPONSE_CONSUMER = (response) -> {
@@ -686,7 +688,8 @@ private String getInstallationToken(final String jwtToken, final int installatio
686688
}
687689

688690
private boolean isExpired(final AccessToken token) {
689-
return token.expiresAt().isBefore(ZonedDateTime.now().plusMinutes(-1));
691+
// Subtract a few minutes to avoid making calls with an expired token due to clock differences
692+
return token.expiresAt().isBefore(ZonedDateTime.now().minusMinutes(EXPIRY_MARGIN_IN_MINUTES));
690693
}
691694

692695
private AccessToken generateInstallationToken(final String jwtToken, final int installationId)

0 commit comments

Comments
 (0)