tauri_plugin_biometric/models.rs
1// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5use serde::{Deserialize, Serialize};
6
7/// Options for [`Biometric::authenticate`](crate::Biometric::authenticate).
8#[derive(Debug, Default, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct AuthOptions {
11 /// Enables authentication using the device's password. This feature is available on both Android and iOS.
12 pub allow_device_credential: bool,
13 /// Label for the Cancel button. This feature is available on both Android and iOS.
14 pub cancel_title: Option<String>,
15 /// Specifies the text displayed on the fallback button if biometric authentication fails. This feature is available iOS only.
16 pub fallback_title: Option<String>,
17 /// Title indicating the purpose of biometric verification. This feature is available Android only.
18 pub title: Option<String>,
19 /// SubTitle providing contextual information of biometric verification. This feature is available Android only.
20 pub subtitle: Option<String>,
21 /// Specifies whether additional user confirmation is required, such as pressing a button after successful biometric authentication. This feature is available Android only.
22 pub confirmation_required: Option<bool>,
23}
24
25/// The kind of biometry hardware detected on the device.
26#[derive(Debug, Clone, serde_repr::Deserialize_repr)]
27#[repr(u8)]
28pub enum BiometryType {
29 /// No biometry hardware is available, or it is not enrolled with the operating system.
30 None = 0,
31 /// Fingerprint authentication (Apple Touch ID or Android fingerprint).
32 TouchID = 1,
33 /// Face authentication (Apple Face ID or Android face authentication).
34 FaceID = 2,
35}
36
37/// The result of [`Biometric::status`](crate::Biometric::status), describing whether biometric
38/// authentication can currently be used.
39#[derive(Debug, Clone, Deserialize)]
40#[serde(rename_all = "camelCase")]
41pub struct Status {
42 /// Whether the device can currently authenticate using biometrics.
43 pub is_available: bool,
44 /// The kind of biometry hardware detected on the device, even when [`Self::is_available`] is `false`.
45 pub biometry_type: BiometryType,
46 /// A human-readable reason why biometric authentication is unavailable. Only set when
47 /// [`Self::is_available`] is `false`.
48 pub error: Option<String>,
49 /// A platform-specific error code describing why biometric authentication is unavailable.
50 /// Only set when [`Self::is_available`] is `false`.
51 pub error_code: Option<String>,
52}