twilio / twilio-verify-for-react-native

React native package for Twilio Verify
https://www.twilio.com/docs/verify/push
Apache License 2.0
7 stars 10 forks source link

React native module for Twilio Verify

License

About

Twilio Verify Push SDK helps you verify users by adding a low-friction, secure, cost-effective, "push verification" factor into your own mobile application. This fully managed API service allows you to seamlessly verify users in-app via a secure channel, without the risks, hassles or costs of One-Time Passcodes (OTPs). This project provides a library to implement Verify Push for your react native app.

Dependencies

React native 0.66.5

Installation

Enable push notifications

Register your iOS App with APNs

If you want to receive challenges as push notifications, you should register Your App with APNs.

More info here

Add firebase configuration for your Android App

If you want to receive challenges as push notifications, you should add a firebase configuration to your project

More info here

Add a push notification library

After setting up push notifications for Android & iOS, you should add a react native library to receive notifications from APN for iOS and FCM for Android.

The example app is using react-native-push-notification, you can find the full example source here

Usage

Create factor

import TwilioVerify, { PushFactorPayload } from '@twilio/twilio-verify-for-react-native';

let factor = await TwilioVerify.createFactor(
  new PushFactorPayload(
    factorName,
    verifyServiceSid,
    identity,
    accessToken,
    pushToken
  )
);

Verify factor

await TwilioVerify.verifyFactor(new VerifyPushFactorPayload(factor.sid));

Get challenge

let challenge = await TwilioVerify.getChallenge(challengeSid, factorSid);

Update challenge

await TwilioVerify.updateChallenge(
  new UpdatePushChallengePayload(factorSid, challengeSid, newStatus)
);

Get factors

let factors = await TwilioVerify.getAllFactors();

Get challenges

let challenges = await TwilioVerify.getAllChallenges(
  new ChallengeListPayload(factorSid, 10, ChallengeStatus.Pending, ChallengeListOrder.Desc)
);

Delete factor

await TwilioVerify.deleteFactor(factorSid);

Clear local storage

You can clear local storage calling the TwilioVerify.clearLocalStorage method:

await TwilioVerify.clearLocalStorage();

Note: Calling this method will not delete factors in Verify Push API, so you need to delete them from your backend to prevent invalid/deleted factors when getting factors for an identity.

Running the Sample app

Install the packages in the twilio-verify-for-react-native project

yarn install

Install the packages in the example app

cd example
yarn install

iOS

cd example
npx pod-install
yarn example ios

NOTE: There could be incompatibility issues with the react native version and your environment, so running the project from Xcode could share more details about the error and how to fix it

Android

yarn example android

Running the Sample backend

Using the sample app

Adding a factor

Sending a challenge

Errors

Android

iOS