-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoob_process_usecase.dart
155 lines (147 loc) · 6.63 KB
/
oob_process_usecase.dart
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright © 2022 Nevis Security AG. All rights reserved.
import 'package:flutter/foundation.dart';
import 'package:injectable/injectable.dart';
import 'package:nevis_mobile_authentication_sdk/nevis_mobile_authentication_sdk.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/blocs/domain_state/domain_bloc.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/blocs/domain_state/domain_event.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/client_provider/client_provider.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/error/error_handler.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/model/error/error.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/model/operation/operation_type.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/model/operation/user_interaction_operation_state.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/repository/state_repository.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/usecase/create_device_information_usecase.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/usecase/oob_payload_decode_usecase.dart';
abstract class OobProcessUseCase {
Future<void> execute(String? json);
}
@Injectable(as: OobProcessUseCase)
class OobProcessUseCaseImpl implements OobProcessUseCase {
final ClientProvider _clientProvider;
final CreateDeviceInformationUseCase _createDeviceInformationUseCase;
final OobPayloadDecodeUseCase _oobPayloadDecodeUseCase;
final AccountSelector _accountSelector;
final AuthenticatorSelector _registrationAuthenticatorSelector;
final AuthenticatorSelector _authenticationAuthenticatorSelector;
final PinEnroller _pinEnroller;
final PasswordEnroller _passwordEnroller;
final PinUserVerifier _pinUserVerifier;
final PasswordUserVerifier _passwordUserVerifier;
final BiometricUserVerifier _biometricUserVerifier;
final DevicePasscodeUserVerifier _devicePasscodeUserVerifier;
final FingerprintUserVerifier _fingerprintUserVerifier;
final DomainBloc _domainBloc;
final StateRepository<UserInteractionOperationState>
_userInteractionOperationStateRepository;
final StateRepository<OperationType> _operationTypeRepository;
final ErrorHandler _errorHandler;
OobProcessUseCaseImpl(
this._clientProvider,
this._createDeviceInformationUseCase,
this._oobPayloadDecodeUseCase,
this._accountSelector,
@Named("auth_selector_reg") this._registrationAuthenticatorSelector,
@Named("auth_selector_auth") this._authenticationAuthenticatorSelector,
this._pinEnroller,
this._passwordEnroller,
this._pinUserVerifier,
this._passwordUserVerifier,
this._biometricUserVerifier,
this._devicePasscodeUserVerifier,
this._fingerprintUserVerifier,
this._domainBloc,
this._userInteractionOperationStateRepository,
this._operationTypeRepository,
this._errorHandler,
);
@override
Future<void> execute(String? json) async {
if (json == null) {
throw BusinessException.missingDispatchTokenResponse();
}
final deviceInformation = await _createDeviceInformationUseCase.execute();
await _oobPayloadDecodeUseCase.execute(
json: json,
onSuccess: (payload) async {
_operationTypeRepository.save(OperationType.registration);
await handleOutOfBandPayload(
outOfBandPayload: payload,
deviceInformation: deviceInformation,
).catchError((error) {
_errorHandler.handle(error);
});
},
);
}
Future<void> handleOutOfBandPayload({
required OutOfBandPayload outOfBandPayload,
required DeviceInformation deviceInformation,
}) async {
await _clientProvider.client.operations.outOfBandOperation //
.payload(outOfBandPayload)
.onRegistration((registration) async {
await handleRegistration(
registration: registration,
deviceInformation: deviceInformation,
).catchError((error) {
_errorHandler.handle(error);
});
}).onAuthentication((authentication) async {
await handleAuthentication(authentication: authentication)
.catchError((error) {
_errorHandler.handle(error);
});
}).onError((error) {
debugPrint('Out of band operation failed: ${error.runtimeType}');
_errorHandler.handle(error);
_userInteractionOperationStateRepository.reset();
}).execute();
}
Future<void> handleRegistration({
required OutOfBandRegistration registration,
required DeviceInformation deviceInformation,
}) async {
return await registration
.deviceInformation(deviceInformation)
.authenticatorSelector(_registrationAuthenticatorSelector)
.pinEnroller(_pinEnroller)
.passwordEnroller(_passwordEnroller)
.biometricUserVerifier(_biometricUserVerifier)
.devicePasscodeUserVerifier(_devicePasscodeUserVerifier)
.fingerprintUserVerifier(_fingerprintUserVerifier)
.onSuccess(() {
debugPrint('Out of band registration succeeded.');
_operationTypeRepository.save(OperationType.registration);
_domainBloc.add(ResultEvent());
_userInteractionOperationStateRepository.reset();
}).onError((error) {
debugPrint('Out of band registration failed: ${error.runtimeType}');
_operationTypeRepository.save(OperationType.registration);
_errorHandler.handle(error);
_userInteractionOperationStateRepository.reset();
}).execute();
}
Future<void> handleAuthentication({
required OutOfBandAuthentication authentication,
}) async {
return await authentication
.accountSelector(_accountSelector)
.authenticatorSelector(_authenticationAuthenticatorSelector)
.pinUserVerifier(_pinUserVerifier)
.passwordUserVerifier(_passwordUserVerifier)
.biometricUserVerifier(_biometricUserVerifier)
.devicePasscodeUserVerifier(_devicePasscodeUserVerifier)
.fingerprintUserVerifier(_fingerprintUserVerifier)
.onSuccess((authorizationProvider) {
debugPrint('Out of band authentication succeeded.');
_operationTypeRepository.save(OperationType.authentication);
_domainBloc.add(ResultEvent());
_userInteractionOperationStateRepository.reset();
}).onError((error) {
debugPrint('Out of band authentication failed: ${error.runtimeType}');
_operationTypeRepository.save(OperationType.authentication);
_errorHandler.handle(error);
_userInteractionOperationStateRepository.reset();
}).execute();
}
}