-
Notifications
You must be signed in to change notification settings - Fork 1
/
registration_usecase.dart
92 lines (84 loc) · 4.05 KB
/
registration_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
// Copyright © 2022 Nevis Security AG. All rights reserved.
import 'dart:async';
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/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';
abstract class RegistrationUseCase {
Future<void> execute({
required String username,
required AuthorizationProvider? authorizationProvider,
});
}
@Injectable(as: RegistrationUseCase)
class RegistrationUseCaseImpl implements RegistrationUseCase {
final ClientProvider _clientProvider;
final CreateDeviceInformationUseCase _createDeviceInformationUseCase;
final AuthenticatorSelector _authenticatorSelector;
final PinEnroller _pinEnroller;
final PasswordEnroller _passwordEnroller;
final BiometricUserVerifier _biometricUserVerifier;
final DevicePasscodeUserVerifier _devicePasscodeUserVerifier;
final FingerprintUserVerifier _fingerprintUserVerifier;
final DomainBloc _domainBloc;
final StateRepository<UserInteractionOperationState>
_userInteractionOperationStateRepository;
final StateRepository<OperationType> _operationTypeRepository;
final ErrorHandler _errorHandler;
RegistrationUseCaseImpl(
this._clientProvider,
this._createDeviceInformationUseCase,
@Named("auth_selector_reg") this._authenticatorSelector,
this._pinEnroller,
this._passwordEnroller,
this._biometricUserVerifier,
this._devicePasscodeUserVerifier,
this._fingerprintUserVerifier,
this._domainBloc,
this._userInteractionOperationStateRepository,
this._operationTypeRepository,
this._errorHandler,
);
@override
Future<void> execute({
required String username,
required AuthorizationProvider? authorizationProvider,
}) async {
final deviceInformation = await _createDeviceInformationUseCase.execute();
_operationTypeRepository.save(OperationType.registration);
// 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.
var registration = _clientProvider.client.operations.registration
.username(username)
.deviceInformation(deviceInformation)
.authenticatorSelector(_authenticatorSelector)
.pinEnroller(_pinEnroller)
.passwordEnroller(_passwordEnroller)
.biometricUserVerifier(_biometricUserVerifier)
.devicePasscodeUserVerifier(_devicePasscodeUserVerifier)
.fingerprintUserVerifier(_fingerprintUserVerifier)
.onSuccess(() {
debugPrint('In-band registration succeeded.');
_domainBloc.add(ResultEvent());
_userInteractionOperationStateRepository.reset();
}).onError((error) {
debugPrint('In-band registration failed: ${error.runtimeType}');
_errorHandler.handle(error);
_userInteractionOperationStateRepository.reset();
});
if (authorizationProvider != null) {
registration.authorizationProvider(authorizationProvider);
}
return await registration.execute();
}
}