Compare commits

..

6 Commits

Author SHA1 Message Date
Liam Newman
cb381dfa06 [maven-release-plugin] prepare release github-api-1.122 2021-01-14 20:13:57 -08:00
Liam Newman
80124e3b85 Merge pull request #1021 from bitwiseman/jwt-string
Allow JWT from string
2021-01-14 20:09:21 -08:00
Liam Newman
7aae27e36f Allow JWT from string 2021-01-14 14:25:51 -08:00
Liam Newman
b212956fbb [maven-release-plugin] prepare for next development iteration 2021-01-14 13:19:41 -08:00
Liam Newman
d033355e84 [maven-release-plugin] prepare release github-api-1.121 2021-01-14 13:19:31 -08:00
Liam Newman
59d7a117d0 [maven-release-plugin] prepare for next development iteration 2021-01-14 10:51:52 -08:00
3 changed files with 15 additions and 18 deletions

View File

@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.120</version>
<version>1.122</version>
<name>GitHub API for Java</name>
<url>https://github-api.kohsuke.org/</url>
<description>GitHub API for Java</description>
@@ -11,7 +11,7 @@
<connection>scm:git:git@github.com/hub4j/${project.artifactId}.git</connection>
<developerConnection>scm:git:ssh://git@github.com/hub4j/${project.artifactId}.git</developerConnection>
<url>https://github.com/hub4j/github-api/</url>
<tag>github-api-1.120</tag>
<tag>github-api-1.122</tag>
</scm>
<distributionManagement>

View File

@@ -42,11 +42,15 @@ public class JWTTokenProvider implements AuthorizationProvider {
private final String applicationId;
public JWTTokenProvider(String applicationId, File keyFile) throws GeneralSecurityException, IOException {
this(applicationId, loadPrivateKey(keyFile.toPath()));
this(applicationId, keyFile.toPath());
}
public JWTTokenProvider(String applicationId, Path keyPath) throws GeneralSecurityException, IOException {
this(applicationId, loadPrivateKey(keyPath));
this(applicationId, new String(Files.readAllBytes(keyPath), StandardCharsets.UTF_8));
}
public JWTTokenProvider(String applicationId, String keyString) throws GeneralSecurityException {
this(applicationId, getPrivateKeyFromString(keyString));
}
public JWTTokenProvider(String applicationId, PrivateKey privateKey) {
@@ -64,18 +68,6 @@ public class JWTTokenProvider implements AuthorizationProvider {
}
}
/**
* add dependencies for a jwt suite You can generate a key to load in this method with:
*
* <pre>
* openssl pkcs8 -topk8 -inform PEM -outform DER -in ~/github-api-app.private-key.pem -out ~/github-api-app.private-key.der -nocrypt
* </pre>
*/
private static PrivateKey loadPrivateKey(Path keyPath) throws GeneralSecurityException, IOException {
String keyString = new String(Files.readAllBytes(keyPath), StandardCharsets.UTF_8);
return getPrivateKeyFromString(keyString);
}
/**
* Convert a PKCS#8 formatted private key in string format into a java PrivateKey
*

View File

@@ -7,6 +7,8 @@ import org.kohsuke.github.extras.authorization.JWTTokenProvider;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.PrivateKey;
@@ -34,9 +36,12 @@ public class AbstractGHAppInstallationTest extends AbstractGitHubWireMockTest {
JWT_PROVIDER_1 = new JWTTokenProvider(TEST_APP_ID_1,
new File(this.getClass().getResource(PRIVATE_KEY_FILE_APP_1).getFile()));
JWT_PROVIDER_2 = new JWTTokenProvider(TEST_APP_ID_2,
new File(this.getClass().getResource(PRIVATE_KEY_FILE_APP_2).getFile()));
new File(this.getClass().getResource(PRIVATE_KEY_FILE_APP_2).getFile()).toPath());
JWT_PROVIDER_3 = new JWTTokenProvider(TEST_APP_ID_3,
new File(this.getClass().getResource(PRIVATE_KEY_FILE_APP_3).getFile()));
new String(
Files.readAllBytes(
new File(this.getClass().getResource(PRIVATE_KEY_FILE_APP_3).getFile()).toPath()),
StandardCharsets.UTF_8));
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException("These should never fail", e);
}