-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from Modagbul/fix/auth
refactor: 애플 키 가져오는 함수 confiuration으로 관리
- Loading branch information
Showing
3 changed files
with
46 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,3 +51,4 @@ data.sql | |
*.html | ||
|
||
firebase-key.json | ||
apple-key.p8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/com/moing/backend/global/config/sns/AppleConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.moing.backend.global.config.sns; | ||
|
||
import com.moing.backend.global.config.fcm.exception.InitializeException; | ||
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; | ||
import org.bouncycastle.openssl.PEMParser; | ||
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.util.FileCopyUtils; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.io.StringReader; | ||
import java.security.PrivateKey; | ||
|
||
@Configuration | ||
public class AppleConfig { | ||
|
||
|
||
@Value("${oauth2.apple.keyPath}") | ||
private String keyPath; | ||
|
||
@Bean | ||
public PrivateKey applePrivateKey(){ | ||
try{ | ||
ClassPathResource resource = new ClassPathResource(keyPath); | ||
String privateKeyString = new String(FileCopyUtils.copyToByteArray(resource.getInputStream())); | ||
Reader reader = new StringReader(privateKeyString); | ||
PEMParser pemParser = new PEMParser(reader); | ||
JcaPEMKeyConverter converter = new JcaPEMKeyConverter(); | ||
PrivateKeyInfo object = (PrivateKeyInfo) pemParser.readObject(); | ||
return converter.getPrivateKey(object); | ||
} catch (FileNotFoundException e) { | ||
throw new IllegalStateException("파일을 찾을 수 없습니다." + e.getMessage()); | ||
} catch (IOException e) { | ||
throw new InitializeException(); | ||
} | ||
} | ||
} |