-
Notifications
You must be signed in to change notification settings - Fork 1
/
AuthCloudApiRegistrationViewModel.ts
78 lines (66 loc) · 2.76 KB
/
AuthCloudApiRegistrationViewModel.ts
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
/**
* Copyright © 2023 Nevis Security AG. All rights reserved.
*/
import { useState } from 'react';
import { useNavigation } from '@react-navigation/native';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import type { RootStackParamList } from './RootStackParamList';
import { ErrorHandler } from '../error/ErrorHandler';
import { OperationType } from '../model/OperationType';
import {
AuthenticatorSelectorImpl,
AuthenticatorSelectorOperation,
} from '../userInteraction/AuthenticatorSelectorImpl';
import { BiometricUserVerifierImpl } from '../userInteraction/BiometricUserVerifierImpl';
import { DevicePasscodeUserVerifierImpl } from '../userInteraction/DevicePasscodeUserVerifierImpl';
import { FingerprintUserVerifierImpl } from '../userInteraction/FingerprintUserVerifierImpl';
import { PasswordEnrollerImpl } from '../userInteraction/PasswordEnrollerImpl';
import { PinEnrollerImpl } from '../userInteraction/PinEnrollerImpl';
import { ClientProvider } from '../utility/ClientProvider';
import { DeviceInformationUtils } from '../utility/DeviceInformationUtils';
const useAuthCloudApiRegistrationViewModel = () => {
const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
const [enrollResponse, setEnrollResponse] = useState('');
const [appLinkUri, setAppLinkUri] = useState('');
async function confirm() {
const client = ClientProvider.getInstance().client;
const deviceInformation =
(await client?.localData.deviceInformation()) ?? DeviceInformationUtils.create();
const authCloudApiRegistration = client?.operations.authCloudApiRegistration
.deviceInformation(deviceInformation)
.authenticatorSelector(
new AuthenticatorSelectorImpl(AuthenticatorSelectorOperation.registration)
)
.pinEnroller(new PinEnrollerImpl())
.passwordEnroller(new PasswordEnrollerImpl())
.biometricUserVerifier(new BiometricUserVerifierImpl())
.devicePasscodeUserVerifier(new DevicePasscodeUserVerifierImpl())
.fingerprintUserVerifier(new FingerprintUserVerifierImpl())
.onSuccess(() => {
console.log('Auth Cloud API registration succeeded.');
navigation.navigate('Result', {
operation: OperationType.authCloudApiRegistration,
});
})
.onError(ErrorHandler.handle.bind(null, OperationType.authCloudApiRegistration));
if (enrollResponse) {
authCloudApiRegistration?.enrollResponse(enrollResponse);
}
if (appLinkUri) {
authCloudApiRegistration?.appLinkUri(appLinkUri);
}
await authCloudApiRegistration
?.execute()
.catch(ErrorHandler.handle.bind(null, OperationType.authCloudApiRegistration));
}
function cancel() {
navigation.goBack();
}
return {
setEnrollResponse,
setAppLinkUri,
confirm,
cancel,
};
};
export default useAuthCloudApiRegistrationViewModel;