You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>In order to authenticate to GitHub as a GitHub App, you must use the JWT token authentication mechanism. This can be easily achieved with this library by obtaining a <code>GitHub</code> instance like this:</p>
<pre><code>GitHub github = new GitHubBuilder().withJwtToken("my_jwt_token").build();</code></pre>
<p>Authenticating as a GitHub App lets you do a couple of things:</p>
<ul>
<li>You can retrieve high-level management information about your GitHub App.</li>
<li>You can request access tokens for an installation of the app.</li></ul></section><section><aid="Where_do_I_get_the_JWT_token_from.3F"></a>
<h1>Where do I get the JWT token from?</h1>
<p>To generate the JWT token required to authenticate as a GitHub app you have to:</p>
<ul>
<li>Sign the JWT token using the private key you configured on your GitHub app as described <aclass="externalLink" href="https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#generating-a-private-key">here</a></li>
<li>Encode it using the <code>RS256</code> algorithm.</li></ul>
<p>GitHub checks that the request is authenticated by verifying the token with the app's stored public key.</p></section><section><aid="Converting_the_private_key_into_a_Java_friendly_format"></a>
<h1>Converting the private key into a Java friendly format</h1>
<p><b>Note:</b> GitHub let's you download the GitHub App private key in the <code>PEM</code> format which isn't natively supported by the JVM unless you leverage a third-party library such as <aclass="externalLink" href="https://www.bouncycastle.org/">BouncyCastle</a>. In this guide we will convert it to <code>DER</code> using the <code>openssl</code> utility.</p>
<p>Once you have the private key converted to the <code>DER</code> format, you will need 2 more things before you are able to generate JWT tokens:</p>
<p><b>GitHub App Id:</b></p>
<p>You can obtain the GitHub App Id from your app settings webpage as shown below:</p><figure><imgsrc="images/Github_App_Id.png" /><figcaption>Github_App_Id</figcaption></figure>
<p><b>JWT library:</b></p>
<p>In order to generate the JWT, you will have to likely use a JWT library. In this guide we will use <aclass="externalLink" href="https://github.com/jwtk/jjwt">jjwt</a> to that matter.</p>
<p>Having said that, add on your <code>pom.xml</code> the following dependencies:</p>
<pre><code><dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.10.5</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.10.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.10.5</version>
<scope>runtime</scope>
</dependency></code></pre>
<p>Now we have everything we need so let's generate the JWT token:</p>