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
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(實例成員)
打開原生對話框菩颖,使用設備硬件指紋掃描器對設備注冊的指紋進行身份驗證誓琼。
參數(shù) | 類型 | 詳情 |
---|---|---|
options | AFAAuthOptions | Options |
****Returns:** Promise<any>
decrypt(options)
打開原生對話框抓韩,使用設備硬件指紋掃描器對設備注冊的指紋進行身份驗證讶迁。
參數(shù) | 類型 | 詳情 |
---|---|---|
options | AFAAuthOptions | Options |
****Returns:** Promise<any>
isAvailable()
檢查服務是否可用
****Returns:** Promise<any>
如果指紋認證在設備上可用连茧,則返回可解析的Promise。
delete()
刪除用于加密和解密的密碼
****Returns:** Promise<any>
如果密碼被成功刪除添瓷,則返回一個可解析的Promise
AFAAuthOptions
參數(shù) | 類型 | 詳情 |
---|---|---|
clientId | string | 必需用作Android Key Store中您的密鑰的別名梅屉。 |
username | string | 用于為加密的令牌和別名創(chuàng)建用于檢索密碼的憑據(jù)字符串(可選) |
password | string | 用于創(chuàng)建加密令牌的憑據(jù)字符串(可選) |
token | string | 必需用于decrypt()成功認證時加密的用戶憑據(jù)進行解密(可選) |
disableBackup | boolean | 設置為true以刪除"USE BACKUP" 按鈕(可選) |
locale | string | 改變語言. (en_US 或者es)(可選) |
maxAttempts | number | 設備最多為5次嘗試。 如果要允許少于5次嘗試鳞贷,請設置此參數(shù)坯汤。(可選) |
userAuthRequired | boolean | 要求用戶使用指紋進行身份驗證,以授權每次使用該密鑰搀愧。 新指紋注冊將使密鑰無效惰聂,并要求備份認證重新啟用指紋認證對話框(可選) |
dialogTitle | string | 設置指紋認證對話框的標題(可選) |
dialogMessage | string | 設置指紋認證對話框的消息(可選) |
dialogHint | string | 在指紋認證對話框中設置指紋圖標顯示的提示(可選) |
AFAEncryptResponse
參數(shù) | 類型 | 詳情 |
---|---|---|
withFingerprint | boolean | Biometric 認證 |
withBackup | boolean | 使用備份憑據(jù)活動進行驗證 |
token | string | base64編碼的用戶憑據(jù)的字符串表示形式 |
AFADecryptOptions
參數(shù) | 類型 | 詳情 |
---|---|---|
withFingerprint | boolean | Biometric 認證 |
withBackup | boolean | 使用備份憑據(jù)活動進行驗證 |
password | string | FingerprintAuth.CipherMode.DECRYPT解密密碼 |