From 49f5bc444fce953ae677cf140ae4a0175f20b760 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Sun, 25 Feb 2024 00:03:41 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20#39=20fcm=20=EC=9D=98=EC=A1=B4=EC=84=B1?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20&&=20admin=20key=20=EC=A3=BC=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fitapet-infra/.gitignore | 5 +++- fitapet-infra/build.gradle | 3 ++ .../kr/co/fitapet/infra/config/FcmConfig.java | 29 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 fitapet-infra/src/main/java/kr/co/fitapet/infra/config/FcmConfig.java diff --git a/fitapet-infra/.gitignore b/fitapet-infra/.gitignore index b63da455..82ebd219 100644 --- a/fitapet-infra/.gitignore +++ b/fitapet-infra/.gitignore @@ -39,4 +39,7 @@ bin/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store + +## firebase sdk key ### +fitapet-ios-firebase-adminsdk-ethnn-6ec10fe329.json diff --git a/fitapet-infra/build.gradle b/fitapet-infra/build.gradle index 5bcd00b7..bda83eb1 100644 --- a/fitapet-infra/build.gradle +++ b/fitapet-infra/build.gradle @@ -30,5 +30,8 @@ dependencies { implementation 'com.fasterxml.jackson.core:jackson-core:2.13.5' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.13.5' + /* Firebase */ + implementation 'com.google.firebase:firebase-admin:9.2.0' + implementation project(':fitapet-common') } \ No newline at end of file diff --git a/fitapet-infra/src/main/java/kr/co/fitapet/infra/config/FcmConfig.java b/fitapet-infra/src/main/java/kr/co/fitapet/infra/config/FcmConfig.java new file mode 100644 index 00000000..349bfb5a --- /dev/null +++ b/fitapet-infra/src/main/java/kr/co/fitapet/infra/config/FcmConfig.java @@ -0,0 +1,29 @@ +package kr.co.fitapet.infra.config; + +import com.google.auth.oauth2.GoogleCredentials; +import com.google.firebase.FirebaseApp; +import com.google.firebase.FirebaseOptions; +import com.google.firebase.messaging.FirebaseMessaging; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; + +import java.io.IOException; + +@Configuration +public class FcmConfig { + private final ClassPathResource firebaseResource = new ClassPathResource("firebase/fitapet-ios-firebase-adminsdk-ethnn-6ec10fe329.json"); + + @Bean + FirebaseApp firebaseApp() throws IOException { + FirebaseOptions option = FirebaseOptions.builder() + .setCredentials(GoogleCredentials.fromStream(firebaseResource.getInputStream())) + .build(); + return FirebaseApp.initializeApp(option); + } + + @Bean + FirebaseMessaging firebaseMessaging() throws IOException { + return FirebaseMessaging.getInstance(firebaseApp()); + } +}