Skip to content

Commit

Permalink
Merge pull request #41 from KCY-Fit-a-Pet/feat/12
Browse files Browse the repository at this point in the history
카카오 로그인 구현
  • Loading branch information
psychology50 authored Dec 9, 2023
2 parents 587ff72 + fdde306 commit 1387184
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 24 deletions.
Binary file not shown.
13 changes: 13 additions & 0 deletions fit-a-pet-client/fit-a-pet-client/API/AlamofireManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,18 @@ class AlamofireManager {
}
}
}
func kakaoCodeGet(completion: @escaping(Result<Data?, Error>) -> Void){
os_log("MyAlamofireManager - kakaoCodeGet() called userInput : ", log: .default, type: .info)

self.session.request(MySearchRouter.kakaoCode)
.response { response in
switch response.result {
case .success(let data):
completion(.success(data))
case .failure(let error):
completion(.failure(error))
}
}
}
}

15 changes: 12 additions & 3 deletions fit-a-pet-client/fit-a-pet-client/API/MySearchRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ enum MySearchRouter: URLRequestConvertible {
case sendAuthSms(to: String)
case checkAuthSms(to: String, code: String)
case findId(phone: String, code: String)
case kakaoCode

var baseURL: URL {
switch self {
case .presignedurl:
return URL(string: API.PRESIGNEDURL)!
case .uploadImage:
return URL(string: PAYLOADURL.PAYLOAD)!
case .kakaoCode:
return URL(string: "https://kauth.kakao.com/oauth/authorize")!
default:
return URL(string: API.BASE_URL)!
}
Expand All @@ -31,6 +34,8 @@ enum MySearchRouter: URLRequestConvertible {
switch self {
case .sendSms, .checkSms, .login, .regist, .presignedurl, .registPet,.sendAuthSms, .checkAuthSms, .findId:
return .post
case .kakaoCode:
return .get
case .uploadImage:
return .put
}
Expand All @@ -46,8 +51,8 @@ enum MySearchRouter: URLRequestConvertible {
return "auth/register"
case .presignedurl:
return "C7QXbC20ti"
case .uploadImage:
return ""
case .uploadImage, .kakaoCode:
return " "
case .registPet:
return "pets"
case .sendAuthSms, .checkAuthSms:
Expand All @@ -71,7 +76,7 @@ enum MySearchRouter: URLRequestConvertible {
return ["uid": uid, "name": name, "password": password, "email": email, "profileImg": profileImg]
case let .presignedurl(dirname, extensionType, _, _):
return ["dirname": dirname, "extension": extensionType]
case .uploadImage(_):
case .uploadImage(_), .kakaoCode:
return [:]
case let .registPet(petName , species , gender , neutralization , birthDate):
return ["petName": petName, "species": species, "gender": gender, "neutralization": neutralization, "birthDate": birthDate]
Expand Down Expand Up @@ -150,6 +155,10 @@ enum MySearchRouter: URLRequestConvertible {

request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters)

case .kakaoCode:
let queryParameters = [URLQueryItem(name: "client_id", value: "bbe38742c0998fecfaaaaaef6856fc32"),URLQueryItem(name: "redirect_uri", value: "kakaobbe38742c0998fecfaaaaaef6856fc32://oauth"), URLQueryItem(name: "response_type", value: "code")]

request = createURLRequestWithQuery(url: baseURL, queryParameters: queryParameters)
default:
request = createURLRequestWithBody(url: url)
}
Expand Down
8 changes: 7 additions & 1 deletion fit-a-pet-client/fit-a-pet-client/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@

import UIKit
import KakaoSDKCommon
import GoogleSignIn

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

KakaoSDK.initSDK(appKey: "cb3b8424b15113ff21c17cb00a1299d1")
KakaoSDK.initSDK(appKey: "bbe38742c0998fecfaaaaaef6856fc32")

return true
}


func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
return GIDSignIn.sharedInstance.handle(url)
}

// MARK: UISceneSession Lifecycle

Expand Down
20 changes: 15 additions & 5 deletions fit-a-pet-client/fit-a-pet-client/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
<string>kakaocb3b8424b15113ff21c17cb00a1299d1</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.911385367064-8ual2h4bmk98fdi87kgbhigosp50dd5t</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>kakaokompassauth</string>
<string>kakaolink</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
Expand All @@ -35,10 +48,7 @@
</array>
</dict>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>kakaokompassauth</string>
<string>kakaolink</string>
</array>
<key>GIDClientID</key>
<string>911385367064-8ual2h4bmk98fdi87kgbhigosp50dd5t.apps.googleusercontent.com</string>
</dict>
</plist>
59 changes: 44 additions & 15 deletions fit-a-pet-client/fit-a-pet-client/ViewControllers/FirstVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import UIKit
import SnapKit
import KakaoSDKAuth
import KakaoSDKUser
import GoogleSignIn
import Alamofire

class FirstVC: UIViewController {

Expand All @@ -28,6 +30,7 @@ class FirstVC: UIViewController {
setLoginViewStyle()
}
}

extension FirstVC{

private func setMainTextLabelStyle(){
Expand Down Expand Up @@ -59,11 +62,6 @@ extension FirstVC{

}
}

@objc func changeSignUpVC(_ sender: UIButton){
let nextVC = InputPhoneNumVC()
self.navigationController?.pushViewController(nextVC, animated: false)
}

private func setLoginBtnStyle(){
self.view.addSubview(loginBtn)
Expand All @@ -86,12 +84,6 @@ extension FirstVC{
}
}

@objc func changeLoginVC(_ sender: UIButton){
let nextVC = LoginVC()
//guard let nextVC = self.storyboard?.instantiateViewController(identifier: "LoginVC") else { return }
self.navigationController?.pushViewController(nextVC, animated: false)
}

private func setLoginViewStyle() {
let loginLabel = UILabel()
loginLabel.text = "혹은 간편 로그인"
Expand All @@ -115,6 +107,7 @@ extension FirstVC{


kakaoLogin.addTarget(self, action: #selector(kakaoLoginBtnTapped(_:)), for: .touchUpInside)
googleLogin.addTarget(self, action: #selector(googleLoginBtnTapped(_ :)), for: .touchUpInside)

let loginButtons = [naverLogin, kakaoLogin, googleLogin, appleLogin]

Expand Down Expand Up @@ -164,22 +157,58 @@ extension FirstVC{
make.height.equalTo(60)
}
}
}

extension FirstVC{
@objc func kakaoLoginBtnTapped(_ sender: UIButton){
print("touch")

UserApi.shared.loginWithKakaoAccount {(oauthToken, error) in

if let error = error {
print(error)
}
else {
print("loginWithKakaoAccount() success.")

_ = oauthToken
}
}
}
@objc func googleLoginBtnTapped(_ sender: UIButton){
GIDSignIn.sharedInstance.signIn(
withPresenting: self) { signInResult, error in
guard error == nil else { return }
guard let signInResult = signInResult else { return }

let user = signInResult.user
let emailAddress = user.profile?.email
let fullName = user.profile?.name
let profilePicUrl = user.profile?.imageURL(withDimension: 320)

print("user: \(user)")
print("emailAddress: \(String(describing: emailAddress))")
print("fullName: \(String(describing: fullName))")
print("profileUrl: \(String(describing: profilePicUrl))")

signInResult.user.refreshTokensIfNeeded { user, error in
guard error == nil else { return }
guard let user = user else { return }

let idToken = user.idToken

print("idToken: \(String(describing: idToken))")
}
}
}

@objc func changeSignUpVC(_ sender: UIButton){
let nextVC = InputPhoneNumVC()
self.navigationController?.pushViewController(nextVC, animated: false)
}

@objc func changeLoginVC(_ sender: UIButton){
let nextVC = LoginVC()
self.navigationController?.pushViewController(nextVC, animated: false)
}

}

0 comments on commit 1387184

Please sign in to comment.