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

160 Auth - 서버연동 #166

Merged
merged 68 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
6a45a21
💉:: [#160] transform 인자값 수정
jjunhaa0211 Feb 2, 2024
1571086
🍗:: [#160] 코드 리펙토링
jjunhaa0211 Feb 2, 2024
3c987bf
💉:: [#160] 컴플리트 버튼 색 변경
jjunhaa0211 Feb 2, 2024
7e20f1c
💉:: [#160] 컴플리트 버튼 타이틀 변경
jjunhaa0211 Feb 2, 2024
9932c50
🏃:: [#160] 파일 구조 및 이름 변경
jjunhaa0211 Feb 2, 2024
4eaf623
💉:: [#160] MG+Label numberOfLineCount 추가
jjunhaa0211 Feb 2, 2024
46917e4
🍗:: [#160] 코드 리펙토링
jjunhaa0211 Feb 2, 2024
848333d
💉:: [#160] ProfileType 변경
jjunhaa0211 Feb 2, 2024
36cd261
🎮:: [#160] introProfile 추가
jjunhaa0211 Feb 2, 2024
3972049
⚓️:: [#160] introViewController 추가
jjunhaa0211 Feb 2, 2024
a17a7d9
⚓️:: [#160] APIType 추가
jjunhaa0211 Feb 2, 2024
15f5858
🚫:: [#160] 더미 파일 삭제
jjunhaa0211 Feb 2, 2024
0ac1fc2
⚓️:: [#160] BaseAPI 추가
jjunhaa0211 Feb 2, 2024
8682c28
🍗:: [#160] BaseURL 리펙토링
jjunhaa0211 Feb 3, 2024
a8beba0
💉:: [#161] goolge Oauth 기반 info 설정
jjunhaa0211 Feb 5, 2024
9189029
🔀:: #162 from MaeumgaGym/feature/#161-makeGoogleOAuth
jjunhaa0211 Feb 5, 2024
d61c9b4
➕:: [#164] KakaoSDK 추가
jjunhaa0211 Feb 5, 2024
5c485f2
➕:: [#164] kakao sdk 의존성 추가
jjunhaa0211 Feb 5, 2024
be034f0
⚓️:: [#164] testViewController 추가
jjunhaa0211 Feb 5, 2024
2e56d85
⚓️:: [#164] Editor 추가
jjunhaa0211 Feb 5, 2024
347a3f5
🎮:: [#164] 카카오 API 호출 준비 설정
jjunhaa0211 Feb 5, 2024
9b18c0a
💉:: [#164] token 받는 코드 추가
jjunhaa0211 Feb 5, 2024
5d827c5
🚫:: [#164] 안쓰는 코드 삭제
jjunhaa0211 Feb 5, 2024
6a7f4eb
⚓️:: [#164] AuthService 추가
jjunhaa0211 Feb 5, 2024
c607d32
⚓️:: [#164] AuthViewControllable 추가
jjunhaa0211 Feb 5, 2024
c4e7502
⚓️:: [#164] ViewModel 추가
jjunhaa0211 Feb 5, 2024
1966ed5
⚓️:: [#164] IntroViewController viewModel 추가
jjunhaa0211 Feb 5, 2024
4104834
⚓️:: [#164] AuthUseCase 추가
jjunhaa0211 Feb 5, 2024
1dcd135
⚓️:: [#164] AuthError 코드 추가
jjunhaa0211 Feb 5, 2024
067b259
⚓️:: [#164] AuthRepositoryInterface 추가
jjunhaa0211 Feb 5, 2024
ed9200a
⚓️:: [#164] AuthRepository 추가
jjunhaa0211 Feb 5, 2024
ca24ff9
💉:: [#164] usecaes로 로직 숨기기
jjunhaa0211 Feb 5, 2024
fab283f
🍗:: [#164] 안쓰는 코드 정리
jjunhaa0211 Feb 5, 2024
6ce1fcf
🔀:: #165 from MaeumgaGym/feature/#164-makeKakaoOAuth
jjunhaa0211 Feb 5, 2024
0e1f7c5
🚫:: [#160] 안쓰는 코드 삭제
jjunhaa0211 Feb 6, 2024
ef5a30a
⚓️:: [#160] LoggingPlugin 추가
jjunhaa0211 Feb 6, 2024
65247b4
⚓️:: [#160] baseAPI 추가
jjunhaa0211 Feb 6, 2024
e99a4a3
💉:: [#160] APIType csrf 추가
jjunhaa0211 Feb 6, 2024
9ced2e6
⚓️:: [#160] CsrfAPI 추가
jjunhaa0211 Feb 6, 2024
811513b
🎮:: [#160] viewmodel 테스트 로직
jjunhaa0211 Feb 6, 2024
18ddded
⚓️:: [#160] token 에러 케이스 추가
jjunhaa0211 Feb 6, 2024
f9c1883
🚫:: [#160] 안쓰는 코드 삭제
jjunhaa0211 Feb 6, 2024
ca498a9
⚓️:: [#160] TokenManager 프로토콜 추가
jjunhaa0211 Feb 6, 2024
b4030f2
🚫:: [#160] 안쓰는 코드 삭제
jjunhaa0211 Feb 6, 2024
f263b29
💉:: [#160] BaseFeatureDependency 추가
jjunhaa0211 Feb 6, 2024
ce92642
⚓️:: BaseFeatureDependency 추가
jjunhaa0211 Feb 6, 2024
25ba1d5
⚓️:: [#160] KeychainType 추가
jjunhaa0211 Feb 6, 2024
4049b1b
⚓️:: [#160] TokenManager 프로토콜 추가
jjunhaa0211 Feb 6, 2024
3d7a407
⚓️:: [#160] KeychainType 추가
jjunhaa0211 Feb 6, 2024
6ed28e5
⚓️:: [#160] TokenManagerImpl 추가
jjunhaa0211 Feb 6, 2024
6219241
💉:: [#160] baseAPI 수정
jjunhaa0211 Feb 6, 2024
605faaa
⚓️:: [#160] KakaoAPI 추가
jjunhaa0211 Feb 6, 2024
e225339
⚓️:: [#160] CsrfAPI 추가
jjunhaa0211 Feb 6, 2024
b16a98b
🏃:: [#160] 잘못된 이름 변경
jjunhaa0211 Feb 6, 2024
deff48c
💉:: [#160] AuthRepository 추가
jjunhaa0211 Feb 6, 2024
6c65ef4
💉:: [#160] AuthRepository 추가
jjunhaa0211 Feb 6, 2024
1c0d76c
💉:: [#160] requestSignIn interface 추가
jjunhaa0211 Feb 6, 2024
fdc9761
💉:: [#160] AuthUseCase 로직 강화
jjunhaa0211 Feb 6, 2024
76bf984
💉:: [#160] token 매니저 추가
jjunhaa0211 Feb 6, 2024
e59340a
💉:: [#160] 서버 연동 추가
jjunhaa0211 Feb 6, 2024
efd3a51
⚓️:: [#160] 코드 변경
jjunhaa0211 Feb 6, 2024
55a0b5b
💉:: [#160] flow 기반 설정
jjunhaa0211 Feb 6, 2024
bd6d719
🚫:: [#160] 안쓰는 코드 삭제
jjunhaa0211 Feb 7, 2024
c41a579
🚫:: [#160] 안쓰는 코드 삭제
jjunhaa0211 Feb 7, 2024
942249f
🚫:: [#160] 안쓰는 주석제거
jjunhaa0211 Feb 7, 2024
2848152
💉:: [#160] action 추가 코드로 변경
jjunhaa0211 Feb 7, 2024
042c89e
💉:: [#160] token 코드 살리기
jjunhaa0211 Feb 7, 2024
013d081
💉:: [#160] 한국어로 패치
jjunhaa0211 Feb 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public extension TargetDependency.SPM {
static let Lottie = TargetDependency.external(name: "Lottie")
static let kingfisher = TargetDependency.external(name: "Kingfisher")
static let MindGymKit = TargetDependency.external(name: "MindGymKit")
static let KakaoSDK = TargetDependency.external(name: "KakaoSDK")
}

39 changes: 33 additions & 6 deletions Plugins/EnvPlugin/ProjectDescriptionHelpers/InfoPlists.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,24 @@ public extension Project {
"CFBundleURLTypes": [
[
"CFBundleTypeRole": "Editor",
"CFBundleURLName": "maeumGaGym-makers",
"CFBundleURLSchemes": ["maeumGaGym-makers"]
"CFBundleURLName": "kakao44df4ecfe4e1218c17550a6ab201d87d",
"CFBundleURLSchemes": ["kakao44df4ecfe4e1218c17550a6ab201d87d"]
]
],
"UIBackgroundModes": ["remote-notification"]
"UIBackgroundModes": ["remote-notification"],

"LSApplicationQueriesSchemes": [
"kakaokompassauth",
"kakaolink",
"kakaoplus"
],

// "GoogleService-Info": .dictionary([
// "CLIENT_ID": .string("49794141515-9gnqemglgiapma28nphc3oabfclbobem.apps.googleusercontent.com"),
// "REVERSED_CLIENT_ID": .string("com.googleusercontent.apps.49794141515-9gnqemglgiapma28nphc3oabfclbobem"),
// "PLIST_VERSION": .string("1"),
// "BUNDLE_ID": .string("com.maeumGaGym-health-iOS"),
// ]),
]

static let demoInfoPlist: [String: InfoPlist.Value] = [
Expand Down Expand Up @@ -83,10 +96,24 @@ public extension Project {
"CFBundleURLTypes": [
[
"CFBundleTypeRole": "Editor",
"CFBundleURLName": "maeumGaGym-makers",
"CFBundleURLSchemes": ["maeumGaGym-makers"]
"CFBundleURLName": "kakao44df4ecfe4e1218c17550a6ab201d87d",
"CFBundleURLSchemes": ["kakao44df4ecfe4e1218c17550a6ab201d87d"]
]
],
"UIBackgroundModes": ["remote-notification"]

"UIBackgroundModes": ["remote-notification"],

"LSApplicationQueriesSchemes": [
"kakaokompassauth",
"kakaolink",
"kakaoplus"
],

// "GoogleService-Info": .dictionary([
// "CLIENT_ID": .string("49794141515-9gnqemglgiapma28nphc3oabfclbobem.apps.googleusercontent.com"),
// "REVERSED_CLIENT_ID": .string("com.googleusercontent.apps.49794141515-9gnqemglgiapma28nphc3oabfclbobem"),
// "PLIST_VERSION": .string("1"),
// "BUNDLE_ID": .string("com.maeumGaGym-health-iOS.test"),
// ]),
]
}
31 changes: 31 additions & 0 deletions Projects/Data/Sources/Repository/AuthRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import UIKit

import RxSwift
import RxCocoa

import Moya
import RxMoya

import Domain
import MGNetworks

public class AuthRepository: AuthRepositoryInterface {

private let networkService: AuthService

public init(networkService: AuthService) {
self.networkService = networkService
}

public func requestSignIn(token: String) -> Single<Bool> {
return networkService.requestToken()
}

public func kakaoToken(access_token: String) -> Single<String> {
networkService.kakaoTokenState(access_token: access_token)
}

public func getCSRFToken() -> Single<String> {
return networkService.getCSRFToken()
}
}
8 changes: 0 additions & 8 deletions Projects/Data/Sources/Repository/HomeRepository.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// HomeRepository.swift
// Data
//
// Created by 박준하 on 1/30/24.
// Copyright © 2024 MaeumGaGym-iOS. All rights reserved.
//

import Foundation
import RxSwift

Expand Down
24 changes: 24 additions & 0 deletions Projects/Domain/Sources/Error/Auth/AuthError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Foundation

public enum AuthError: Error {
case unknown
case googleSignInFailed
case appleSignInFailed
case kakaoSignInFailed
case tokenNotFound

var localizedDescription: String {
switch self {
case .unknown:
return "알 수 없는 오류가 발생했습니다."
case .googleSignInFailed:
return "Google 로그인에 실패했습니다."
case .appleSignInFailed:
return "Apple 로그인에 실패했습니다."
case .kakaoSignInFailed:
return "Kakao 로그인에 실패했습니다."
case .tokenNotFound:
return "토큰을 찾을 수 없습니다"
}
}
}
1 change: 0 additions & 1 deletion Projects/Domain/Sources/Error/dummy1.swift

This file was deleted.

13 changes: 13 additions & 0 deletions Projects/Domain/Sources/Model/Auth/User.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import UIKit

public struct User {
let id: String
let name: String
let accessToken: String

public init(id: String, name: String, accessToken: String) {
self.id = id
self.name = name
self.accessToken = accessToken
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import UIKit

import RxSwift
import RxCocoa

public protocol AuthRepositoryInterface {
func requestSignIn(token: String) -> Single<Bool>
func kakaoToken(access_token: String) -> Single<String>
func getCSRFToken() -> Single<String>
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// HomeRepositoryInterface.swift
// Domain
//
// Created by 박준하 on 1/30/24.
// Copyright © 2024 MaeumGaGym-iOS. All rights reserved.
//

import UIKit

import RxSwift
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import RxSwift

public protocol SignInRepositoryInterface {
func requestSignIn(token: String) -> Single<Bool>
}
83 changes: 83 additions & 0 deletions Projects/Domain/Sources/UseCase/AuthUseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import UIKit

import RxSwift
import RxCocoa

import Core
import KakaoSDKUser
import Moya

import TokenManager

public enum AuthHandleableType {
case loginSuccess
case loginFailure
}

public protocol AuthUseCase {
func requestSignIn(token: String)
func kakaoButtonTap()
func getCSRFToken() -> Single<String>
var signInResult: PublishSubject<Result<AuthHandleableType, Error>> { get }
}

public class DefaultAuthUseCase {
private let authRepository: AuthRepositoryInterface
private let disposeBag = DisposeBag()

private let keychainAuthorization = KeychainType.authorizationToken


public init(authRepository: AuthRepositoryInterface) {
self.authRepository = authRepository
}
}

extension DefaultAuthUseCase: AuthUseCase {


public func getCSRFToken() -> Single<String> {
return authRepository.getCSRFToken()
}

public func kakaoButtonTap() {
if (UserApi.isKakaoTalkLoginAvailable()) {
UserApi.shared.loginWithKakaoTalk { [weak self] (oauthToken, error) in
if let error = error {
print(error)
} else {
guard let self = self, let accessToken = oauthToken?.accessToken else { return }

self.authRepository.kakaoToken(access_token: accessToken)
.subscribe(onSuccess: { [weak self] _ in
guard let self = self else { return }
if TokenManagerImpl().save(token: accessToken, with: self.keychainAuthorization) {
print("토큰 저장 성공")
} else {
print("토큰 저장 실패")
}
self.signInResult.onNext(.success(.loginSuccess))
}, onFailure: { [weak self] error in
self?.signInResult.onNext(.failure(error))
})
.disposed(by: self.disposeBag)
}
}
}
}

public func requestSignIn(token: String) {
authRepository.requestSignIn(token: token)
.subscribe(onSuccess: { [weak self] _ in
self?.signInResult.onNext(.success(.loginSuccess))
print("성공")
}, onFailure: { [weak self] error in
self?.signInResult.onNext(.failure(error))
})
.disposed(by: disposeBag)
}

public var signInResult: PublishSubject<Result<AuthHandleableType, Error>> {
return PublishSubject<Result<AuthHandleableType, Error>>()
}
}
8 changes: 0 additions & 8 deletions Projects/Domain/Sources/UseCase/HomeUseCase.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
////
//// HomeUseCase.swift
//// Domain
////
//// Created by 박준하 on 1/30/24.
//// Copyright © 2024 MaeumGaGym-iOS. All rights reserved.
////
//
import UIKit
import RxSwift
import RxCocoa
Expand Down
34 changes: 0 additions & 34 deletions Projects/Features/AuthFeature/Demo/Sources/AppDelegate.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import UIKit
import KakaoSDKAuth

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
if (AuthApi.isKakaoTalkLoginUrl(url)) {
return AuthController.handleOpenUrl(url: url)
}

return false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import UIKit
import AuthFeatureInterface
import RxFlow
import Core
import AuthFeature

import Domain
import Data

import MGNetworks

import KakaoSDKAuth
import KakaoSDKCommon

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let url = URLContexts.first?.url {
if (AuthApi.isKakaoTalkLoginUrl(url)) {
_ = AuthController.handleOpenUrl(url: url)
}
}
}

func scene(_ scene: UIScene,
willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
KakaoSDK.initSDK(appKey: "44df4ecfe4e1218c17550a6ab201d87d")

guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)

let useCase = DefaultAuthUseCase(authRepository: AuthRepository(networkService: AuthService()))
let viewModel = IntroViewModel(authUseCase: useCase)
let viewController = IntroViewController(viewModel)
window?.configure(withRootViewController: viewController)
window?.makeKeyAndVisible()
}

// private func coordinatorLogStart() {
// coordinator.rx.willNavigate
// .subscribe(onNext: { flow, step in
// let currentFlow = "\(flow)".split(separator: ".").last ?? "no flow"
// print("➡️ will navigate to flow = \(currentFlow) and step = \(step)")
// })
// .disposed(by: disposeBag)
//
// // didNavigate
// }
}
Loading