安卓指纹认证(Android Fingerprint Auth)

Android Fingerprint Auth

此插件将打开一个原生对话框,提示用户使用其指纹进行身份验证。 如果设备具有安全的锁定屏幕(模式,PIN或密码),则用户可以选择使用该方法进行身份验证作为备份。
Repo(备份): https://github.com/mjwheatley/cordova-plugin-android-fingerprint-auth

Installation(安装)

1.安装Cordova和Ionic原生插件:

$ ionic cordova plugin add cordova-plugin-android-fingerprint-auth
$ npm install --save @ionic-native/android-fingerprint-auth

2.添加插件到 app's module

Supported platforms(支持平台)

Android

Usage(用法)

import { AndroidFingerprintAuth } from '@ionic-native/android-fingerprint-auth';

constructor(private androidFingerprintAuth: AndroidFingerprintAuth) { }

...


this.androidFingerprintAuth.isAvailable()
  .then((result)=> {
    if(result.isAvailable){
      // it is available

      this.androidFingerprintAuth.encrypt({ clientId: 'myAppName', username: 'myUsername', password: 'myPassword' })
        .then(result => {
           if (result.withFingerprint) {
               console.log('Successfully encrypted credentials.');
               console.log('Encrypted credentials: ' + result.token);
           } else if (result.withBackup) {
             console.log('Successfully authenticated with backup password!');
           } else console.log('Didn\'t authenticate!');
        })
        .catch(error => {
           if (error === this.androidFingerprintAuth.ERRORS.FINGERPRINT_CANCELLED) {
             console.log('Fingerprint authentication cancelled');
           } else console.error(error)
        });

    } else {
      // fingerprint auth isn't available
    }
  })
  .catch(error => console.error(error));

Instance Members(实例成员)

ERRORS

encrypt(options)

打开原生对话框,使用设备硬件指纹扫描器对设备注册的指纹进行身份验证。

参数 类型 详情
options AFAAuthOptions Options

****Returns:** Promise

decrypt(options)
打开原生对话框,使用设备硬件指纹扫描器对设备注册的指纹进行身份验证。

参数 类型 详情
options AFAAuthOptions Options

****Returns:** Promise

isAvailable()
检查服务是否可用
****Returns:** Promise
如果指纹认证在设备上可用,则返回可解析的Promise。

delete()
删除用于加密和解密的密码
****Returns:** Promise
如果密码被成功删除,则返回一个可解析的Promise

AFAAuthOptions

参数 类型 详情
clientId string 必需用作Android Key Store中您的密钥的别名。
username string 用于为加密的令牌和别名创建用于检索密码的凭据字符串(可选)
password string 用于创建加密令牌的凭据字符串(可选)
token string 必需用于decrypt()成功认证时加密的用户凭据进行解密(可选)
disableBackup boolean 设置为true以删除"USE BACKUP" 按钮(可选)
locale string 改变语言. (en_US 或者es)(可选)
maxAttempts number 设备最多为5次尝试。 如果要允许少于5次尝试,请设置此参数。(可选)
userAuthRequired boolean 要求用户使用指纹进行身份验证,以授权每次使用该密钥。 新指纹注册将使密钥无效,并要求备份认证重新启用指纹认证对话框(可选)
dialogTitle string 设置指纹认证对话框的标题(可选)
dialogMessage string 设置指纹认证对话框的消息(可选)
dialogHint string 在指纹认证对话框中设置指纹图标显示的提示(可选)

AFAEncryptResponse

参数 类型 详情
withFingerprint boolean Biometric 认证
withBackup boolean 使用备份凭据活动进行验证
token string base64编码的用户凭据的字符串表示形式

AFADecryptOptions

参数 类型 详情
withFingerprint boolean Biometric 认证
withBackup boolean 使用备份凭据活动进行验证
password string FingerprintAuth.CipherMode.DECRYPT解密密码

你可能感兴趣的:(安卓指纹认证(Android Fingerprint Auth))