Skip to content

Commit

Permalink
[Feat/#95] AuthRepository에 OAuth 처리 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HELLOHIDI committed Nov 2, 2024
1 parent 00324f7 commit fa55c94
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 38 deletions.
43 changes: 43 additions & 0 deletions HMH_Tuist_iOS/Projects/Data/Sources/Model/OAuthProviderType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// OAuthProviderType.swift
// Data
//
// Created by 류희재 on 11/2/24.
// Copyright © 2024 HMH-iOS. All rights reserved.
//

import Foundation

import Domain
import Networks

/**
- description: OAuth 서비스를 제공하는 제공자 종류
우리 서비스의 경우 Apple, Kakao 서비스 사용
*/

public enum OAuthProvider: OAuthProviderType {
case kakao
case apple

public var socialPlatform: String {
switch self {
case .kakao:
return "KAKAO"
case .apple:
return "APPLE"
}
}

public var service: OAuthServiceType {
switch self {
case .kakao:
return OAuthKakaoService()
case .apple:
return OAuthAppleService()
}
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ import Domain
import Networks

public struct AuthRepository: AuthRepositoryType {
private let service: AuthServiceType

init(service: AuthServiceType) {
self.service = service
private let authService: AuthServiceType
private let factory: (OAuthProviderType) -> OAuthServiceType

init(authService: AuthServiceType,
factory: @escaping (OAuthProviderType) -> OAuthServiceType
) {
self.authService = authService
self.factory = factory
}

public func authorize(_ serviceType: OAuthProviderType) -> AnyPublisher<String, Error> {
return factory(serviceType)
.authorize()
.map { $0 }
.mapToGeneralError()
}

public func signUp(socialPlatform: String, name: String, averageUseTime: String, problem: [String], challengeInfo: ChallengeInfo) -> AnyPublisher<Auth, Error> {
Expand All @@ -29,14 +41,16 @@ public struct AuthRepository: AuthRepositoryType {
),
challenge: challengeInfo.toDTO()
)
return service.signUp(request: request)

return authService.signUp(request: request)
.map { $0.toEntity() }
.mapToGeneralError()
}

public func socialLogin(socialPlatform: String) -> AnyPublisher<Auth, Error> {
let request = SocialLoginRequest(socialPlatform: socialPlatform)
return service.socialLogin(request: request)

return authService.socialLogin(request: request)
.map { $0.toEntity() }
.mapToGeneralError()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// OAuthProviderType.swift
// Domain
//
// Created by 류희재 on 11/2/24.
// Copyright © 2024 HMH-iOS. All rights reserved.
//

import Foundation

public protocol OAuthProviderType {
var socialPlatform: String { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public protocol AuthRepositoryType {
challengeInfo: ChallengeInfo
) -> AnyPublisher<Auth, Error>
func socialLogin(socialPlatform: String) -> AnyPublisher<Auth, Error>
func authorize(_ serviceType: OAuthProviderType) -> AnyPublisher<String, Error>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import Foundation
import AuthenticationServices
import Combine

final class OAuthAppleService: OAuthServiceType {

public final class OAuthAppleService: OAuthServiceType {
public init() {}

private let appleLoginManager = AppleLoginManager()

func authorize() -> AnyPublisher<String, HMHNetworkError.AuthError> {
public func authorize() -> AnyPublisher<String, HMHNetworkError.AuthError> {
return login()
.map { $0 }
.eraseToAnyPublisher()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
////
//// OAuthProviderType.swift
//// Networks
////
//// Created by 류희재 on 10/31/24.
//// Copyright © 2024 HMH-iOS. All rights reserved.
////
//
// OAuthProviderType.swift
// Networks
//import Foundation
//
// Created by 류희재 on 10/31/24.
// Copyright © 2024 HMH-iOS. All rights reserved.
///**
// - description: OAuth 서비스를 제공하는 제공자 종류
// 우리 서비스의 경우 Apple, Kakao 서비스 사용
// */
//
//enum OAuthProviderType: String, Hashable, CaseIterable {
// case kakao
// case apple
//
// var service: OAuthServiceType {
// switch self {
// case .kakao:
// return OAuthKakaoService()
// case .apple:
// return OAuthAppleService()
// }
// }
//}
//

import Foundation

/**
- description: OAuth 서비스를 제공하는 제공자 종류
우리 서비스의 경우 Apple, Kakao 서비스 사용
*/

enum OAuthProviderType: String, Hashable, CaseIterable {
case kakao
case apple

var service: OAuthServiceType {
switch self {
case .kakao:
return OAuthKakaoService()
case .apple:
return OAuthAppleService()
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import Combine

protocol OAuthServiceType {
public protocol OAuthServiceType {
func authorize() -> AnyPublisher<String, HMHNetworkError.AuthError>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import KakaoSDKAuth
import KakaoSDKUser
import Core

final class OAuthKakaoService: OAuthServiceType {
public final class OAuthKakaoService: OAuthServiceType {

public init() {}
let cancelBag = CancelBag()

func authorize() -> AnyPublisher<String, HMHNetworkError.AuthError> {
public func authorize() -> AnyPublisher<String, HMHNetworkError.AuthError> {
return login()
.map { $0.accessToken }
.eraseToAnyPublisher()
}

func login() -> Future<OAuthToken, HMHNetworkError.AuthError> {
private func login() -> Future<OAuthToken, HMHNetworkError.AuthError> {
return Future { promise in
let userApi = UserApi.shared

Expand Down

0 comments on commit fa55c94

Please sign in to comment.