You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Github apps token should be automatically refreshed #941
GitHubgh = newGitHubBuilder().withJwtToken(jwtToken).build();
GHAppInstallationinstallation = gh.getApp().getInstallationByOrganization("myorg");
GHAppInstallationTokenghAppInstallationToken = installation.createToken().create();
// At this point, ghAppInstallationToken should be valid to authenticate as an app// installation for a given organization. The problem is that it will eventually expire// in ~1hourreturnnewGitHubBuilder()
.withAppInstallationToken(ghAppInstallationToken.getToken())
.withJwtToken(jwtToken)
.withConnector(connector)
.build();
The problem with this is that the token is only valid for a while (1 hour in my tests),
and we would need to update it depending on the expiration time that can
be obtained in:
ghAppInstallationToken.getExpiresAt();
To Reproduce
Create a GitHub application, and perform an installation. Obtain the application installation token,
and use it. Approximately 1 hour later (for my manual tests) the token will expire and it will be
no longer valid.
Expected behavior
Once the GitHub builder /GitHub object is configured with a valid token, it should
automatically refresh the Token. Alternatively, a refresh mechanism should be provided
to manually refresh credentials.
Discussion
Should the library provide a way of manually refreshing the Token, or instead automatically refresh it?
I can take care of this once we achieve some basic points of what would be the ideal outcome.
@MarcosCela
Automatic refresh would be nice for most users. This could be done similar to RateLimitCheckers. Instead of accepting a jwtToken we could accept a CredentialProvider. Before each call to the server, the GitHubClient would ask the provider for a token, and provider would provide a current token, updating as needed.
Activity
bitwiseman commentedon Sep 21, 2020
@MarcosCela
Automatic refresh would be nice for most users. This could be done similar to
RateLimitCheckers. Instead of accepting ajwtTokenwe could accept aCredentialProvider. Before each call to the server, theGitHubClientwould ask the provider for a token, and provider would provide a current token, updating as needed.The manual update case could be supported by having
CredentialProviderhave a publicrefresh()method that would let the caller force a refresh. Maybe also an overloadrefresh(TimeSpan)to allow refreshing if the token is older than a specific age. See https://github.com/bitwiseman/github-branch-source-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentials.java and jenkinsci/github-branch-source-plugin#326 for some ideas/starting points.I look forward to seeing you PR. Ping if you have any questions.
MarcosCela commentedon Sep 24, 2020
Officially started working on this, will be opening a draft PR as soon as it makes sense to review anything!
bitwiseman commentedon Feb 9, 2021
Published in v1.122. Congrats and thanks, @MarcosCela !
Already being used by the Jenkins github-branch-source-plugin.
MarcosCela commentedon Feb 9, 2021
Thank you too for your valuable input and support on the issue, we have also been using this and no problems have been found (yet :p).