Skip to content

Commit

Permalink
Provide configurations to AuthenticationClient on initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mohannad-hassan committed Jan 5, 2025
1 parent 3cdc724 commit f07289d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
10 changes: 7 additions & 3 deletions Data/AuthenticationClient/Sources/AuthenticationClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public struct OAuthAppConfiguration {
///
/// Expected to be configuered with the host app's OAuth configuration before further operations are attempted.
public protocol AuthenticationClient {
/// Sets the app configuration to be used for authentication.
func set(appConfiguration: OAuthAppConfiguration)

/// Performs the login flow to Quran.com
///
/// - Parameter viewController: The view controller to be used as base for presenting the login flow.
Expand All @@ -65,3 +62,10 @@ public protocol AuthenticationClient {

var authenticationState: AuthenticationState { get }
}


public struct AuthentincationClientBuilder {
public static func make(withConfigurations config: OAuthAppConfiguration?) -> AuthenticationClient {
AuthenticationClientImpl(configurations: config)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import Foundation
import UIKit
import VLogging

public final class AuthenticationClientImpl: AuthenticationClient {
final class AuthenticationClientImpl: AuthenticationClient {
// MARK: Lifecycle

init(caller: OAuthCaller, persistance: Persistance) {
init(configurations: OAuthAppConfiguration?, caller: OAuthCaller, persistance: Persistance) {
self.caller = caller
self.persistance = persistance
self.appConfiguration = configurations
}

// MARK: Public
Expand All @@ -28,10 +29,6 @@ public final class AuthenticationClientImpl: AuthenticationClient {
return state?.isAuthorized == true ? .authenticated : .notAuthenticated
}

public func set(appConfiguration: OAuthAppConfiguration) {
self.appConfiguration = appConfiguration
}

public func login(on viewController: UIViewController) async throws {
do {
try persistance.clear()
Expand Down Expand Up @@ -114,7 +111,9 @@ public final class AuthenticationClientImpl: AuthenticationClient {
}

extension AuthenticationClientImpl {
public convenience init() {
self.init(caller: AppAuthCaller(), persistance: KeychainPersistance())
public convenience init(configurations: OAuthAppConfiguration?) {
self.init(configurations: configurations,
caller: AppAuthCaller(),
persistance: KeychainPersistance())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ final class AuthenticationClientTests: XCTestCase {
override func setUp() {
caller = OAuthCallerMock()
persistance = PersistanceMock()
sut = AuthenticationClientImpl(caller: caller, persistance: persistance)
}

func testNoConfigurations() async throws {
Expand Down
5 changes: 1 addition & 4 deletions Example/QuranEngineApp/Classes/Container.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ class Container: AppDependencies {
private(set) lazy var pageBookmarkPersistence: PageBookmarkPersistence = CoreDataPageBookmarkPersistence(stack: coreDataStack)
private(set) lazy var notePersistence: NotePersistence = CoreDataNotePersistence(stack: coreDataStack)
private(set) lazy var authenticationClient: any AuthenticationClient = {
let client = AuthenticationClientImpl()
if let config = Constant.QuranOAuthAppConfigurations {
client.set(appConfiguration: config)
}
let client = AuthentincationClientBuilder.make(withConfigurations: Constant.QuranOAuthAppConfigurations)
return client
}()

Expand Down

0 comments on commit f07289d

Please sign in to comment.