From 1b4e34b39cfec6f28584d60a8f2354dc9551aa55 Mon Sep 17 00:00:00 2001 From: chomki32 Date: Sun, 6 Oct 2024 16:24:35 +0900 Subject: [PATCH 1/2] Feat: KaKao, Google Login --- app.xcodeproj/project.pbxproj | 86 ++++++++++++++++++- .../xcshareddata/swiftpm/Package.resolved | 47 +++++++++- app/AppDelegate.swift | 20 ++++- app/Info.plist | 29 +++++++ app/SceneDelegate.swift | 9 ++ app/WebVIew/WebBridgeHandler.swift | 52 +++++++++++ app/utils/GoogleLogin.swift | 19 ++++ app/utils/KakaoLogin.swift | 23 +++++ app/utils/LoginDelegate.swift | 15 ++++ 9 files changed, 294 insertions(+), 6 deletions(-) create mode 100644 app/utils/GoogleLogin.swift create mode 100644 app/utils/KakaoLogin.swift create mode 100644 app/utils/LoginDelegate.swift diff --git a/app.xcodeproj/project.pbxproj b/app.xcodeproj/project.pbxproj index cbd31ba..b408f12 100644 --- a/app.xcodeproj/project.pbxproj +++ b/app.xcodeproj/project.pbxproj @@ -11,8 +11,17 @@ C81D694C2BC1821D00C77484 /* SwiftSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = C81D694B2BC1821D00C77484 /* SwiftSupport.swift */; }; C81D694F2BC18B9000C77484 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = C81D694E2BC18B9000C77484 /* JSON.swift */; }; C81D69512BC193AE00C77484 /* UIColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C81D69502BC193AE00C77484 /* UIColor+Extension.swift */; }; + C835EDEC2CB269FE00B44D23 /* LoginDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C835EDEB2CB269FE00B44D23 /* LoginDelegate.swift */; }; + C835EDEE2CB26A4C00B44D23 /* GoogleLogin.swift in Sources */ = {isa = PBXBuildFile; fileRef = C835EDED2CB26A4C00B44D23 /* GoogleLogin.swift */; }; + C835EDF02CB26A7F00B44D23 /* KakaoLogin.swift in Sources */ = {isa = PBXBuildFile; fileRef = C835EDEF2CB26A7F00B44D23 /* KakaoLogin.swift */; }; C867F0C32BB059C0004CE321 /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = C867F0C22BB059C0004CE321 /* FirebaseMessaging */; }; C86A24032C109C64006285DD /* Static.swift in Sources */ = {isa = PBXBuildFile; fileRef = C86A24022C109C64006285DD /* Static.swift */; }; + C88766972CB17CF700B64A63 /* KakaoSDK in Frameworks */ = {isa = PBXBuildFile; productRef = C88766962CB17CF700B64A63 /* KakaoSDK */; }; + C88766992CB17CF700B64A63 /* KakaoSDKAuth in Frameworks */ = {isa = PBXBuildFile; productRef = C88766982CB17CF700B64A63 /* KakaoSDKAuth */; }; + C887669B2CB17CF700B64A63 /* KakaoSDKCommon in Frameworks */ = {isa = PBXBuildFile; productRef = C887669A2CB17CF700B64A63 /* KakaoSDKCommon */; }; + C887669D2CB17CF700B64A63 /* KakaoSDKUser in Frameworks */ = {isa = PBXBuildFile; productRef = C887669C2CB17CF700B64A63 /* KakaoSDKUser */; }; + C88766A12CB1853C00B64A63 /* GoogleSignIn in Frameworks */ = {isa = PBXBuildFile; productRef = C88766A02CB1853C00B64A63 /* GoogleSignIn */; }; + C88766A32CB1853C00B64A63 /* GoogleSignInSwift in Frameworks */ = {isa = PBXBuildFile; productRef = C88766A22CB1853C00B64A63 /* GoogleSignInSwift */; }; C88D19382B9DE72200197101 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C88D19372B9DE72200197101 /* AppDelegate.swift */; }; C88D193A2B9DE73600197101 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C88D19392B9DE73600197101 /* SceneDelegate.swift */; }; C8AAE3342BE11AFE002478B2 /* NotificationName.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8AAE3332BE11AFE002478B2 /* NotificationName.swift */; }; @@ -53,6 +62,9 @@ C81D694B2BC1821D00C77484 /* SwiftSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftSupport.swift; sourceTree = ""; }; C81D694E2BC18B9000C77484 /* JSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = ""; }; C81D69502BC193AE00C77484 /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = ""; }; + C835EDEB2CB269FE00B44D23 /* LoginDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginDelegate.swift; sourceTree = ""; }; + C835EDED2CB26A4C00B44D23 /* GoogleLogin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoogleLogin.swift; sourceTree = ""; }; + C835EDEF2CB26A7F00B44D23 /* KakaoLogin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KakaoLogin.swift; sourceTree = ""; }; C867F0B82BB054A5004CE321 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; C86A24022C109C64006285DD /* Static.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Static.swift; sourceTree = ""; }; C88D19372B9DE72200197101 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -83,6 +95,12 @@ files = ( C867F0C32BB059C0004CE321 /* FirebaseMessaging in Frameworks */, C8C3B1552C2710CE00D558B9 /* FirebaseRemoteConfigSwift in Frameworks */, + C887669D2CB17CF700B64A63 /* KakaoSDKUser in Frameworks */, + C88766A32CB1853C00B64A63 /* GoogleSignInSwift in Frameworks */, + C88766972CB17CF700B64A63 /* KakaoSDK in Frameworks */, + C887669B2CB17CF700B64A63 /* KakaoSDKCommon in Frameworks */, + C88766992CB17CF700B64A63 /* KakaoSDKAuth in Frameworks */, + C88766A12CB1853C00B64A63 /* GoogleSignIn in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -128,6 +146,9 @@ isa = PBXGroup; children = ( C8C3B1562C2716B700D558B9 /* FinhubRemoteConfig.swift */, + C835EDEB2CB269FE00B44D23 /* LoginDelegate.swift */, + C835EDEF2CB26A7F00B44D23 /* KakaoLogin.swift */, + C835EDED2CB26A4C00B44D23 /* GoogleLogin.swift */, ); path = utils; sourceTree = ""; @@ -217,6 +238,12 @@ packageProductDependencies = ( C867F0C22BB059C0004CE321 /* FirebaseMessaging */, C8C3B1542C2710CE00D558B9 /* FirebaseRemoteConfigSwift */, + C88766962CB17CF700B64A63 /* KakaoSDK */, + C88766982CB17CF700B64A63 /* KakaoSDKAuth */, + C887669A2CB17CF700B64A63 /* KakaoSDKCommon */, + C887669C2CB17CF700B64A63 /* KakaoSDKUser */, + C88766A02CB1853C00B64A63 /* GoogleSignIn */, + C88766A22CB1853C00B64A63 /* GoogleSignInSwift */, ); productName = app; productReference = FDFD05BD2B74E59C0029CA87 /* app.app */; @@ -292,6 +319,8 @@ mainGroup = FDFD05B42B74E59C0029CA87; packageReferences = ( C867F0C12BB059C0004CE321 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */, + C88766952CB168E700B64A63 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */, + C887669F2CB1853B00B64A63 /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */, ); productRefGroup = FDFD05BE2B74E59C0029CA87 /* Products */; projectDirPath = ""; @@ -338,6 +367,8 @@ files = ( C81D694C2BC1821D00C77484 /* SwiftSupport.swift in Sources */, C8AAE3342BE11AFE002478B2 /* NotificationName.swift in Sources */, + C835EDF02CB26A7F00B44D23 /* KakaoLogin.swift in Sources */, + C835EDEE2CB26A4C00B44D23 /* GoogleLogin.swift in Sources */, C88D193A2B9DE73600197101 /* SceneDelegate.swift in Sources */, C88D19382B9DE72200197101 /* AppDelegate.swift in Sources */, C8AAE3362BE1228D002478B2 /* String+Extension.swift in Sources */, @@ -348,6 +379,7 @@ C81D694F2BC18B9000C77484 /* JSON.swift in Sources */, FDFD05C32B74E59C0029CA87 /* ContentView.swift in Sources */, FDFD05C12B74E59C0029CA87 /* appApp.swift in Sources */, + C835EDEC2CB269FE00B44D23 /* LoginDelegate.swift in Sources */, FDA5B4E42BB7DE9300A4DC49 /* FinhubWebView.swift in Sources */, C81D69512BC193AE00C77484 /* UIColor+Extension.swift in Sources */, ); @@ -507,12 +539,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - BASE_URL = "https://dev-main.fin-hub.co.kr"; + BASE_URL = "http://192.168.219.108:3000"; CODE_SIGN_ENTITLEMENTS = app/app.entitlements; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 19; DEVELOPMENT_ASSET_PATHS = "\"app/Preview Content\""; - DEVELOPMENT_TEAM = JBY3X8KKJH; + DEVELOPMENT_TEAM = 8XA9DWRR85; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = app/Info.plist; @@ -546,11 +578,11 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 19; DEVELOPMENT_ASSET_PATHS = "\"app/Preview Content\""; - DEVELOPMENT_TEAM = JBY3X8KKJH; + DEVELOPMENT_TEAM = 8XA9DWRR85; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = app/Info.plist; - INFOPLIST_KEY_CFBundleDisplayName = "핀허브"; + INFOPLIST_KEY_CFBundleDisplayName = "핀허브(개발)"; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; @@ -696,6 +728,22 @@ minimumVersion = 10.23.0; }; }; + C88766952CB168E700B64A63 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/kakao/kakao-ios-sdk"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.22.7; + }; + }; + C887669F2CB1853B00B64A63 /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/google/GoogleSignIn-iOS"; + requirement = { + kind = exactVersion; + version = 7.0.0; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -704,6 +752,36 @@ package = C867F0C12BB059C0004CE321 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; productName = FirebaseMessaging; }; + C88766962CB17CF700B64A63 /* KakaoSDK */ = { + isa = XCSwiftPackageProductDependency; + package = C88766952CB168E700B64A63 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDK; + }; + C88766982CB17CF700B64A63 /* KakaoSDKAuth */ = { + isa = XCSwiftPackageProductDependency; + package = C88766952CB168E700B64A63 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDKAuth; + }; + C887669A2CB17CF700B64A63 /* KakaoSDKCommon */ = { + isa = XCSwiftPackageProductDependency; + package = C88766952CB168E700B64A63 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDKCommon; + }; + C887669C2CB17CF700B64A63 /* KakaoSDKUser */ = { + isa = XCSwiftPackageProductDependency; + package = C88766952CB168E700B64A63 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */; + productName = KakaoSDKUser; + }; + C88766A02CB1853C00B64A63 /* GoogleSignIn */ = { + isa = XCSwiftPackageProductDependency; + package = C887669F2CB1853B00B64A63 /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */; + productName = GoogleSignIn; + }; + C88766A22CB1853C00B64A63 /* GoogleSignInSwift */ = { + isa = XCSwiftPackageProductDependency; + package = C887669F2CB1853B00B64A63 /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */; + productName = GoogleSignInSwift; + }; C8C3B1542C2710CE00D558B9 /* FirebaseRemoteConfigSwift */ = { isa = XCSwiftPackageProductDependency; package = C867F0C12BB059C0004CE321 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; diff --git a/app.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/app.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 1ad57b8..8feaeb6 100644 --- a/app.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/app.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "a1569f9895aa2be8e24832f98525d5da4eb90b5d158a82691c15b47eb72a13d7", + "originHash" : "b80ba020e4f7bf35e22fc97c5a46cb894214f9258b706f52ab20d37dea8bc7cb", "pins" : [ { "identity" : "abseil-cpp-binary", @@ -10,6 +10,15 @@ "version" : "1.2024011601.0" } }, + { + "identity" : "alamofire", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Alamofire/Alamofire.git", + "state" : { + "revision" : "f455c2975872ccd2d9c81594c658af65716e9b9a", + "version" : "5.9.1" + } + }, { "identity" : "app-check", "kind" : "remoteSourceControl", @@ -19,6 +28,15 @@ "version" : "10.18.1" } }, + { + "identity" : "appauth-ios", + "kind" : "remoteSourceControl", + "location" : "https://github.com/openid/AppAuth-iOS.git", + "state" : { + "revision" : "c89ed571ae140f8eb1142735e6e23d7bb8c34cb2", + "version" : "1.7.5" + } + }, { "identity" : "firebase-ios-sdk", "kind" : "remoteSourceControl", @@ -46,6 +64,15 @@ "version" : "9.3.0" } }, + { + "identity" : "googlesignin-ios", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleSignIn-iOS", + "state" : { + "revision" : "7932d33686c1dc4d7df7a919aae47361d1cdfda4", + "version" : "7.0.0" + } + }, { "identity" : "googleutilities", "kind" : "remoteSourceControl", @@ -73,6 +100,15 @@ "version" : "3.3.1" } }, + { + "identity" : "gtmappauth", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GTMAppAuth.git", + "state" : { + "revision" : "cee3c709307912d040bd1e06ca919875a92339c6", + "version" : "2.0.0" + } + }, { "identity" : "interop-ios-for-google-sdks", "kind" : "remoteSourceControl", @@ -82,6 +118,15 @@ "version" : "100.0.0" } }, + { + "identity" : "kakao-ios-sdk", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kakao/kakao-ios-sdk", + "state" : { + "revision" : "5fcd519edd8ecfa134017fff90cf0d30e0a90919", + "version" : "2.22.7" + } + }, { "identity" : "leveldb", "kind" : "remoteSourceControl", diff --git a/app/AppDelegate.swift b/app/AppDelegate.swift index 7b5c20b..889d970 100644 --- a/app/AppDelegate.swift +++ b/app/AppDelegate.swift @@ -9,6 +9,9 @@ import Foundation import UIKit import FirebaseCore import FirebaseMessaging +import KakaoSDKCommon +import KakaoSDKAuth +import GoogleSignIn class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, @@ -21,9 +24,12 @@ class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { + // Firebase 초기화 FirebaseApp.configure() - + // FirebaseRemoteConfig 초기화 FinhubRemoteConfig.shared.ready() + // Kakao SDK 초기화 + KakaoSDK.initSDK(appKey: Bundle.main.object(forInfoDictionaryKey: "KAKAO_SDK_KEY") as! String) let authOption: UNAuthorizationOptions = [.alert, .badge, .sound] UNUserNotificationCenter.current().requestAuthorization(options: authOption, completionHandler: {_, _ in }) @@ -39,6 +45,18 @@ class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { Messaging.messaging().apnsToken = deviceToken } + + func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { + if AuthApi.isKakaoTalkLoginUrl(url) { + return AuthController.handleOpenUrl(url: url) + } + + if GIDSignIn.sharedInstance.handle(url) { + return true + } + + return false + } } extension AppDelegate: UNUserNotificationCenterDelegate { diff --git a/app/Info.plist b/app/Info.plist index 88e9d36..681321c 100644 --- a/app/Info.plist +++ b/app/Info.plist @@ -4,8 +4,37 @@ BASE_URL ${BASE_URL} + KAKAO_SDK_KEY + 8ac60f3977b6f8ae9d19501b7faf5edb + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLSchemes + + kakao8ac60f3977b6f8ae9d19501b7faf5edb + + + + CFBundleTypeRole + Editor + CFBundleURLSchemes + + com.googleusercontent.apps.353339464651-cnrkadg38nfnk9fn2fset2hb1cho1lj9 + + + + GIDClientID + 353339464651-cnrkadg38nfnk9fn2fset2hb1cho1lj9.apps.googleusercontent.com ITSAppUsesNonExemptEncryption + LSApplicationQueriesSchemes + + kakaokompassauth + kakaolink + kakaoplus + UIBackgroundModes fetch diff --git a/app/SceneDelegate.swift b/app/SceneDelegate.swift index e6df655..ac7a311 100644 --- a/app/SceneDelegate.swift +++ b/app/SceneDelegate.swift @@ -7,6 +7,7 @@ import Foundation import UIKit +import KakaoSDKAuth class SceneDelegate: NSObject, UIWindowSceneDelegate { func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { @@ -21,4 +22,12 @@ class SceneDelegate: NSObject, UIWindowSceneDelegate { SwiftSupport.sendNotification(data: userInfo.toJsonString) } } + + func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { + if let url = URLContexts.first?.url { + if (AuthApi.isKakaoTalkLoginUrl(url)) { + _ = AuthController.handleOpenUrl(url: url) + } + } + } } diff --git a/app/WebVIew/WebBridgeHandler.swift b/app/WebVIew/WebBridgeHandler.swift index e80f53c..26507e9 100644 --- a/app/WebVIew/WebBridgeHandler.swift +++ b/app/WebVIew/WebBridgeHandler.swift @@ -9,6 +9,8 @@ import Foundation import WebKit import FirebaseMessaging import FirebaseRemoteConfig +import KakaoSDKUser +import GoogleSignIn protocol WebBridgeDelegate: NSObjectProtocol { func callbackWeb(callbackId: String, data: String?) @@ -16,6 +18,7 @@ protocol WebBridgeDelegate: NSObjectProtocol { class WebBridgeHandler: NSObject { weak var delegate: WebBridgeDelegate? + private var loginDelegate: LoginDelegate? init(_ delegate: WebBridgeDelegate? = nil) { self.delegate = delegate @@ -104,4 +107,53 @@ extension WebBridgeHandler { @objc func requestNotificationPermission(_ json: JSON) { UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) } + + @objc func loginKakao(_ json: JSON) { + guard let callback = getCallback(json) else { return } + + loginDelegate = KakaoLogin() + login(callback: callback) + } + + @objc func loginGoogle(_ json: JSON) { + guard let _ = SwiftSupport.topViewController, + let callback = getCallback(json) + else { return } + + loginDelegate = GoogleLogin() + login(callback: callback) + } + + @objc func loginApple(_ json: JSON) { + // TODO + } + + private func login(callback: String) { + loginDelegate?.login { [weak self] token, error in + guard let self = self else { return } + + var result: JSON = [:] + + if let error = error { + result = [ + "result": "error", + "msg": error.localizedDescription + ] + } + else if let token = token { + result = [ + "result": "success", + "token": token + ] + } + else { + result = [ + "result": "failed", + "msg": "로그인 실패" + ] + } + + self.delegate?.callbackWeb(callbackId: callback, data: result.toJsonString) + } + } } diff --git a/app/utils/GoogleLogin.swift b/app/utils/GoogleLogin.swift new file mode 100644 index 0000000..e5b129e --- /dev/null +++ b/app/utils/GoogleLogin.swift @@ -0,0 +1,19 @@ +// +// GoogleLogin.swift +// app +// +// Created by 조민기 on 10/6/24. +// + +import Foundation +import GoogleSignIn + +class GoogleLogin: LoginDelegate { + func login(complete result: LoginResult?) { + guard let viewController = SwiftSupport.topViewController else { return } + + GIDSignIn.sharedInstance.signIn(withPresenting: viewController) { auth, error in + result?(auth?.user.idToken?.tokenString, error) + } + } +} diff --git a/app/utils/KakaoLogin.swift b/app/utils/KakaoLogin.swift new file mode 100644 index 0000000..030ad1d --- /dev/null +++ b/app/utils/KakaoLogin.swift @@ -0,0 +1,23 @@ +// +// KakaoLogin.swift +// app +// +// Created by 조민기 on 10/6/24. +// + +import Foundation +import KakaoSDKUser + +class KakaoLogin: LoginDelegate { + func login(complete result: LoginResult?) { + if (UserApi.isKakaoTalkLoginAvailable()) { + UserApi.shared.loginWithKakaoTalk(completion: { oauthToken, error in + result?(oauthToken?.accessToken, error) + }) + } else { + UserApi.shared.loginWithKakaoAccount { oauthToken, error in + result?(oauthToken?.accessToken, error) + } + } + } +} diff --git a/app/utils/LoginDelegate.swift b/app/utils/LoginDelegate.swift new file mode 100644 index 0000000..ad2385b --- /dev/null +++ b/app/utils/LoginDelegate.swift @@ -0,0 +1,15 @@ +// +// LoginProtocol.swift +// app +// +// Created by 조민기 on 10/6/24. +// + +import Foundation + +typealias LoginResult = (_ token: String?, _ error: Error?) -> Void + +protocol LoginDelegate { + func login(complete result: LoginResult?) +} + From a9e586ab4468c83b28120fd530c93748bf122555 Mon Sep 17 00:00:00 2001 From: chomki32 Date: Sun, 6 Oct 2024 19:18:12 +0900 Subject: [PATCH 2/2] fix: add server client id --- app/Info.plist | 6 ++++-- app/utils/GoogleLogin.swift | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Info.plist b/app/Info.plist index 681321c..bb6b62a 100644 --- a/app/Info.plist +++ b/app/Info.plist @@ -4,8 +4,6 @@ BASE_URL ${BASE_URL} - KAKAO_SDK_KEY - 8ac60f3977b6f8ae9d19501b7faf5edb CFBundleURLTypes @@ -27,8 +25,12 @@ GIDClientID 353339464651-cnrkadg38nfnk9fn2fset2hb1cho1lj9.apps.googleusercontent.com + GIDServerClientID + 353339464651-dnul84p5jsljqkg1gfsgsdoqol5ci1ak.apps.googleusercontent.com ITSAppUsesNonExemptEncryption + KAKAO_SDK_KEY + 8ac60f3977b6f8ae9d19501b7faf5edb LSApplicationQueriesSchemes kakaokompassauth diff --git a/app/utils/GoogleLogin.swift b/app/utils/GoogleLogin.swift index e5b129e..6275670 100644 --- a/app/utils/GoogleLogin.swift +++ b/app/utils/GoogleLogin.swift @@ -13,7 +13,7 @@ class GoogleLogin: LoginDelegate { guard let viewController = SwiftSupport.topViewController else { return } GIDSignIn.sharedInstance.signIn(withPresenting: viewController) { auth, error in - result?(auth?.user.idToken?.tokenString, error) + result?(auth?.serverAuthCode, error) } } }