Skip to content

Some "GHAppInstallation" methods need an installation token, not a JWT token #1082

@tginiotis-at-work

Description

@tginiotis-at-work

I can explain the oddity on lines 84-87, since I originally wrote them.

GitHub gitHub = getGitHubBuilder().withJwtToken(jwtToken)
.withEndpoint(mockGitHub.apiServer().baseUrl())
.build();
GHAppInstallation appInstallation = gitHub.getApp()
.listInstallations()
.toList()
.stream()
.filter(it -> it.getAccount().login.equals("hub4j-test-org"))
.findFirst()
.get();
// TODO: this is odd
// appInstallation
// .setRoot(getGitHubBuilder().withAppInstallationToken(appInstallation.createToken().create().getToken())
// .withEndpoint(mockGitHub.apiServer().baseUrl())
// .build());

The GitHub client constructed on line 71 is using the JWT token. Which is appropriate for e.g. retrieving a list of installations for the app and other high-level information about the App.

The tests in GHAppInstallationTest.java are using API methods that need a client authenticated as an "Installation", not an "App" though. I.e. a GitHub client needs to be constructed with the "installation token", which is separate and is retrieved using the "JWT token".

Details from the documentation:

So the commented out code did exactly that - used the client with the "JWT token" to create an "installation token" and inserted it back on the GHAppInstallation object, so further API calls would correctly use the "installation token".

I am pretty sure the live tests will fail now with that code commented out.

And I remember not finding a really nice way (without using setRoot()) of exchanging those tokens on the GHAppInstallation object, so it is probably an improvement opportunity.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions