Skip to content

Commit

Permalink
feat: 구글 로그인 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ryr0121 committed Mar 15, 2023
1 parent b91dbcd commit 8c3877c
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 7 deletions.
20 changes: 20 additions & 0 deletions KeKi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@
A2434AC3298651F500F60D1A /* Frameworks */,
A2434AC4298651F500F60D1A /* Resources */,
1B90B7F2C8B7B75310385F93 /* [CP] Embed Pods Frameworks */,
D8120C1246AF0D85A8F0061A /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -741,6 +742,23 @@
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-KeKi/Pods-KeKi-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
D8120C1246AF0D85A8F0061A /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-KeKi/Pods-KeKi-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-KeKi/Pods-KeKi-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-KeKi/Pods-KeKi-resources.sh\"\n";
showEnvVarsInLog = 0;
};
DE60C26EFAE342A4F9F45506 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1001,6 +1019,7 @@
INFOPLIST_KEY_UIMainStoryboardFile = "";
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_UIUserInterfaceStyle = Light;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -1036,6 +1055,7 @@
INFOPLIST_KEY_UIMainStoryboardFile = "";
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_UIUserInterfaceStyle = Light;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
5 changes: 5 additions & 0 deletions KeKi/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import NaverThirdPartyLogin

import AuthenticationServices

import GoogleSignIn

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

Expand All @@ -38,6 +40,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
instance?.consumerSecret = "XZHzyRgQditsj_BuDAHZ" // pw
instance?.appName = "케키" // app name

// Google
GIDSignIn.sharedInstance().clientID = "282823038399-jp07tva2mg6o0amv7hrm1relkockop3r.apps.googleusercontent.com"


// Loacl Notification
let center = UNUserNotificationCenter.current() // 알림 센터 가져오기
Expand Down
6 changes: 6 additions & 0 deletions KeKi/App/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import UIKit
import KakaoSDKAuth
import NaverThirdPartyLogin
import GoogleSignIn

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

Expand Down Expand Up @@ -39,6 +40,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
.getSharedInstance()?
.receiveAccessToken(URLContexts.first?.url)
}

guard let scheme = URLContexts.first?.url.scheme else { return }
if scheme.contains("com.googleusercontent.apps") {
GIDSignIn.sharedInstance().handle(URLContexts.first?.url)
}
}

}
Expand Down
10 changes: 8 additions & 2 deletions KeKi/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand All @@ -24,6 +22,14 @@
<string>https://keki-dev.store/users/callback/naver</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.282823038399-jp07tva2mg6o0amv7hrm1relkockop3r</string>
</array>
</dict>
</array>
<key>KAKAO_NATIVE_APP_KEY</key>
<string>${KAKAO_NATIVE_APP_KEY}</string>
Expand Down
49 changes: 45 additions & 4 deletions KeKi/Scenes/Login/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import KakaoSDKAuth
import KakaoSDKUser
import NaverThirdPartyLogin
import AuthenticationServices
import GoogleSignIn

enum Role: String {
case notUser = "비회원"
Expand All @@ -28,7 +29,7 @@ class LoginViewController: UIViewController {
// MARK: - Variables, IBOutlet, ...
let naverLoginInstance = NaverThirdPartyLoginConnection.getSharedInstance()

@IBOutlet weak var googleLoginButton: UIButton!
@IBOutlet weak var googleLoginButton: GIDSignInButton!
@IBOutlet weak var kakaoLoginButton: UIButton!
@IBOutlet weak var naverLoginButton: UIButton!
@IBOutlet weak var appleLoginButton: ASAuthorizationAppleIDButton!
Expand All @@ -43,6 +44,9 @@ class LoginViewController: UIViewController {

// apple login button setup
appleLoginButton.addTarget(self, action: #selector(didTapAppleLoginButton(_:)), for: .touchUpInside)

// google login setup
setGoogleSignInButton()
}

override func viewWillAppear(_ animated: Bool) {
Expand All @@ -54,10 +58,11 @@ class LoginViewController: UIViewController {
@IBAction func didTapGoogleLoginButton(_ sender: UIButton) {
// TODO: 구글 로그인 기능 추가
print("didTapGoogleLoginButton")
googleSocialLogin()

// 유저 정보 설정창으로 전환 처리 (임시 구현, 이후 삭제 예정)
guard let selectUserCategoryViewController = storyboard?.instantiateViewController(withIdentifier: "SelectUserCategoryViewController") as? SelectUserCategoryViewController else { return }
navigationController?.pushViewController(selectUserCategoryViewController, animated: true)
// guard let selectUserCategoryViewController = storyboard?.instantiateViewController(withIdentifier: "SelectUserCategoryViewController") as? SelectUserCategoryViewController else { return }
// navigationController?.pushViewController(selectUserCategoryViewController, animated: true)
}

@IBAction func didTapKakaoLoginButton(_ sender: UIButton) {
Expand All @@ -80,6 +85,11 @@ class LoginViewController: UIViewController {


// MARK: - Helper Methods (Setup Method, ...)
private func setGoogleSignInButton() {
GIDSignIn.sharedInstance()?.presentingViewController = self
GIDSignIn.sharedInstance().delegate = self
}

private func setupButtonLayouts() {
[
googleLoginButton,
Expand All @@ -96,7 +106,7 @@ class LoginViewController: UIViewController {
appleLoginButton
].forEach { $0?.layer.cornerRadius = 25 }

googleLoginButton.configuration?.imagePadding = 53
// googleLoginButton.configuration?.imagePadding = 53
kakaoLoginButton.configuration?.imagePadding = 53
naverLoginButton.configuration?.imagePadding = 34
// appleLoginButton.configuration?.imagePadding = 48
Expand All @@ -123,6 +133,33 @@ class LoginViewController: UIViewController {
}
}

// MARK: - GOOGLE Social Login Delegate
extension LoginViewController: GIDSignInDelegate {
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error {
if (error as NSError).code == GIDSignInErrorCode.hasNoAuthInKeychain.rawValue {
print("The user has not signed in before or they have since signed out.")
} else {
print("\(error.localizedDescription)")
}
return
}

// 사용자 정보 가져오기
if let email = user.profile.email {
print("User Email : \(email)")
requestSocialLogin(email: email, provider: "구글")

} else {
print("Error : User Data Not Found")
}
}

func oauth20Connection(_ oauthConnection: NaverThirdPartyLoginConnection!, didFinishAuthorizationWithResult receiveType: THIRDPARTYLOGIN_RECEIVE_TYPE) {
print("Google Login Disconnect")
}
}

// MARK: - NAVER Social Login Delegate
extension LoginViewController : NaverThirdPartyLoginConnectionDelegate {
func oauth20ConnectionDidFinishRequestACTokenWithAuthCode() { getNaverUserInfo() }
Expand Down Expand Up @@ -204,6 +241,10 @@ extension LoginViewController {
authorizationController.presentationContextProvider = self
authorizationController.performRequests()
}

private func googleSocialLogin() {
GIDSignIn.sharedInstance()?.signIn()
}
}

extension LoginViewController {
Expand Down
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ target 'KeKi' do
pod 'IQKeyboardManagerSwift'
pod 'naveridlogin-sdk-ios'
pod 'JGProgressHUD'
pod 'GoogleSignIn', '~> 5.0'

end
25 changes: 24 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
PODS:
- AppAuth (1.6.0):
- AppAuth/Core (= 1.6.0)
- AppAuth/ExternalUserAgent (= 1.6.0)
- AppAuth/Core (1.6.0)
- AppAuth/ExternalUserAgent (1.6.0):
- AppAuth/Core
- GoogleSignIn (5.0.2):
- AppAuth (~> 1.2)
- GTMAppAuth (~> 1.0)
- GTMSessionFetcher/Core (~> 1.1)
- GTMAppAuth (1.3.1):
- AppAuth/Core (~> 1.6)
- GTMSessionFetcher/Core (< 3.0, >= 1.5)
- GTMSessionFetcher/Core (1.7.2)
- IQKeyboardManagerSwift (6.5.11)
- JGProgressHUD (2.2)
- naveridlogin-sdk-ios (4.1.5)

DEPENDENCIES:
- GoogleSignIn (~> 5.0)
- IQKeyboardManagerSwift
- JGProgressHUD
- naveridlogin-sdk-ios

SPEC REPOS:
trunk:
- AppAuth
- GoogleSignIn
- GTMAppAuth
- GTMSessionFetcher
- IQKeyboardManagerSwift
- JGProgressHUD
- naveridlogin-sdk-ios

SPEC CHECKSUMS:
AppAuth: 8fca6b5563a5baef2c04bee27538025e4ceb2add
GoogleSignIn: 7137d297ddc022a7e0aa4619c86d72c909fa7213
GTMAppAuth: 0ff230db599948a9ad7470ca667337803b3fc4dd
GTMSessionFetcher: 5595ec75acf5be50814f81e9189490412bad82ba
IQKeyboardManagerSwift: c7955c0bdbf7b2eb29bb7daaa44e3d90f55a9a85
JGProgressHUD: d83d7a981b85d11205e19ff8ad5bb9c40571c847
naveridlogin-sdk-ios: 4351fe7162cd6b8b6dbb37bd7cc205304fa1d889

PODFILE CHECKSUM: b1c2d7472062cbb78bb5f4a1496c6b7905de1861
PODFILE CHECKSUM: 9c54f882dc5ba1f159bbd41025044f1fc34fe4c0

COCOAPODS: 1.11.3

0 comments on commit 8c3877c

Please sign in to comment.