From 1f7d63c0f28c694bec169995ac5169813e0edf8e Mon Sep 17 00:00:00 2001 From: Young June Park Date: Sat, 24 Dec 2022 15:30:31 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[chore]=20auth=20Key=20plist=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpaceCapsule/SpaceCapsule.xcodeproj/project.pbxproj | 4 ++++ SpaceCapsule/SpaceCapsule/AuthKey.plist | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 SpaceCapsule/SpaceCapsule/AuthKey.plist diff --git a/SpaceCapsule/SpaceCapsule.xcodeproj/project.pbxproj b/SpaceCapsule/SpaceCapsule.xcodeproj/project.pbxproj index 5d6dc39..9905783 100644 --- a/SpaceCapsule/SpaceCapsule.xcodeproj/project.pbxproj +++ b/SpaceCapsule/SpaceCapsule.xcodeproj/project.pbxproj @@ -88,6 +88,7 @@ 28419EA32941BD6400266AB6 /* FirebaseStorage in Frameworks */ = {isa = PBXBuildFile; productRef = 28419EA22941BD6400266AB6 /* FirebaseStorage */; }; 28419EA52944C8BD00266AB6 /* Data+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28419EA42944C8BD00266AB6 /* Data+.swift */; }; 28419EAE2944F59000266AB6 /* SwiftJWT in Frameworks */ = {isa = PBXBuildFile; productRef = 28419EAD2944F59000266AB6 /* SwiftJWT */; }; + 287C9BE82956D35400435EC5 /* AuthKey.plist in Resources */ = {isa = PBXBuildFile; fileRef = 287C9BE72956D35400435EC5 /* AuthKey.plist */; }; 2885AA00293B6466003E5311 /* ProfileButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2885A9FF293B6466003E5311 /* ProfileButton.swift */; }; 288A8E922923244D000229D2 /* Coordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 288A8E912923244D000229D2 /* Coordinator.swift */; }; 288A8E9B29235A6E000229D2 /* SignInView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 288A8E9A29235A6E000229D2 /* SignInView.swift */; }; @@ -267,6 +268,7 @@ 28245561293B17B100DE03A1 /* UnOpenable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnOpenable.swift; sourceTree = ""; }; 28419E5E294028DE00266AB6 /* NotificationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationManager.swift; sourceTree = ""; }; 28419EA42944C8BD00266AB6 /* Data+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+.swift"; sourceTree = ""; }; + 287C9BE72956D35400435EC5 /* AuthKey.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = AuthKey.plist; sourceTree = ""; }; 2885A9FF293B6466003E5311 /* ProfileButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileButton.swift; sourceTree = ""; }; 288A8E912923244D000229D2 /* Coordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Coordinator.swift; sourceTree = ""; }; 288A8E96292359CF000229D2 /* AuthCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthCoordinator.swift; sourceTree = ""; }; @@ -432,6 +434,7 @@ 59F567F72923BE1E00F756B2 /* SpaceCapsule.entitlements */, 4A05D0EB2924C04200A2EF50 /* GoogleService-Info.plist */, 0D6CA342292216A400E02393 /* Info.plist */, + 287C9BE72956D35400435EC5 /* AuthKey.plist */, 0D2B7AB92934594400CE34E3 /* running.gpx */, 0D6CA33D292216A400E02393 /* Assets.xcassets */, 0D6CA33F292216A400E02393 /* LaunchScreen.storyboard */, @@ -1046,6 +1049,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 287C9BE82956D35400435EC5 /* AuthKey.plist in Resources */, 599C1A2C292C9F5B00517E93 /* .swiftlint.yml in Resources */, 0D6CA341292216A400E02393 /* LaunchScreen.storyboard in Resources */, 0D6CA33E292216A400E02393 /* Assets.xcassets in Resources */, diff --git a/SpaceCapsule/SpaceCapsule/AuthKey.plist b/SpaceCapsule/SpaceCapsule/AuthKey.plist new file mode 100644 index 0000000..ce9c739 --- /dev/null +++ b/SpaceCapsule/SpaceCapsule/AuthKey.plist @@ -0,0 +1,8 @@ + + + + + AuthKey + 여기에 키 입력 + + From da166f1ec3d0d62e0a26d638ece6740ae65459e9 Mon Sep 17 00:00:00 2001 From: Young June Park Date: Sat, 24 Dec 2022 15:40:03 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[chore]=20=EB=B2=88=EB=93=A4=20extension=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20(#127)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SpaceCapsule.xcodeproj/project.pbxproj | 4 +++ .../Extensions/SpaceCapsule+Bundle.swift | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift diff --git a/SpaceCapsule/SpaceCapsule.xcodeproj/project.pbxproj b/SpaceCapsule/SpaceCapsule.xcodeproj/project.pbxproj index 9905783..2e92f46 100644 --- a/SpaceCapsule/SpaceCapsule.xcodeproj/project.pbxproj +++ b/SpaceCapsule/SpaceCapsule.xcodeproj/project.pbxproj @@ -89,6 +89,7 @@ 28419EA52944C8BD00266AB6 /* Data+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28419EA42944C8BD00266AB6 /* Data+.swift */; }; 28419EAE2944F59000266AB6 /* SwiftJWT in Frameworks */ = {isa = PBXBuildFile; productRef = 28419EAD2944F59000266AB6 /* SwiftJWT */; }; 287C9BE82956D35400435EC5 /* AuthKey.plist in Resources */ = {isa = PBXBuildFile; fileRef = 287C9BE72956D35400435EC5 /* AuthKey.plist */; }; + 287C9BEA2956D42400435EC5 /* SpaceCapsule+Bundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 287C9BE92956D42400435EC5 /* SpaceCapsule+Bundle.swift */; }; 2885AA00293B6466003E5311 /* ProfileButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2885A9FF293B6466003E5311 /* ProfileButton.swift */; }; 288A8E922923244D000229D2 /* Coordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 288A8E912923244D000229D2 /* Coordinator.swift */; }; 288A8E9B29235A6E000229D2 /* SignInView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 288A8E9A29235A6E000229D2 /* SignInView.swift */; }; @@ -269,6 +270,7 @@ 28419E5E294028DE00266AB6 /* NotificationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationManager.swift; sourceTree = ""; }; 28419EA42944C8BD00266AB6 /* Data+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+.swift"; sourceTree = ""; }; 287C9BE72956D35400435EC5 /* AuthKey.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = AuthKey.plist; sourceTree = ""; }; + 287C9BE92956D42400435EC5 /* SpaceCapsule+Bundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SpaceCapsule+Bundle.swift"; sourceTree = ""; }; 2885A9FF293B6466003E5311 /* ProfileButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileButton.swift; sourceTree = ""; }; 288A8E912923244D000229D2 /* Coordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Coordinator.swift; sourceTree = ""; }; 288A8E96292359CF000229D2 /* AuthCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthCoordinator.swift; sourceTree = ""; }; @@ -508,6 +510,7 @@ 0DD83D10292F2EC80020F15C /* UIViewController+.swift */, 4AA4C5B62948729200171D0D /* Calendar+.swift */, 28419EA42944C8BD00266AB6 /* Data+.swift */, + 287C9BE92956D42400435EC5 /* SpaceCapsule+Bundle.swift */, ); path = Extensions; sourceTree = ""; @@ -1205,6 +1208,7 @@ 288A8EB229235B5A000229D2 /* ProfileView.swift in Sources */, 2894CBA22947303800E8F5FE /* Payload.swift in Sources */, 28419EA52944C8BD00266AB6 /* Data+.swift in Sources */, + 287C9BEA2956D42400435EC5 /* SpaceCapsule+Bundle.swift in Sources */, 2894CBA52947307900E8F5FE /* RefreshTokenResponse.swift in Sources */, 0DA05E1D29308B8400B08FA5 /* CustomNavigationController.swift in Sources */, 288A8ED029235BF9000229D2 /* HomeCoordinator.swift in Sources */, diff --git a/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift b/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift new file mode 100644 index 0000000..c5f18dd --- /dev/null +++ b/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift @@ -0,0 +1,25 @@ +// +// SpaceCapsule+Bundle.swift +// SpaceCapsule +// +// Created by young june Park on 2022/12/24. +// + +import Foundation + +extension Bundle { + var authKey: String { + guard let file = self.path(forResource: "AuthKey", ofType: ".plist"), + let url = URL(string: file) else { + return "" + } + + guard let resource = try? NSDictionary(contentsOf: url, error: ()) else { + return "" + } + guard let key = resource["AuthKey"] as? String else { + fatalError("AuthKey.plist에 authKey를 등록하세요") + } + return key + } +} From 56b60c59b6ec52de6a62148d2a14827c66450c77 Mon Sep 17 00:00:00 2001 From: Young June Park Date: Sat, 24 Dec 2022 15:42:07 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[chore]=20authKey=20=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Manager/Firebase/FirebaseAuthManager.swift | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift b/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift index 8640e58..ed50e63 100644 --- a/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift +++ b/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift @@ -60,18 +60,9 @@ final class FirebaseAuthManager { } private func clientSecret() -> String? { - guard let privateKey = - """ - -----BEGIN PRIVATE KEY----- - MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgBu59KBTVAYoS7A9A - SDr09NemKkFxu44brOzjfeo7YaGgCgYIKoZIzj0DAQehRANCAAS8nCVjRqbbQkU6 - w3jDMFAzLKYlZzWYN/QOS/hANnIOic1GMPKC2N98Fz4EDO52iWLsyl5pq7O3Wh2O - 79TSHEtE - -----END PRIVATE KEY----- - """.data(using: .utf8) else { + guard let privateKey = Bundle.main.authKey.data(using: .utf8) else { return nil } - var myJWT = JWT(claims: Payload()) let jwtSigner = JWTSigner.es256(privateKey: privateKey) guard let signedJWT = try? myJWT.sign(using: jwtSigner) else { From 944fce69cc45414cb97ac60cc95c3f369c63aa89 Mon Sep 17 00:00:00 2001 From: Young June Park Date: Sat, 24 Dec 2022 15:58:33 +0900 Subject: [PATCH 4/8] =?UTF-8?q?[chore]=20=EA=B5=AC=ED=98=84=EB=B6=80=20dep?= =?UTF-8?q?recated=20=EB=90=9C=20=ED=95=A8=EC=88=98=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=20(#127)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpaceCapsule/SpaceCapsule/AuthKey.plist | 7 ++++++- .../SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/SpaceCapsule/SpaceCapsule/AuthKey.plist b/SpaceCapsule/SpaceCapsule/AuthKey.plist index ce9c739..835ca7c 100644 --- a/SpaceCapsule/SpaceCapsule/AuthKey.plist +++ b/SpaceCapsule/SpaceCapsule/AuthKey.plist @@ -3,6 +3,11 @@ AuthKey - 여기에 키 입력 + -----BEGIN PRIVATE KEY----- + MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgBu59KBTVAYoS7A9A + SDr09NemKkFxu44brOzjfeo7YaGgCgYIKoZIzj0DAQehRANCAAS8nCVjRqbbQkU6 + w3jDMFAzLKYlZzWYN/QOS/hANnIOic1GMPKC2N98Fz4EDO52iWLsyl5pq7O3Wh2O + 79TSHEtE + -----END PRIVATE KEY----- diff --git a/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift b/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift index c5f18dd..a247f97 100644 --- a/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift +++ b/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift @@ -9,17 +9,17 @@ import Foundation extension Bundle { var authKey: String { - guard let file = self.path(forResource: "AuthKey", ofType: ".plist"), - let url = URL(string: file) else { + guard let file = path(forResource: "AuthKey", ofType: "plist") else { return "" } - - guard let resource = try? NSDictionary(contentsOf: url, error: ()) else { + + guard let resource = try? NSDictionary(contentsOf: NSURL(fileURLWithPath: file) as URL, error: ()) else { return "" } guard let key = resource["AuthKey"] as? String else { fatalError("AuthKey.plist에 authKey를 등록하세요") } + print(key) return key } } From aaf8d39a5d6f3bcd86e8b5310921c9ef50aed4fb Mon Sep 17 00:00:00 2001 From: Young June Park Date: Sat, 24 Dec 2022 16:01:52 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[chore]=20p8=20=EB=8B=A4=EC=9A=B4=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20=ED=95=A8=EC=88=98=20=EC=A0=9C=EA=B1=B0=20(#127)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Manager/Firebase/FirebaseStorageManager.swift | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseStorageManager.swift b/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseStorageManager.swift index d794b02..d5ec335 100644 --- a/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseStorageManager.swift +++ b/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseStorageManager.swift @@ -43,18 +43,6 @@ final class FirebaseStorageManager { } } - func downloadAuthP8(urlString: String, completion: @escaping (Data?) -> Void) { - let storageReference = storage.reference(forURL: urlString) - let megaByte = Int64(1 * 1024 * 1024) - storageReference.getData(maxSize: megaByte) { data, _ in - guard let data = data else { - completion(nil) - return - } - completion(data) - } - } - func deleteImagesInCapsule(capsules: [Capsule], completion: @escaping (Error?) -> Void) { for capsule in capsules { capsule.images.forEach { url in From 977db51abfa59650677b14b0356df4d72967e41f Mon Sep 17 00:00:00 2001 From: Young June Park Date: Sat, 24 Dec 2022 16:03:20 +0900 Subject: [PATCH 6/8] =?UTF-8?q?[chore]=20print=EB=AC=B8=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20(#127)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift b/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift index a247f97..48d0f38 100644 --- a/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift +++ b/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift @@ -19,7 +19,6 @@ extension Bundle { guard let key = resource["AuthKey"] as? String else { fatalError("AuthKey.plist에 authKey를 등록하세요") } - print(key) return key } } From a8cb78f1208c98ecbe100d3a5037e38331a09b10 Mon Sep 17 00:00:00 2001 From: Young June Park Date: Sat, 24 Dec 2022 16:42:52 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[refactor]=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=ED=94=BC=EB=93=9C=EB=B0=B1=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/SpaceCapsule+Bundle.swift | 16 ++++++---------- .../Manager/Firebase/FirebaseAuthManager.swift | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift b/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift index 48d0f38..46333e2 100644 --- a/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift +++ b/SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift @@ -8,17 +8,13 @@ import Foundation extension Bundle { - var authKey: String { - guard let file = path(forResource: "AuthKey", ofType: "plist") else { - return "" - } - - guard let resource = try? NSDictionary(contentsOf: NSURL(fileURLWithPath: file) as URL, error: ()) else { - return "" - } - guard let key = resource["AuthKey"] as? String else { - fatalError("AuthKey.plist에 authKey를 등록하세요") + var authKey: String? { + guard let file = path(forResource: "AuthKey", ofType: "plist"), + let resource = try? NSDictionary(contentsOf: NSURL(fileURLWithPath: file) as URL, error: ()), + let key = resource["AuthKey"] as? String else { + return nil } + return key } } diff --git a/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift b/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift index ed50e63..c225852 100644 --- a/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift +++ b/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift @@ -60,7 +60,7 @@ final class FirebaseAuthManager { } private func clientSecret() -> String? { - guard let privateKey = Bundle.main.authKey.data(using: .utf8) else { + guard let privateKey = Bundle.main.authKey?.data(using: .utf8) else { return nil } var myJWT = JWT(claims: Payload()) From 2e991c81ffa69817af95d8320c8adc122ec69bc5 Mon Sep 17 00:00:00 2001 From: Young June Park Date: Sat, 24 Dec 2022 16:47:39 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[refactor]=20=ED=9A=8C=EC=9B=90=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EC=8B=9C=20auth=EC=97=90=EC=84=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=20=EC=82=AD=EC=A0=9C=20=EB=90=9C=20=EA=B2=BD=EC=9A=B0?= =?UTF-8?q?=20error=20=EB=82=B4=EC=A7=80=20=EC=95=8A=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift b/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift index c225852..34a5e26 100644 --- a/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift +++ b/SpaceCapsule/SpaceCapsule/Manager/Firebase/FirebaseAuthManager.swift @@ -50,7 +50,11 @@ final class FirebaseAuthManager { } func deleteAccountFromAuth(completion: @escaping ((FBAuthError?) -> Void)) { - auth.currentUser?.delete { error in + guard let currentUser = auth.currentUser else { + completion(nil) + return + } + currentUser.delete { error in if error != nil { completion(FBAuthError.deleteUserFromAuthError) } else {