Das App-Template bietet die Möglichkeit der biometrischen Authentifizierung. Diese Funktion kann im Projekt aktiviert werden.
<!----><DefineConstants>$(DefineConstants);Biometric</DefineConstants> <!-- Needed for biometric authentication --> <PackageReference Include="Oscore.Maui.Biometric" Version="1.0.1" />
Danach kann einfach die Content-Ansicht BiometricAuthConventView
eingebunden werden oder eine eigene Ansicht erstellt werden.
<contentViews:BiometricAuthConventView Background="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource OffBlack}}" IsVisible="{Binding BiometricAuthed, Converter={StaticResource BooleanReverseVisibilityConverter}}" AuthButtonCommand="{Binding BiometricAuthCommand}" TitleLabelText="{x:Static localization:Strings.NoteSecuredAreaAuthNeeded}" AuthButtonText="{x:Static localization:Strings.Authenticate}" > <contentViews:BiometricAuthConventView.Style> <Style TargetType="contentViews:BiometricAuthConventView"> <Setter Property="IsVisible" Value="True" /> <Style.Triggers> <DataTrigger TargetType="contentViews:BiometricAuthConventView" Binding="{Binding BiometricAuthSupported}" Value="False" > <Setter Property="IsVisible" Value="False" /> </DataTrigger> <DataTrigger TargetType="contentViews:BiometricAuthConventView" Binding="{Binding BiometricAuthed}" Value="True" > <Setter Property="IsVisible" Value="True" /> </DataTrigger> </Style.Triggers> </Style> </contentViews:BiometricAuthConventView.Style> </contentViews:BiometricAuthConventView>
Commands
Die dazugehörigen Commands
und Properties
findest du im BaseViewModel
.
[ObservableProperty] bool biometricAuthSupported = true; [ObservableProperty] bool resetBiometricAuthOnPageLeave = true; [ObservableProperty] bool biometricAuthed = false; //... [RelayCommand] async Task BiometricAuth() { try { AuthenticationResult result = await BiometricAuthentication.Current.AuthenticateAsync(new AuthenticationRequest( Strings.RequestedBiometricAuthHeadline, Strings.RequestedBiometricAuthContent)); await DispatchManager.DispatchAsync(Dispatcher, () => BiometricAuthed = result.Authenticated); } catch (Exception exc) { EventManager.Instance.LogError(exc); } }
Bitte beachte, dass die Form nur angezeigt werden soll, wenn die Eigenschaft BiometricAuthSupported
wahr ist.