/twilio-verify-sna-android

Twilio Verify SNA SDK provides the verification of mobile number possession directly on the device by using its built-in connectivity to the mobile operators’ wireless network.

Primary LanguageKotlinApache License 2.0Apache-2.0

Twilio Verify SNA

ktlint License

Table of Contents

About

Twilio Silent Network Auth will protect you against account takeovers (ATOs) that target your user's phone number by streamlining your methods for verifying mobile number possession. Instead of sending one-time passcodes (OTPs) that can be stolen or forcing users to implement complicated app-based solutions, Twilio Silent Network Auth will verify mobile number possession directly on the device by using its built-in connectivity to the mobile operators’ wireless network.

This SDK will help you with process the SNA URL's provided by our Verify services to silently validate a phone number.

See Technical Overview

See Silent Network Auth Overview

Dependencies

None

Requirements

  • Android Studio Dolphin | 2021.3.1 or higher
  • Java 8
  • Android SDK 21 or higher
  • Gradle 7.2
  • Kotlin 1.6

Documentation

Offical documentation will be added via Twilio docs once this project gets released.

Installation

Important note:

We are working on having the Twilio Verify SNA SDK artifact available in a repository manager soon.

Currently, it's possible to include the aar of the SDK including it as external package following the next steps:

  1. Clone the repo and open it in Android Studio.
  2. Generate the SDK aar file by building the project. The built file is located in:
/verify_sna/build/outputs/aar/
  1. Put the aar file in libs folder of your app project (create the folder if it doesn't exist).
  2. On your app, in the project-level build.gradle file:
allprojects {
    // ...
  repositories {
    // ...
    flatDir {
        dirs 'libs'
    }
  }
}
  1. In the app-level build.gradle file add:
dependencies {
    // ...
    implementation (name:'aar-name', ext:'aar')
}

Running the Sample App

For running the demo you will need to create a sample backend, this backend will communicate with the Twilio Verify Services and provide to the client a SNA URL that this SDK will use to validate across the carrier cellular network.

Important note:

The demo app needs to run on a real device with a working SIM-CARD and internet connection (provided by the sim-card, not Wi-Fi).

Currently it's not possible to test the functionality using a virtual device.

To run the sample app:

  1. Clone the repo.
  2. Open it in Android Studio.
  3. Select sample in the run/debug configuration selector.
  4. Connect or prepare your test device with developer options enabled.
  5. Click Run button.

Running the Sample Backend

  • Configure a Verify Service.
  • Go to: Verify SNA Sample Backend
  • Use the Quick Deploy to Twilio option
    • You should log in to your Twilio account.
    • Enter the Account Sid, Auth Token, Verify Service Sid, Sync Service Sid and Sync Map Sid you created above.
      • Create Sync Map Sid by clicking on the Service > Maps tab and click the Create new Sync Map button in the top right. Once created, copy the Sid.
    • Deploy the application.
    • Press Go to live application.
    • You will see the start page. You can check for SNA transactions there, using the Fetch transactions button.
    • Copy the url and remove index.html, e.g. verify-sna-xxxx.twil.io. This will be the sample backend URL to use in the sample app.

Using the Sample App

To validate a phone number:

  • Set the phone number.
    • Available carriers during this phase:
      • US: Verizon, TMO.
      • UK: EE, Vodafone, O2 and ThreeUK.
      • CA: Bell, Rogers and Telus.
  • Set the country code (only US during pilot stage).
  • Set your sample backend URL.
  • Submit the form by using the CTA button.

Expected behavior: The app will ask the network carrier if the provided phone number is the same used on the network request, if the phone number is correct, then the app will redirect to a success screen.

Errors

Name Description Technical cause
InvalidUrlException Invalid url, please check the format. Unable to convert the url string to an URL struct.
CellularNetworkNotAvailable Cellular network not available Cellular network not available, check if the device has cellular internet connection or you are not using a simulator or tablet.
NoResultFromUrl Unable to get a valid result from the requested URL. Unable to get a redirection path or a result path from the url, probably the SNA URL is corrupted (or maybe expired)
NetworkRequestException Error processing the network request. An error was thrown in the network layer, check the inner exception property for more details.
RunInMainThreadException The SDK detected it was running in the main thread. The SDK is performing long-time tasks that can freeze or stop the app, it's required to run the SDK in a background thread.
UnexpectedException An unknown error was thrown. Check the inner exception for more details.

Contributing

This project welcomes contributions. Please check out our Contributing guide to learn more on how to get started.

License

Apache © Twilio Inc.