Skip to content

Commit

Permalink
[Feat] #468 - apple getIdentityToken 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
meltsplit committed Jan 18, 2025
1 parent 6aa9eba commit 1d8d045
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
//
// CoreAuthRepository.swift
// CoreOAuthRepository.swift
// Data
//
// Created by 장석우 on 1/18/25.
// Copyright © 2025 SOPT-iOS. All rights reserved.
//

import Combine
import Foundation

import Domain
import Networks

public class CoreOAuthRepository {

private let appleService: AuthenticationService
// private let googleService:

public init(appleService: AuthenticationService) {
self.appleService = appleService
}
}

extension CoreOAuthRepository: CoreOAuthRepositoryInterface {
public func getIdentityToken(from provider: OAuthType) -> AnyPublisher<String, Domain.CoreAuthError> {
switch provider {
case .apple: return appleService.getIdentityToken()
case .google: fatalError() //TODO:
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class SignInRepository {

private let authService: AuthService
private let userService: UserService

private let cancelBag = CancelBag()

public init(authService: AuthService, userService: UserService) {
Expand All @@ -28,6 +29,7 @@ public class SignInRepository {
}

extension SignInRepository: SignInRepositoryInterface {

public func requestSignIn(token: String) -> AnyPublisher<Bool, Error> {
return authService.signIn(token: token)
.catch ({ error in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ extension AppDelegate {
)
}
)

container.register(
interface: CoreOAuthRepositoryInterface.self,
implement: {
CoreOAuthRepository(appleService: DefaultAppleAuthenticationService())
}
)

container.register(
interface: SplashRepositoryInterface.self,
implement: {
SplashRepository(service: DefaultFirebaseService())
}
)

container.register(
interface: MainRepositoryInterface.self,
implement: {
Expand Down
16 changes: 16 additions & 0 deletions SOPT-iOS/Projects/Domain/Sources/Error/CoreAuthError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,19 @@
//

import Foundation

public enum CoreAuthError: Error {
case apple(Apple)
case google(Google)
case unknown(Error)

public enum Apple: Error {
case authFail(Error)
case credentialFail
case encodedFail
}

public enum Google: Error {

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// CoreAuthRepository.swift
// CoreOAuthRepositoryInterface.swift
// Domain
//
// Created by 장석우 on 1/18/25.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import Combine

// TODO: - User 유형 설정 방식 생각하기

public protocol SignInRepositoryInterface {
func requestSignIn(token: String) -> AnyPublisher<Bool, Error>
}
18 changes: 17 additions & 1 deletion SOPT-iOS/Projects/Domain/Sources/UseCase/SignInUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,25 @@ public enum SiginInHandleableType {

public protocol SignInUseCase {
func requestSignIn(token: String)
func login(with provider: OAuthType) -> AnyPublisher<String, Never>
var signInSuccess: CurrentValueSubject<SiginInHandleableType, Error> { get set }
}

public class DefaultSignInUseCase {

private let repository: SignInRepositoryInterface
private let oauthRepository: CoreOAuthRepositoryInterface

private var cancelBag = CancelBag()

public var signInSuccess = CurrentValueSubject<SiginInHandleableType, Error>(.loginFailure)

public init(repository: SignInRepositoryInterface) {
public init(
repository: SignInRepositoryInterface,
oauthRepository: CoreOAuthRepositoryInterface
) {
self.repository = repository
self.oauthRepository = oauthRepository
}
}

Expand All @@ -46,4 +54,12 @@ extension DefaultSignInUseCase: SignInUseCase {
self.signInSuccess.send(isSuccessed ? .loginSuccess : .loginFailure)
}.store(in: self.cancelBag)
}

public func login(with provider: OAuthType) -> AnyPublisher<String, Never> {
oauthRepository.getIdentityToken(from: .apple)
.catch { _ in
return Empty<String, Never>()
}
.eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import Domain
public
final class AuthBuilder {
@Injected public var repository: SignInRepositoryInterface
@Injected public var oauthRepository: CoreOAuthRepositoryInterface

public init() { }
}

extension AuthBuilder: AuthFeatureViewBuildable {

public func makeSignIn() -> SignInPresentable {
let useCase = DefaultSignInUseCase(repository: repository)
let useCase = DefaultSignInUseCase(repository: repository, oauthRepository: oauthRepository)
let vm = SignInViewModel(useCase: useCase)
let vc = SignInVC()
vc.viewModel = vm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,13 @@ extension SignInViewModel {
UserDefaultKeyList.clearUserData()
}.store(in: self.cancelBag)

input.googleLoginButtonTapped
Publishers.Merge(
input.googleLoginButtonTapped.map { OAuthType.google },
input.appleLoginButtonTapped.map { OAuthType.apple }
).flatMap(useCase.login)
.withUnretained(self)
.sink { owner, _ in
owner.onSocialLoginFail?() //TODO: 구글 로그인 로직
}.store(in: self.cancelBag)

input.appleLoginButtonTapped
.withUnretained(self)
.sink { owner, _ in
owner.onSocialLoginFail?() //TODO: 애플 로그인 로직
.sink { owner, id in
print(id)
}.store(in: self.cancelBag)

input.signUpButtonTapped
Expand Down
4 changes: 4 additions & 0 deletions SOPT-iOS/Projects/SOPT-iOS/SOPT-iOS.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ extension AppDelegate {
)
}
)

container.register(
interface: CoreOAuthRepositoryInterface.self,
implement: {
CoreOAuthRepository(appleService: DefaultAppleAuthenticationService())
}
)

container.register(
interface: SplashRepositoryInterface.self,
implement: {
Expand Down

0 comments on commit 1d8d045

Please sign in to comment.