question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GitHub app: isCredentialValid doesn't work

See original GitHub issue

I’m trying to add GitHub app support to the github-branch-source Jenkins plugin, I’m facing 2 main issues,

  1. From the GitHub class I can’t tell if I’m using a GitHub app

  2. 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

cc @PauloMigAlmeida

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
PauloMigAlmeidacommented, Oct 30, 2019

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 using Github.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?

1reaction
PauloMigAlmeidacommented, Oct 30, 2019

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)

From the GitHub class I can’t tell if I’m using a GitHub app

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 the GitHub class using new GitHubBuilder().withJwtToken(jwtToken).build() then you know you are ‘using a Github App’.

isValidCredential / 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"}

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:

  1. App Installation Token is an OAuth token (so is personal access tokens and oauth apps)
  2. This library defined the behaviour (many years ago) that if you pass an oauth token with no login then it tries to call the 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:

GitHub githubAuthAsInst = new GitHubBuilder()
                    .withOAuthToken(appInstallationToken.getToken(), "")
                    .build();

After the #583 PR is approved:

GitHub githubAuthAsInst = new GitHubBuilder()
                    .withAppInstallationToken(appInstallationToken.getToken())
                    .build();

Hope this helps

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found