如何解决React-Native中Android的Face ID身份验证
我需要android face_id身份验证SDK来响应本机android应用程序登录。我使用了可用的插件,这些插件仅支持android的手指身份验证和密码。请让我知道是否有可用的插件或SDK,以便我可以在React Native Android中使用。
如何通过创建本机模块在React Native中使用此代码。 https://developer.android.com/training/sign-in/biometric-auth
private Executor executor;
private BiometricPrompt biometricPrompt;
private BiometricPrompt.PromptInfo promptInfo;
executor = ContextCompat.getMainExecutor(this);
biometricPrompt = new BiometricPrompt(MainActivity.this,executor,new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode,@NonNull CharSequence errString) {
super.onAuthenticationError(errorCode,errString);
Toast.makeText(getApplicationContext(),"Authentication error: " + errString,Toast.LENGTH_SHORT)
.show();
}
@Override
public void onAuthenticationSucceeded(
@NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
Toast.makeText(getApplicationContext(),"Authentication succeeded!",Toast.LENGTH_SHORT).show();
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
Toast.makeText(getApplicationContext(),"Authentication Failed",Toast.LENGTH_SHORT)
.show();
}
});
promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login for my app")
.setSubtitle("Log in using your biometric credential")
.setNegativeButtonText("Use account password")
.build();
解决方法
react-native-fingerprint-scanner是您使用的许多API之一,下面是一个示例:
const isBiometricValid = async () =>
FingerprintScanner.authenticate({
description: 'Scan your fingerprint on the device scanner to continue'
});
const availableBiometric = async () => FingerprintScanner.isSensorAvailable();
const secureLogin = async ({
cpf,password,setFieldError,storedUser,navigation,dispatch,setUseManualPassword,useManualPassword,setFieldValue
}) => {
const authArgs = {
cpf,dispatch
};
try {
const availableBiometricType = await availableBiometric();
if (!availableBiometricType) {
return AuthCreators.getToken({ ...authArgs });
}
if (useManualPassword) {
return AuthCreators.getToken({
...authArgs,cpf: storedUser[0]
});
}
if (storedUser) {
const userAccessGranted = await isBiometricValid();
if (userAccessGranted) {
const storedPasswordEncrypted = await AsyncStorage.getItem('@__:password');
const decryptedPasswordBytes = CryptoJS.AES.decrypt(
storedPasswordEncrypted,Config.USER_PASSWORD_ENCRYPTION_KEY
);
const decryptedPassword = decryptedPasswordBytes.toString(CryptoJS.enc.Utf8);
return AuthCreators.getToken({
...authArgs,cpf: storedUser[0],password: decryptedPassword
});
}
}
return AuthCreators.getToken({
...authArgs,biometric: normalizedBiometricType(availableBiometricType)
});
} catch (error) {
return biometricAuthFailure({
...authArgs,error,setFieldValue,storedUser
});
}
};
例如,您可以通过打开iOS 11之类的设备(或默认使用faceID为任何人的设备)进行测试和调试,然后在“功能”>“ FaceID”>“已注册”中注册生物特征识别。
,Android中常见的是最新设备使用的指纹和iOS Face ID,我认为无法以与Android中的Face ID类似的方式进行管理。
例如,此library特定于Face-ID和Touch-ID(仅适用于iOS设备和生物识别技术)适用于Android,其工作方式与Touch-ID相似。
其他用户也回答了类似的question。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。