mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-11 15:50:17 +00:00
Compare commits
6 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb381dfa06 | ||
|
|
80124e3b85 | ||
|
|
7aae27e36f | ||
|
|
b212956fbb | ||
|
|
d033355e84 | ||
|
|
59d7a117d0 |
4
pom.xml
4
pom.xml
@@ -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>
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user