-
Notifications
You must be signed in to change notification settings - Fork 0
/
RegistrationUseCaseImpl.swift
111 lines (93 loc) · 3.77 KB
/
RegistrationUseCaseImpl.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
//
// Nevis Mobile Authentication SDK Example App
//
// Copyright © 2022. Nevis Security AG. All rights reserved.
//
import NevisMobileAuthentication
import RxSwift
/// Default implementation of ``RegistrationUseCase`` protocol.
class RegistrationUseCaseImpl {
// 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: - RegistrationUseCase
extension RegistrationUseCaseImpl: RegistrationUseCase {
func execute(username: String, authorizationProvider: AuthorizationProvider?) -> Observable<OperationResponse> {
Observable.create { [weak self] observer in
guard let self else {
return Disposables.create()
}
/// Nevis Mobile Authentication SDK supports registering authenticators in multiple servers.
/// You can specify the base URL of the server where the registration should be made, see ``Registration/serverUrl(_:)``.
/// If no server base URL is provided, then the base URL defined in ``Configuration/baseUrl`` will be used.
let client = clientProvider.get()
let operation = client?.operations.registration
.username(username)
.deviceInformation(createDeviceInformationUseCase.execute())
.authenticatorSelector(authenticatorSelector)
.pinEnroller(pinEnroller)
.passwordEnroller(passwordEnroller)
.biometricUserVerifier(biometricUserVerifier)
.devicePasscodeUserVerifier(devicePasscodeUserVerifier)
.onSuccess {
self.logger.log("In-Band registration succeeded.", color: .green)
observer.onNext(CompletedResponse(operation: .registration))
observer.onCompleted()
}
.onError {
self.logger.log("In-Band registration failed.", color: .red)
observer.onError(OperationError(operation: .registration,
underlyingError: $0))
}
if let authorizationProvider {
operation?.authorizationProvider(authorizationProvider)
}
operation?.execute()
return Disposables.create()
}
}
}