react-native-trusted-device
Trusded device library for react native from Fazpass company
Installation
npm install react-native-trusted-device
Usage
First you should call this code in your root view. It will save that credential in then local storage of the device.
import { initialize } from 'react-native-trusted-device';
Fazpass.initialize("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjo0fQ.WEV3bCizw9U_hxRC6DxHOzZthuJXRE8ziI3b6bHUpEI",
1,(err:string)=>{
console.log(err)
})
Permission
For enjoy of all feature make sue your app request this permission
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
If you feel lazy to take care about it you can call this method
import { requestPermission } from 'react-native-trusted-device';
requestPermission()
OTP & HE
If you want to listen incoming OTP by SMS or Misscall you need to call streamOtp
and close this stream on component will unmount
React.useEffect(() => {
streamOtp((otp:string)=>{
})
return()=>{
closeStreamNotification()
}
}, [])
Request & Validate OTP
Request OTP that use phone number as the parameter
Fazpass.requestOtpByPhone(phone,
"1e1de010-71b2-47d6-a037-254182ff3696",
(_response:any)=>{
setOtpId(_response.id)
},
(_err:string)=>{
ToastAndroid.show(_err, ToastAndroid.SHORT);
})
If you want email as the parameter you can call requestOtpByEmail
This is example for validation OTP
Fazpass.validateOtp(otpId, otp,
(status:boolean)=>{
setVerifyStatus("Verification status is: "+ status)
},
(err:string)=>{
})
Header enrichment only accept phone number as a parameter
Fazpass.heValidation(phone,
"6cb0b024-9721-4243-9010-fd9e386157ec",
(status:boolean)=>{
setHeMessage('Result of He valisation is ' + status)
},
(err:string)=>{
setHeMessage(err)
})
Trusted Device
Available Method:
Fazpass.checkDevice('PHONE_NUMBER', 'EMAIL',
(status:any)=>{
setCheckStatus(`Status cross device : ${status.cd} Status trusted device : ${status.td}`)
},
(err:string)=>{
ToastAndroid.show(err, 1)
})
Note: You can't call enroll or validate if you have not call check
const user = {
"email":"",
"phone":phone,
"name":"Andri nova riswanto",
"id_card":"",
"address":"Bogor"
}
Fazpass.enrollDeviceByFinger(user, "PIN", (status:boolean)=>{
ToastAndroid.show(`Enroll status ${status}`,1)
},
(err:string)=>{
ToastAndroid.show(err, 1)
})
Fazpass.enrollDeviceByPin(user, "PIN", (status:boolean)=>{
ToastAndroid.show(`Enroll status ${status}`,1)
},
(err:string)=>{
ToastAndroid.show(err, 1)
})
Note: Don't enroll device if trusted device status is false, so better you validate this user & device first using OTP or Header enrichment
Fazpass.validateUser("PIN", (response:any)=>{
ToastAndroid.show(`Your confidence rate is : ${response.summary}`,1)
}, (err:string)=>{
ToastAndroid.show(`Something went wrong cause : ${err}`,1)
})
Fazpass.removeDevice('PIN',
(status:any)=>{
ToastAndroid.show(`Remove status ${status}`, 1)
},
(err:string)=>{
ToastAndroid.show(err, 1)
})
Cross Device
When check device there are 2 status (Trusted Device & Cross Device) so it is possible when trusted device is false
but cross device status is true
.
You can call method cross device to send notification that will request validation, It will make you no need to validate OTP or Header Enrichment
- Initialize Cross Device Default View
React.useEffect(() => {
Fazpass.initializeCrossDevice(false)
}, [])
- Initialize Cross Device Modification View
React.useEffect(() => {
Fazpass.initializeCrossDeviceNonView(false, (onNotif:string)=>{
setNotificated(true)
let a = onNotif.split(',')
setNotificationMessage(`There was an intruder that try to login \n from device ${a[1]}`)
}, (onRunning:string)=>{
console.log(onRunning)
})
streamNotification((device:string)=>{
setNotificated(true)
let a = device.split(',')
setNotificationMessage(`There was an intruder that try to login \n from device ${a[1]}`)
})
return()=>{
closeStreamNotification()
}
}, [])
Note: you need to call this method in the first view on your app
Create release
We use native library so make sure you disable shrinkResource in gradle
buildTypes {
release {
minifyEnabled false
shrinkResources false
}
}
License
MIT