-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuthCloudApiRegistrationUseCaseImpl.swift
113 lines (94 loc) · 3.65 KB
/
AuthCloudApiRegistrationUseCaseImpl.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// Nevis Mobile Authentication SDK Example App
//
// Copyright © 2022. Nevis Security AG. All rights reserved.
//
import NevisMobileAuthentication
import RxSwift
/// Default implementation of ``AuthCloudApiRegistrationUseCase`` protocol.
class AuthCloudApiRegistrationUseCaseImpl {
// MARK: - Properties
/// The client provider.
private let clientProvider: ClientProvider
/// Use case for creating device information.
private let createDeviceInformationUseCase: CreateDeviceInformationUseCase
/// The authenticator selector.
private let authenticatorSelector: AuthenticatorSelector
/// The PIN enroller.
private let pinEnroller: PinEnroller
/// The Password enroller.
private let passwordEnroller: PasswordEnroller
/// The biometric user verifier.
private let biometricUserVerifier: BiometricUserVerifier
/// The device passcode user verifier.
private let devicePasscodeUserVerifier: DevicePasscodeUserVerifier
/// The logger.
private let logger: SDKLogger
// MARK: - Initialization
/// Creates a new instance.
///
/// - Parameters:
/// - clientProvider: The client provider.
/// - createDeviceInformationUseCase: Use case for creating device information.
/// - authenticatorSelector: The authenticator selector.
/// - pinEnroller: The PIN enroller.
/// - passwordEnroller: The Password enroller.
/// - biometricUserVerifier: The biometric user verifier.
/// - devicePasscodeUserVerifier: The device passcode user verifier.
/// - logger: The logger.
init(clientProvider: ClientProvider,
createDeviceInformationUseCase: CreateDeviceInformationUseCase,
authenticatorSelector: AuthenticatorSelector,
pinEnroller: PinEnroller,
passwordEnroller: PasswordEnroller,
biometricUserVerifier: BiometricUserVerifier,
devicePasscodeUserVerifier: DevicePasscodeUserVerifier,
logger: SDKLogger) {
self.clientProvider = clientProvider
self.createDeviceInformationUseCase = createDeviceInformationUseCase
self.authenticatorSelector = authenticatorSelector
self.pinEnroller = pinEnroller
self.passwordEnroller = passwordEnroller
self.biometricUserVerifier = biometricUserVerifier
self.devicePasscodeUserVerifier = devicePasscodeUserVerifier
self.logger = logger
}
}
// MARK: - AuthCloudApiRegistrationUseCase
extension AuthCloudApiRegistrationUseCaseImpl: AuthCloudApiRegistrationUseCase {
func execute(enrollResponse: String?, appLinkUri: String?) -> Observable<OperationResponse> {
Observable.create { [weak self] observer in
guard let self else {
return Disposables.create()
}
let client = clientProvider.get()
let operation = client?.operations.authCloudApiRegistration
.deviceInformation(createDeviceInformationUseCase.execute())
.authenticatorSelector(authenticatorSelector)
.pinEnroller(pinEnroller)
.passwordEnroller(passwordEnroller)
.biometricUserVerifier(biometricUserVerifier)
.devicePasscodeUserVerifier(devicePasscodeUserVerifier)
.onSuccess {
self.logger.log("Auth Cloud Api registration succeeded.", color: .green)
observer.onNext(CompletedResponse(operation: .registration))
observer.onCompleted()
}
.onError {
self.logger.log("Auth Cloud Api registration failed.", color: .red)
observer.onError(OperationError(operation: .registration,
underlyingError: $0))
}
// Emtpy string is not allowed!
if let enrollResponse, !enrollResponse.isEmpty {
operation?.enrollResponse(enrollResponse)
}
// Emtpy string is not allowed!
if let appLinkUri, !appLinkUri.isEmpty {
operation?.appLinkUri(appLinkUri)
}
operation?.execute()
return Disposables.create()
}
}
}