Opublikowano 23. marca 2023 przez Jan Bunk
Chcesz poprawić bezpieczeństwo swojej aplikacji, nie tracąc na wygodzie? Lokalna autoryzacja może być rozwiązaniem. Ta dokumentacja pokaże Ci, jak poprosić użytkowników aplikacji o podanie PIN-u urządzenia, odcisku palca lub Face ID przed dostępem do części aplikacji.
Włącz uprawnienie biometryczne w ustawieniach uprawnień. W przeciwnym razie ta funkcja może działać tylko częściowo (bez Face ID) lub nieoczekiwanie się psuć.
executeWhenAppReady()
w naszym pomocniczym skrypcie aplikacji. Zapewnia, że Twoja strona nie próbuje komunikować się z aplikacją zanim będzie gotowa lub gdy strona jest otwarta w zwykłej przeglądarce (ReferenceError, funkcja nie jest zdefiniowana). requestLocalAuthentication
Użyj tej funkcji, aby poprosić użytkownika o autoryzację.
<script>
try {
// This message will be displayed to the user along with the prompt.
let reason = "Please authenticate to access this part of the app";
// returns a boolean. True if the authentication was successful, false if it failed (e.g. because the user
// canceled it by pressing the back button).
let authenticationResult = (await requestLocalAuthentication(reason))["result"];
}
catch (e) {
switch(e) {
case "NotAvailable":
// The user has not configured an authentication method on the device.
// Occurred on Android in this case, difference to PasscodeNotSet is not completely clear.
break;
case "PasscodeNotSet":
// The user has not configured a passcode (iOS) or PIN/pattern/password (Android) on the device
break;
case "LockedOut":
// Authentication is temporarily locked due to too many attempts.
break;
case "PermanentlyLockedOut":
// Authentication is more persistently locked out than with "LockedOut".
// Strong authentication like PIN/Pattern/Password is required to unlock.
break;
}
}
</script>