aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-12-25 16:44:01 +0300
committerGravatar Vitaly Takmazov2019-12-25 16:44:01 +0300
commit78ee6cf0ec2ab93ad322dd2c6137b68f8e1de34b (patch)
tree5ad8b38a5f33e62d69a8edbb9b1c951bf9347918 /src
parentdf812aa75aac92ff4685dcf052b9ac4ed8d12fe6 (diff)
AppleClientSecretGenerator does not depend on Spring
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java18
-rw-r--r--src/main/java/com/github/scribejava/apis/AppleSignInApi.java1
-rw-r--r--src/main/java/com/juick/server/configuration/SignInWithAppleConfig.java2
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java2
4 files changed, 12 insertions, 11 deletions
diff --git a/src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java b/src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java
index f8e10d97..f3406182 100644
--- a/src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java
+++ b/src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java
@@ -19,18 +19,20 @@ package com.github.scribejava.apis;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
-import org.apache.commons.io.IOUtils;
import java.io.IOException;
-import java.io.InputStream;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.security.Key;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.spec.EncodedKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
-import java.time.*;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
import java.util.Base64;
import java.util.Date;
@@ -41,16 +43,16 @@ public class AppleClientSecretGenerator {
private final Key signingKey;
- private final String pemData;
+ private final byte[] pemData;
- public AppleClientSecretGenerator(final String subject, final String teamId, final String keyId, final InputStream keyData)
+ public AppleClientSecretGenerator(final String subject, final String teamId, final String keyId, final Path keyFile)
throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
this.subject = subject;
this.keyId = keyId;
this.teamId = teamId;
- this.pemData = IOUtils.toString(keyData, StandardCharsets.UTF_8);
- String p8encodedData = getPemData()
+ this.pemData = Files.readAllBytes(keyFile);
+ String p8encodedData = new String(getPemData(), StandardCharsets.UTF_8)
.replace(
"-----BEGIN PRIVATE KEY-----\n", "")
.replace("\n", "")
@@ -85,7 +87,7 @@ public class AppleClientSecretGenerator {
return subject;
}
- public String getPemData() {
+ public byte[] getPemData() {
return pemData;
}
}
diff --git a/src/main/java/com/github/scribejava/apis/AppleSignInApi.java b/src/main/java/com/github/scribejava/apis/AppleSignInApi.java
index 14b7f0e6..7d960d35 100644
--- a/src/main/java/com/github/scribejava/apis/AppleSignInApi.java
+++ b/src/main/java/com/github/scribejava/apis/AppleSignInApi.java
@@ -18,7 +18,6 @@
package com.github.scribejava.apis;
import com.github.scribejava.core.builder.api.DefaultApi20;
-import com.github.scribejava.core.model.OAuth2AccessToken;
import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSAlgorithm;
diff --git a/src/main/java/com/juick/server/configuration/SignInWithAppleConfig.java b/src/main/java/com/juick/server/configuration/SignInWithAppleConfig.java
index b55ba391..310c5899 100644
--- a/src/main/java/com/juick/server/configuration/SignInWithAppleConfig.java
+++ b/src/main/java/com/juick/server/configuration/SignInWithAppleConfig.java
@@ -40,6 +40,6 @@ public class SignInWithAppleConfig {
@Bean
public AppleClientSecretGenerator clientSecretGenerator() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException {
- return new AppleClientSecretGenerator(appId, teamId, keyId, keyPath.getInputStream());
+ return new AppleClientSecretGenerator(appId, teamId, keyId, keyPath.getFile().toPath());
}
}
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 30f2a025..a8fc4563 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -2339,7 +2339,7 @@ public class ServerTests {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
JcaPEMKeyConverter pemConverter = new JcaPEMKeyConverter();
pemConverter.setProvider("BC");
- final Reader pemReader = new StringReader(clientSecretGenerator.getPemData());
+ final Reader pemReader = new InputStreamReader(new ByteArrayInputStream(clientSecretGenerator.getPemData()));
final PEMParser parser = new PEMParser(pemReader);
PrivateKey privateKey;
Object pemObj = parser.readObject();