Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

401 when trying to extract GHUser#type #1816

Open
Haarolean opened this issue Mar 14, 2024 · 3 comments
Open

401 when trying to extract GHUser#type #1816

Haarolean opened this issue Mar 14, 2024 · 3 comments
Labels

Comments

@Haarolean
Copy link
Contributor

Hi, a code like this

new GitHubBuilder()
        .withJwtToken("token")
        .build()
        .getApp()
        .getInstallationById(githubInstallationId)
        .getAccount()
        .getType()

leads to 401:

Caused by: org.kohsuke.github.HttpException: {"message":"Bad credentials","documentation_url":"https://docs.github.com/rest"}
	at org.kohsuke.github.GitHubConnectorResponseErrorHandler$1.onError(GitHubConnectorResponseErrorHandler.java:62) ~[github-api-unbridged-1.318.jar:na]

There are a few issues here:

  1. The field is already initialized as "Organization" after calling getAccount(), so populating here is not necessary, perhaps.
  2. installation.getAccount().getUrl() returns https://api.github.com/users/<ORGANIZATION_LOGIN>, which perhaps is invalid, because it's an organization, not a user.
@Haarolean
Copy link
Contributor Author

Haarolean commented Mar 14, 2024

Unfortunately, I couldn't find a way to work around this by determining installation owner's account type, please let me know if there's something I missed

UPD: Found a workaround:

ghInstallation.getRoot().setConnector(HttpConnector.OFFLINE);
ghInstallation.getAccount().getType();

@bitwiseman
Copy link
Member

Here's the problem:

public String getType() throws IOException {
populate();
return type;

populate() should only be called if type is null.

@bitwiseman bitwiseman added the bug label Mar 15, 2024
@Haarolean
Copy link
Contributor Author

@bitwiseman got it. How should we solve this taking into consideration the fact that there are multiple fields like this? Should we track the "populated = true/false" flag for an entity or something else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants