Skip to content
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
8 changes: 0 additions & 8 deletions Application/App/Sources/App/Delegate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
private let logger = Logger(category: "AppDelegate")
private let container = AppDIContainer.shared

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

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
Expand Down
3 changes: 0 additions & 3 deletions Application/App/Sources/Resource/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>$(REVERSED_CLIENT_ID)</string>
<string>DevLog</string>
</array>
</dict>
Expand All @@ -48,8 +47,6 @@
<string>$(FIRESTORE_DATABASE_ID)</string>
<key>FUNCTION_API_BASE_URL</key>
<string>$(FUNCTION_API_BASE_URL)</string>
<key>GIDClientID</key>
<string>$(CLIENT_ID)</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationCategoryType</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ private actor UserServiceSpy: UserService {
private final class AuthServiceSpy: AuthService {
var uid: String?
let providerIDs = [String]()
let currentUserEmail: String? = nil
let providerCount = 0
private let subject = PassthroughSubject<Bool, Never>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ private actor UserServiceSpy: UserService {
private final class AuthServiceSpy: AuthService {
var uid: String?
let providerIDs = [String]()
let currentUserEmail: String? = nil
let providerCount = 0
private let subject = PassthroughSubject<Bool, Never>()

Expand Down
1 change: 0 additions & 1 deletion Application/Data/Sources/Protocol/AuthService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Foundation
public protocol AuthService {
var uid: String? { get }
var providerIDs: [String] { get }
var currentUserEmail: String? { get }
var providerCount: Int { get }

func observeSignedIn() -> AnyPublisher<Bool, Never>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public protocol AuthenticationService {
func signIn() async throws -> AuthDataResponse?
func signOut(_ uid: String) async throws
func deleteAuth(_ uid: String) async throws
func link(uid: String, email: String) async throws -> Bool
func link(uid: String) async throws -> Bool
func unlink(_ uid: String) async throws
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ final class AuthDataRepositoryImpl: AuthDataRepository {
}

func linkProvider(_ provider: AuthProvider) async throws -> Bool {
guard let uid = authService.uid,
let email = authService.currentUserEmail else {
guard let uid = authService.uid else {
throw AuthError.notAuthenticated
}

Expand All @@ -54,7 +53,7 @@ final class AuthDataRepositoryImpl: AuthDataRepository {
}

do {
return try await service.link(uid: uid, email: email)
return try await service.link(uid: uid)
} catch {
throw mapLinkError(error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ final class AuthenticationRepositoryImpl: AuthenticationRepository {
widgetSnapshotUpdater.clear()
}

func restore() -> Bool {
// MARK: 후에 Google API를 사용 시 Google만의 restorePreviousSignIn 로직 추가
return authService.uid != nil
}

func delete() async throws {
guard let uid = authService.uid else {
throw AuthError.notAuthenticated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ struct AuthDataRepositoryImplTests {
uid: "user-id",
providerID: "apple.com",
providerIDs: ["apple.com", "google.com"],
currentUserEmail: "apple@example.com",
providerCount: providerCount,
events: events
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,19 @@ final class AuthenticationRepositoryAuthServiceSpy: AuthService {

var uid: String?
let providerIDs: [String]
let currentUserEmail: String?
let providerCount: Int

init(
uid: String?,
providerID: String?,
providerIDs: [String],
currentUserEmail: String? = nil,
providerCount: Int? = nil,
deleteCurrentUserError: Error? = nil,
events: AuthenticationRepositoryEventRecorder
) {
self.uid = uid
self.providerID = providerID
self.providerIDs = providerIDs
self.currentUserEmail = currentUserEmail
self.providerCount = providerCount ?? providerIDs.count
self.deleteCurrentUserError = deleteCurrentUserError
self.events = events
Expand Down Expand Up @@ -263,7 +260,7 @@ actor AuthenticationServiceSpy: AuthenticationService {
events.record("\(provider).deleteAuth")
}

func link(uid: String, email: String) async throws -> Bool {
func link(uid: String) async throws -> Bool {
events.record("\(provider).link")
return try linkResult.get()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ private final class WebPageRepositoryAuthServiceSpy: AuthService {

var uid: String?
var providerIDs: [String] { [] }
var currentUserEmail: String? { nil }
var providerCount: Int { 0 }

init(uid: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ import Foundation
public protocol AuthenticationRepository {
func signIn(_ provider: AuthProvider) async throws -> Bool
func signOut() async throws
func restore() -> Bool
func delete() async throws
}
13 changes: 1 addition & 12 deletions Application/Infra/Sources/Common/InfraLayerError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import AuthenticationServices
import Foundation
import Data

enum FirestoreError: Error, LocalizedError {
case dataNotFound(_ key: String)
Expand All @@ -20,16 +19,7 @@ enum FirestoreError: Error, LocalizedError {
}
}

enum UIError: Error {
case notFoundTopViewController
}

enum TokenError: Error {
case invalidResponse
}

enum SocialLoginError: Error {
case invalidOAuthState
case invalidOAuthCallback
case failedToStartWebAuthenticationSession
case authenticationAlreadyInProgress
Expand All @@ -43,8 +33,7 @@ extension Error {
case let webAuthError as ASWebAuthenticationSessionError:
return webAuthError.code == .canceledLogin
default:
let nsError = self as NSError
return nsError.domain == "com.google.GIDSignIn" && nsError.code == -5
return false
}
}
}
47 changes: 0 additions & 47 deletions Application/Infra/Sources/Common/TopViewControllerProvider.swift

This file was deleted.

4 changes: 0 additions & 4 deletions Application/Infra/Sources/Service/AuthServiceImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ final class AuthServiceImpl: AuthService {
Auth.auth().currentUser?.providerData.map { $0.providerID } ?? []
}

var currentUserEmail: String? {
Auth.auth().currentUser?.email
}

var providerCount: Int {
Auth.auth().currentUser?.providerData.count ?? 0
}
Expand Down
14 changes: 4 additions & 10 deletions Application/Infra/Sources/Service/FunctionAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,12 @@ private enum FunctionAPIErrorCode: String {
case emailMismatch = "email-mismatch"
case githubEmailConflict = "github-email-changed-account-conflict"
case appleProviderLinkConflict = "apple-provider-link-conflict"
case googleProviderLinkConflict = "google-provider-link-conflict"
case lastProvider = "last-provider"
}

enum AppleAuthenticationAPIError: Error, Equatable {
case providerLinkConflict
}

enum AuthenticationAPIError: Error, Equatable {
case providerLinkConflict
case lastProvider
}

Expand All @@ -174,8 +172,8 @@ struct FunctionAPIServerErrorDecoder: NXServerErrorDecoder {
return EmailError.mismatch
case .githubEmailConflict:
return EmailError.githubEmailConflict
case .appleProviderLinkConflict:
return AppleAuthenticationAPIError.providerLinkConflict
case .appleProviderLinkConflict, .googleProviderLinkConflict:
return AuthenticationAPIError.providerLinkConflict
case .lastProvider:
return AuthenticationAPIError.lastProvider
}
Expand All @@ -197,10 +195,6 @@ extension Error {
functionAPIUnderlyingError as? EmailError
}

var apiAppleAuthenticationError: AppleAuthenticationAPIError? {
functionAPIUnderlyingError as? AppleAuthenticationAPIError
}

var apiAuthenticationError: AuthenticationAPIError? {
functionAPIUnderlyingError as? AuthenticationAPIError
}
Expand Down
12 changes: 12 additions & 0 deletions Application/Infra/Sources/Service/FunctionAPIEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ extension FunctionAPIEndpoint where Response == EmptyAPIResponse {
static let revokeGithubAccessToken = Self(method: .delete, path: "/auth/github/access-token")
static let linkGithubAccount = Self(method: .put, path: "/auth/github/account-link")
static let unlinkGithubAccount = Self(method: .delete, path: "/auth/github/account-link")
static let revokeGoogleAccessToken = Self(method: .delete, path: "/auth/google/access-token")
static let linkGoogleAccount = Self(method: .put, path: "/auth/google/account-link")
static let unlinkGoogleAccount = Self(method: .delete, path: "/auth/google/account-link")
static let linkAppleAccount = Self(method: .put, path: "/auth/apple/account-link")
static let unlinkAppleAccount = Self(method: .delete, path: "/auth/apple/account-link")
static let revokeAppleAccessToken = Self(method: .delete, path: "/auth/apple/access-token")
Expand All @@ -49,6 +52,7 @@ extension FunctionAPIEndpoint where Response == AppleChallengeResponse {
extension FunctionAPIEndpoint where Response == FirebaseCustomTokenResponse {
static let requestAppleCustomToken = Self(method: .post, path: "/auth/apple/custom-token")
static let requestGithubCustomToken = Self(method: .post, path: "/auth/github/custom-token")
static let requestGoogleCustomToken = Self(method: .post, path: "/auth/google/custom-token")
}

extension FunctionAPIEndpoint where Response == OAuthAuthenticationSessionResponse {
Expand All @@ -60,6 +64,14 @@ extension FunctionAPIEndpoint where Response == OAuthAuthenticationSessionRespon
method: .post,
path: "/auth/github/account-link-sessions"
)
static let requestGoogleSignInSession = Self(
method: .post,
path: "/auth/google/sign-in-sessions"
)
static let requestGoogleAccountLinkSession = Self(
method: .post,
path: "/auth/google/account-link-sessions"
)
}

private func functionAPIPathSegment(_ value: String) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
private let store = FirebaseConfiguration.firestore
private let messaging = Messaging.messaging()
private var user: User? { Auth.auth().currentUser }
private let providerID = AuthProviderID.apple
private let logger = Logger(category: "AppleAuthService")

func signIn() async throws -> AuthDataResponse? {
Expand Down Expand Up @@ -98,7 +97,7 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
}
}

func link(uid: String, email _: String) async throws -> Bool {
func link(uid: String) async throws -> Bool {
do {
logger.info("Linking Apple account for user: \(uid)")
let challenge = try await requestAppleChallenge()
Expand Down Expand Up @@ -236,13 +235,11 @@ private extension AppleAuthenticationServiceImpl {
return emailError
}

if error.apiAuthenticationError == .lastProvider {
return DataLayerError.failedToUnlinkLastProvider
}

switch error.apiAppleAuthenticationError {
switch error.apiAuthenticationError {
case .providerLinkConflict:
return DataLayerError.linkCredentialAlreadyInUse
case .lastProvider:
return DataLayerError.failedToUnlinkLastProvider
case .none:
return error
}
Expand Down
Loading
Loading