Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ“ฎ ์นด์นด์˜ค oauth ์—ฐ๋™ #41

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}

}