GitHub app: isCredentialValid doesn't work
See original GitHub issueI’m trying to add GitHub app support to the github-branch-source Jenkins plugin, I’m facing 2 main issues,
-
From the GitHub class I can’t tell if I’m using a GitHub app
-
isCredentialValid / getMyself don’t work
org.kohsuke.github.GHFileNotFoundException: {"message":"Resource not accessible by integration","documentation_url":"https://developer.github.com/v3/users/#get-the-authenticated-user"}
Ideally isCredentialValid
would do something else when using a GitHub
app and not sure if there’s anything that can be done about getMyself
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
GitHub app: isCredentialValid doesn't work · Issue #582
i.e. the UI tries to check a credential is valid, and the method isCredentialValid doesn't work if you're using a GitHub app.
Read more >Authentication Failed (with valid credentials, CLI is working fine)
I can use the app for about a month or so, then suddenly (seemingly randomly) it will refuse to authenticate, even if i...
Read more >Authentication Failure with GitHub Desktop · Issue #8860
reinstalled Github Desktop; signed in using the native app authentication (including 2FA); attempted to clone a repo. It still doesn't work.
Read more >Authenticating to GitHub - GitHub Docs
This error means that there is an issue with your stored account credentials. To troubleshoot, sign out of your account on GitHub Desktop...
Read more >Troubleshooting OAuth App access token request errors
To solve this error, make sure you have the correct credentials for your OAuth App. Double check the client_id and client_secret to make...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hmmm got it now. Thanks for the link.
I see what you are trying to do but the
GitHub.isCredentialValid()
isn’t applicable to Github App as it make a request to/user
and this isn’t a Github App-ready endpoint. (this would’ve worked on the “old” oauth apps though)TBH, the
/user
is really a swiss knife that has been used to verify whether or not the credentials provided would work…but I don’t think there isn’t an equivalent one for GIthub Apps as their permissions will vary a lot given the fine-grained permissions users can set.The closest you can get to it (for now) authenticated as a Github App (whether via JWT or App Installation Token) would be to implement in your source code the same try/catch mechanism used on
GitHub.isCredentialValid()
but usingGithub.getRateLimit()
as this seems to be an available endpoint for Apps@bitwiseman let me pick your brains on this one. Do you think we should make
GitHub.isCredentialValid()
call under-the-hood different GitHub endpoints depending on the credentials used or is it the case that we simply document that developers should only use this method when using oauth apps or username/pass credentials?Hi @timja
Both points have been discussed on #570. I really suggest you read it (I know it’s bit lengthy, but that’s going to answer most questions you may have)
The
GitHub
class should be diligently created using the appropriate credentials/permissions for what you need… which means that if you get an instance of theGitHub
class usingnew GitHubBuilder().withJwtToken(jwtToken).build()
then you know you are ‘using a Github App’.This was also discussed on #570 and I proposed to @bitwiseman that a convenience/cosmetic method was created to make it easier for developers to know how to make heads or tails of the multiple ways of authenticating to GIthub with this library.
Basically, the summarised version of why you are facing it would be:
getMyself
method which for App Installation token flow isn’t applicable as/user
isn’t a GitHub App-ready endpoint. Since we may have users relying on this behaviour, we won’t change it until we are ready to bump to the 2.x version of this sdk.How to address it:
Before the #583 PR is approved:
After the #583 PR is approved:
Hope this helps