Skip to content

Commit

Permalink
Merge pull request #128 from boostcampwm-2022/refactor_hideP8Key
Browse files Browse the repository at this point in the history
[전체] Auth Key Plist에 넣기
  • Loading branch information
pyj9748 authored Dec 24, 2022
2 parents fae5103 + 2e991c8 commit 0ded849
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
8 changes: 8 additions & 0 deletions SpaceCapsule/SpaceCapsule.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
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 */; };
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 */; };
Expand Down Expand Up @@ -267,6 +269,8 @@
28245561293B17B100DE03A1 /* UnOpenable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnOpenable.swift; sourceTree = "<group>"; };
28419E5E294028DE00266AB6 /* NotificationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationManager.swift; sourceTree = "<group>"; };
28419EA42944C8BD00266AB6 /* Data+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+.swift"; sourceTree = "<group>"; };
287C9BE72956D35400435EC5 /* AuthKey.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = AuthKey.plist; sourceTree = "<group>"; };
287C9BE92956D42400435EC5 /* SpaceCapsule+Bundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SpaceCapsule+Bundle.swift"; sourceTree = "<group>"; };
2885A9FF293B6466003E5311 /* ProfileButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileButton.swift; sourceTree = "<group>"; };
288A8E912923244D000229D2 /* Coordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Coordinator.swift; sourceTree = "<group>"; };
288A8E96292359CF000229D2 /* AuthCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthCoordinator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -432,6 +436,7 @@
59F567F72923BE1E00F756B2 /* SpaceCapsule.entitlements */,
4A05D0EB2924C04200A2EF50 /* GoogleService-Info.plist */,
0D6CA342292216A400E02393 /* Info.plist */,
287C9BE72956D35400435EC5 /* AuthKey.plist */,
0D2B7AB92934594400CE34E3 /* running.gpx */,
0D6CA33D292216A400E02393 /* Assets.xcassets */,
0D6CA33F292216A400E02393 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -505,6 +510,7 @@
0DD83D10292F2EC80020F15C /* UIViewController+.swift */,
4AA4C5B62948729200171D0D /* Calendar+.swift */,
28419EA42944C8BD00266AB6 /* Data+.swift */,
287C9BE92956D42400435EC5 /* SpaceCapsule+Bundle.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1046,6 +1052,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 */,
Expand Down Expand Up @@ -1201,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 */,
Expand Down
13 changes: 13 additions & 0 deletions SpaceCapsule/SpaceCapsule/AuthKey.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AuthKey</key>
<string>-----BEGIN PRIVATE KEY-----
MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgBu59KBTVAYoS7A9A
SDr09NemKkFxu44brOzjfeo7YaGgCgYIKoZIzj0DAQehRANCAAS8nCVjRqbbQkU6
w3jDMFAzLKYlZzWYN/QOS/hANnIOic1GMPKC2N98Fz4EDO52iWLsyl5pq7O3Wh2O
79TSHEtE
-----END PRIVATE KEY-----</string>
</dict>
</plist>
20 changes: 20 additions & 0 deletions SpaceCapsule/SpaceCapsule/Extensions/SpaceCapsule+Bundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// SpaceCapsule+Bundle.swift
// SpaceCapsule
//
// Created by young june Park on 2022/12/24.
//

import Foundation

extension Bundle {
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -60,18 +64,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ded849

Please sign in to comment.