-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuthCloudApiRegistrationPresenter.swift
131 lines (109 loc) · 4.15 KB
/
AuthCloudApiRegistrationPresenter.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// Nevis Mobile Authentication SDK Example App
//
// Copyright © 2022. Nevis Security AG. All rights reserved.
//
import NevisMobileAuthentication
import UIKit
/// Presenter of Auth Cloud Api Registration view.
final class AuthCloudApiRegistrationPresenter {
// MARK: - Properties
/// The view of the presenter.
weak var view: BaseView?
/// The client provider.
private let clientProvider: ClientProvider
/// The authenticator selector used during registration.
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 application coordinator.
private let appCoordinator: AppCoordinator
/// The error handler chain.
private let errorHandlerChain: ErrorHandlerChain
/// The logger.
private let logger: SDKLogger
// MARK: - Initialization
/// Creates a new instance.
///
/// - Parameters:
/// - clientProvider: The client provider.
/// - authenticatorSelector: The authenticator selector used during registration.
/// - pinEnroller: The PIN enroller.
/// - passwordEnroller: The Password enroller.
/// - biometricUserVerifier: The biometric user verifier.
/// - devicePasscodeUserVerifier: The device passcode user verifier.
/// - appCoordinator: The application coordinator.
/// - errorHandlerChain: The error handler chain.
/// - logger: The logger.
init(clientProvider: ClientProvider,
authenticatorSelector: AuthenticatorSelector,
pinEnroller: PinEnroller,
passwordEnroller: PasswordEnroller,
biometricUserVerifier: BiometricUserVerifier,
devicePasscodeUserVerifier: DevicePasscodeUserVerifier,
appCoordinator: AppCoordinator,
errorHandlerChain: ErrorHandlerChain,
logger: SDKLogger) {
self.clientProvider = clientProvider
self.authenticatorSelector = authenticatorSelector
self.pinEnroller = pinEnroller
self.passwordEnroller = passwordEnroller
self.biometricUserVerifier = biometricUserVerifier
self.devicePasscodeUserVerifier = devicePasscodeUserVerifier
self.appCoordinator = appCoordinator
self.errorHandlerChain = errorHandlerChain
self.logger = logger
}
/// :nodoc:
deinit {
os_log("AuthCloudApiRegistrationPresenter", log: OSLog.deinit, type: .debug)
}
}
// MARK: - Public Interface
extension AuthCloudApiRegistrationPresenter {
/// Registers based on the enrollment response or the app link URI.
///
/// - Parameters:
/// - enrollResponse: The response of the Cloud HTTP API to the enroll endpoint.
/// - appLinkUri: The value of the `appLinkUri` attribute in the enroll response sent by the server.
func register(enrollResponse: String?, appLinkUri: String?) {
view?.disableInteraction()
let client = clientProvider.get()
let deviceInformation = client?.localData.deviceInformation ?? DeviceInformation(name: UIDevice.extendedName)
let operation = client?.operations.authCloudApiRegistration
.deviceInformation(deviceInformation)
.authenticatorSelector(authenticatorSelector)
.pinEnroller(pinEnroller)
.passwordEnroller(passwordEnroller)
.biometricUserVerifier(biometricUserVerifier)
.devicePasscodeUserVerifier(devicePasscodeUserVerifier)
.onSuccess {
self.logger.log("Auth Cloud Api registration succeeded.", color: .green)
self.appCoordinator.navigateToResult(with: .success(operation: .registration))
}
.onError {
self.logger.log("Auth Cloud Api registration failed.", color: .red)
let operationError = OperationError(operation: .registration, underlyingError: $0)
self.errorHandlerChain.handle(error: operationError)
}
// 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()
}
/// Cancels the registration.
func cancel() {
appCoordinator.start()
}
}