spotify/github-java-client

[Bug] Expired token unable to refresh

bguedel opened this issue · 3 comments

2021-07-29 19:44:31.615  INFO [my-bot,1efb3e9c675e3506,1efb3e9c675e3506] 1 --- [nio-8080-exec-7] c.s.github.v3.clients.GitHubClient       : Github token for installation 1234 is either expired or null. Trying to get a new one.
--
2021-07-29 19:44:31.615  INFO [my-bot,1efb3e9c675e3506,1efb3e9c675e3506] 1 --- [nio-8080-exec-7] c.s.github.v3.clients.GitHubClient       : Got JWT Token. Now getting Github access_token for installation 1234
2021-07-29 19:44:31.619 ERROR [my-bot,a1558e2c87f905cd,a1558e2c87f905cd] 1 --- [nio-8080-exec-5] c.comp.path.WebhookErrorHandler  : error processing request: (Could not generate access token for github app)
java.lang.RuntimeException: Could not generate access token for github app
...
Caused by: java.lang.Exception: Got non-2xx status 401 when getting an access token from GitHub: Unauthorized
    at com.spotify.github.v3.clients.GitHubClient.generateInstallationToken(GitHubClient.java:607) ~[github-client-0.0.25.jar:0.0.25]
    at com.spotify.github.v3.clients.GitHubClient.getInstallationToken(GitHubClient.java:581) ~[github-client-0.0.25.jar:0.0.25]
    at com.spotify.github.v3.clients.GitHubClient.getAuthorizationHeader(GitHubClient.java:560) ~[github-client-0.0.25.jar:0.0.25]

on restart of the application; everything works fine.

Ill keep an eye on this. I think #70 might have fixed this? This error often happens after the connection leaked issue happens.

#70 did NOT fix this. Still seeing it.

doesnt happen on every request. so dont really know what it could be.

Here are my thoughts

https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-a-github-app

# Generate the JWT
payload = {
  # issued at time, 60 seconds in the past to allow for clock drift
  iat: Time.now.to_i - 60,

however in this code we see

so i am wondering if the fix is simply to remove 60 seconds.