Mis à jour le 21. mars 2026 par Jan Bunk
Vous souhaitez améliorer la sécurité de votre application tout en conservant une grande facilité d'utilisation ? L'authentification locale peut être la solution. La présente documentation vous montrera comment vous pouvez inviter les utilisateurs de votre application à saisir leur code confidentiel/empreinte digitale/identification faciale avant d'accéder à certaines parties de votre application.
Activez l'autorisation de biométrie dans vos paramètres d'autorisation. Sans cela, cette fonctionnalité risque de ne fonctionner que partiellement (pas d'identification des visages) ou de dysfonctionner de manière inattendue.
executeWhenAppReady()dans notre script d'aide de l'application. Elle garantit que votre site web n'essaie pas d'interagir avec l'application avant qu'elle ne soit prête ou lorsque votre site web est chargé à l'aide d'un navigateur normal (Erreur de référence, la fonction n'est pas définie). requestLocalAuthenticationUtilisez cette fonction pour demander à l'utilisateur de s'authentifier.
The function returns an object with a boolean result on success. If the authentication prompt is canceled or the device cannot continue, it throws a string error code instead.
<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 the authentication challenge failed.
// If the prompt is canceled or the device cannot continue, an error string is thrown instead.
let authenticationResult = (await requestLocalAuthentication(reason))["result"];
}
catch (e) {
switch(e) {
case "userCanceled":
// The user canceled the prompt and didn't authenticate.
break;
case "authInProgress":
// Another authentication request is already running.
break;
case "noCredentialsSet":
// No biometrics, PIN, password, or pattern is configured.
break;
case "systemCanceled":
// The system interrupted the authentication attempt, for example when the app gets closed.
break;
// All the errors below should be very rare in practice:
case "timeout":
// The authentication prompt timed out.
break;
case "uiUnavailable":
// The system cannot show the authentication prompt right now.
break;
case "deviceError":
// A device-level error prevented authentication.
break;
case "unknownError":
// An unknown error occurred.
break;
default:
// Any other error
break;
}
}
</script>
Older app versions may still be handling error strings such as NotAvailable, PasscodeNotSet, LockedOut, and PermanentlyLockedOut.