forked from hub4j/github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubappappinsttokenauth.apt
More file actions
32 lines (23 loc) · 1.22 KB
/
Copy pathgithubappappinsttokenauth.apt
File metadata and controls
32 lines (23 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Authenticating as an installation
In order to authenticate to GitHub as an installation of your GitHub App, you must use the App Installation Token
authentication mechanism. This can be achieved with by creating a <<<GitHub>>> instance like this:
+-----+
GitHub githubAuthAsInst = new GitHubBuilder()
.withAppInstallationToken(appInstallationToken.getToken())
.build();
+-----+
How do I create an App Installation Token?
Assuming that you followed the {{{/githubappjwtauth.html} GitHub App Authentication via JWT token guide}} then you
can create the App Installation Token like this:
+-----+
String jwtToken = createJWT("44435", 600000); //sdk-github-api-app-test
GitHub gitHubApp = new GitHubBuilder().withJwtToken(jwtToken).build();
GHAppInstallation appInstallation = gitHubApp.getApp().getInstallationById(111111); // Installation Id
Map<String, GHPermissionType> permissions = new HashMap<>();
permissions.put("pull_requests", GHPermissionType.WRITE);
GHAppInstallationToken appInstallationToken = appInstallation
.createToken(permissions)
.create();
// Or
GHAppInstallationToken appInstallationToken = appInstallation.createToken().create();
+-----+