0.1.6 • Published 1 year ago

react-native-trusted-device v0.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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)
      // TODO when initialize status false & true
    })

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)=>{
    // Your OTP come here
    })
  return()=>{
    closeStreamNotification()
  }
}, [])

Request & Validate OTP

Request OTP that use phone number as the parameter

Fazpass.requestOtpByPhone(phone,
  // This is your gateway
  "1e1de010-71b2-47d6-a037-254182ff3696",
  (_response:any)=>{
    // This otp id will be use for validate that OTP
    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)=>{
  // validation status
  setVerifyStatus("Verification status is: "+ status)
  },
  (err:string)=>{
    
  })

Header Enrichment

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:

  • Check The device
// you just need to fill one of them phone/email
Fazpass.checkDevice('PHONE_NUMBER', 'EMAIL',
  (status:any)=>{
    // CD status os cross device status, and TD is trusted Device
  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

  • Enroll The Device
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)
})

// or you can enroll device by pin only
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

  • Check Confidence Rate
Fazpass.validateUser("PIN", (response:any)=>{
  ToastAndroid.show(`Your confidence rate is : ${response.summary}`,1)
  }, (err:string)=>{
    ToastAndroid.show(`Something went wrong cause : ${err}`,1)
  })
  • Remove Device
  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
// make it true if you want validate cross device using pin
React.useEffect(() => {
  Fazpass.initializeCrossDevice(false)
}, [])
  • Initialize Cross Device Modification View
React.useEffect(() => {
  Fazpass.initializeCrossDeviceNonView(false, (onNotif:string)=>{
      //this is state
    setNotificated(true)
    let a = onNotif.split(',')
      //this is state
    setNotificationMessage(`There was an intruder that try to login \n from device ${a[1]}`)
    }, (onRunning:string)=>{
      console.log(onRunning)
    })
  // Call this method also to handle foreground notification  
  streamNotification((device:string)=>{
      //this is state
    setNotificated(true)
      let a = device.split(',')
    //this is state
    setNotificationMessage(`There was an intruder that try to login \n from device ${a[1]}`)
  })
    return()=>{
      // You need to close the stream
     closeStreamNotification()
    }
  }, [])

Note: you need to call this method in the first view on your app

Stream error

We use bridging between native code and react so if you want to know what error that happen you can listen with call function

streamNativeError((data)=>{
  // do some thing
})

and dont forget to close it when component willunmount

closeStreamNativeError()

Create release

We use native library so make sure you disable shrinkResource in gradle

  buildTypes {
    release {
      minifyEnabled false
      shrinkResources false
    }
  }

License

MIT


0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago