local_auth_ohos
HarmonyOS (OpenHarmony / HarmonyOS NEXT) local-authentication implementation
for local_auth, backed by the UserIAM
userAuth kit (@ohos.userIAM.userAuth).
How it works
- Dart side —
LocalAuthOhos extends LocalAuthPlatform(local_auth_platform_interface). Declared asdartPluginClasswithimplements: local_auth, so the Flutter tool registers it automatically for ohos builds; no changes to the app-facinglocal_authpackage are needed. - Native side —
LocalAuthOhosPluginserves the method channelorg.tsinbeilabs.local_auth_ohos/auth:Method Behavior authenticatepicks the first available credential (fingerprint → face → PIN unless biometricOnly), runsuserAuth.getAuthInstance(..., ATL3)with the system promptdeviceSupportsBiometricsfingerprint or face available getEnrolledBiometricsfingerprint/face/weak(PIN) as enrolledisDeviceSupportedany credential available stopAuthenticationcancels the in-flight AuthInstance
Error mapping to LocalAuthExceptionCode: userCanceled, timeout,
noCredentialsSet, noBiometricsEnrolled, authInProgress, deviceError.
Usage
dependencies:
local_auth: ^3.0.2
local_auth_ohos:
git:
url: https://github.com/TsinbeiLabs/local_auth_ohos.git
ref: main
Register the native plugin in GeneratedPluginRegistrant.ets:
import LocalAuthOhosPlugin from 'local_auth_ohos';
// ...
flutterEngine.getPlugins()?.add(new LocalAuthOhosPlugin());
The plugin declares ohos.permission.ACCESS_BIOMETRIC in its module.json5;
the permission is merged into the app at build time.
Notes & limitations
- Authentication runs at trust level ATL3 (sufficient for app unlock / local confirmation flows). ATL4 (payment-grade) is not targeted.
AuthMessagescustomization is ignored: the prompt UI is fully system-rendered by the UserIAM framework.- Requires a device with enrolled credentials;
getAvailableStatuserror codes drive the availability checks.
License
Apache-2.0.
Libraries
- local_auth_ohos
- HarmonyOS local-authentication implementation for
local_auth.