diff options
Diffstat (limited to 'src/main')
3 files changed, 20 insertions, 8 deletions
diff --git a/src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java b/src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java index 3af6bc7a..f8e10d97 100644 --- a/src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java +++ b/src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java @@ -19,10 +19,10 @@ package com.github.scribejava.apis; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; -import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; -import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.security.Key; import java.security.KeyFactory; @@ -41,14 +41,16 @@ public class AppleClientSecretGenerator { private final Key signingKey; - public AppleClientSecretGenerator(final String subject, final String teamId, final String keyId, final String keyPath) + private final String pemData; + + public AppleClientSecretGenerator(final String subject, final String teamId, final String keyId, final InputStream keyData) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { this.subject = subject; this.keyId = keyId; this.teamId = teamId; - String pemData = FileUtils.readFileToString(new File(keyPath), StandardCharsets.UTF_8); - String p8encodedData = pemData + this.pemData = IOUtils.toString(keyData, StandardCharsets.UTF_8); + String p8encodedData = getPemData() .replace( "-----BEGIN PRIVATE KEY-----\n", "") .replace("\n", "") @@ -82,4 +84,8 @@ public class AppleClientSecretGenerator { public String getApplicationId() { return subject; } + + public String getPemData() { + return pemData; + } } diff --git a/src/main/java/com/juick/server/configuration/SignInWithAppleConfig.java b/src/main/java/com/juick/server/configuration/SignInWithAppleConfig.java index f736e673..b55ba391 100644 --- a/src/main/java/com/juick/server/configuration/SignInWithAppleConfig.java +++ b/src/main/java/com/juick/server/configuration/SignInWithAppleConfig.java @@ -21,6 +21,7 @@ import com.github.scribejava.apis.AppleClientSecretGenerator; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; import java.io.IOException; import java.security.NoSuchAlgorithmException; @@ -34,11 +35,11 @@ public class SignInWithAppleConfig { private String teamId; @Value("${apple_key_id:keyid}") private String keyId; - @Value("${apple_key_path:AuthKey.p8}") - private String keyPath; + @Value("${apple_key_path:classpath:testkey.p8}") + private Resource keyPath; @Bean public AppleClientSecretGenerator clientSecretGenerator() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException { - return new AppleClientSecretGenerator(appId, teamId, keyId, keyPath); + return new AppleClientSecretGenerator(appId, teamId, keyId, keyPath.getInputStream()); } } diff --git a/src/main/resources/testkey.p8 b/src/main/resources/testkey.p8 new file mode 100644 index 00000000..1e5d0f98 --- /dev/null +++ b/src/main/resources/testkey.p8 @@ -0,0 +1,5 @@ +-----BEGIN PRIVATE KEY----- +MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg72/yb71r7uVirjpf +vjAPZ5aUR0si2c1yH6Lt/NlhWcWhRANCAAQydvu0D1+DTVM0/U0rbxHfkG3AswYw +hZZk58QvxSbxoBcmoLLMKAuaNBCVg+4I0xKvCfB0dkIjRATNpveON8y3 +-----END PRIVATE KEY----- |