Search
⌃K

React Native

This guide helps you to integrate the Passbase SDK into your React Native project

General

Before integrating Passbase, we suggest you read first our best practice on how to integrate Passbase in your system in the overview section and complete the initial setup steps.
You can either follow the integration guide or watch the integration tutorial that shows the same steps. Please be aware that some property or function names might have slightly changed with newer versions. Make sure to compare your implementation with the latest code snippets here in the documentation.

1. Install the Package

Only customers on the Passbase Enterprise beta program should use V3 of the SDK. If you are not on the Passbase Enteprise beta program, you should use V2 of the SDK as V3 contains breaking changes.
At the root level of your project, install the package with yarn or npm inside the terminal:
# yarn
yarn add @passbase/[email protected]
# npm
npm i @passbase/[email protected] -s

For React Native <0.60

If your React Native version is larger than >= 0.60, you can ignore this step. Otherwise, please run the following command to link the package:
react-native link @passbase/react-native-passbase

iOS Specific Steps

Please follow these steps to complete the installation and integrate the SDK in the iOS project.

Adding Sources to Podfile

Navigate inside your iOS project folder and add the following lines at top of the Podfile. (If you don't have a Podfile yet, please create one by running the command pod init inside the ios folder)
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/passbase/cocoapods-specs.git'
source 'https://github.com/passbase/microblink-cocoapods-specs.git'
The minimum iOS version is 11.0. Make sure to include this in the Podfile: platform :ios, '11.0'
Then, navigate inside the terminal into your project folder and run the following command to install the Passbase iOS SDK as a dependency:pod install
pod install can take longer (up to 20 minutes) depending upon the speed of your internet. You can monitor the network activity in the activity monitor.

Example of a complete Podfile

# Example of a Podfile
# 1. Add this here
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/passbase/cocoapods-specs.git'
source 'https://github.com/passbase/microblink-cocoapods-specs.git'
# 2. Add the platform requirement to at least iOS 11
platform :ios, '11.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
target 'ReactNativeTest' do
use_frameworks!
# Pods for ReactNativeTest
# ... (not all listed)
target 'ReactNativeTestTests' do
inherit! :search_paths
# Pods for testing
end
use_native_modules!
end
target 'ReactNativeTest-tvOS' do
# Pods for ReactNativeTest-tvOS
target 'ReactNativeTest-tvOSTests' do
inherit! :search_paths
# Pods for testing
end
end

Create Objective-C Bridging if your iOS project is in Objective-C

After the pods are installed, open your project's .xcworkspace file in Xcode. If you have an Objective-C project, add a blank Swift file to your project (File -> New -> Swift File), with a bridging header (it will prompt you to auto-create one).
1. right click on project's name directory & select new file.
2. select swift file & click next
3. give name to your file & click Create
4. select Create Bridging Header

Adding Camera Permissions in Info.plist

If you made it here, you successfully installed the Passbase SDK for iOS. Now let's adjust your last settings and start your first verification.
Please add the following permissions to your app's Info.plist, so that the Passbase iOS SDK can access a user's camera to run a verification. You can do this in the property list view or by code.
Right-click somewhere outside the table and select Add Row. Now add the entries like below.
Or if you prefer to do this step with code, right-click on Info.plist and select Open As -> Source Code. Add the lines below somewhere inside the <dict> </dict>
<!-- permission strings to be include in info.plist -->
<key>NSCameraUsageDescription</key>
<string>Please give us access to your camera, to complete the verification.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Please give us access to your photo library to verify you.</string>
You have successfully finished setting up the Passbase iOS SDK! 🎉

Android Specific Steps

After installing the Passbase React Native package with yarn or npm, please complete the following steps to set up the Android environment correctly:

Adding Kotlin, Maven and minSdkVersion

Note: Make sure your Android Studio also supports Kotlin. As of this writing, Android Studio Version 3.5.1 has Kotlin support. If you're using an older version, you can install Kotlin support under Android Studio → Preferences… → Plugins → Browse Repository → Type “Kotlin” in search box → Install
Kotlin support is required in the main Android project. Please add the following lines to your project'sandroid/build.gradle file:
  1. 1.
    Set minSdkVersion to 21 or higher
  2. 2.
    Set kotlin_version to "1.6.0" or higher
  3. 3.
    Add in dependencies the line classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
  4. 4.
    Add in repositories the line maven { url 'https://button.passbase.com/__android' }

Code Example

// In the different lines to your projcet's build.gradle file
buildscript {
ext {
...
minSdkVersion = 21 // 1. Add minSdkVersion
compileSdkVersion 32
targetSdkVersion 32
kotlin_version = "1.6.0" // 2. Add kotlin_version
}
dependencies {
...
// 3. Add classpath
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
...
// 4. Add maven block
maven { url 'https://button.passbase.com/__android' }
}
}
Sync the gradle & run. You've successfully installed the Passbase SDK for Android! 🎉

2. Initialize the SDK

Please use the publishable API key for all integrations. The secret key should never be exposed or used in a web integration or mobile app since it can access sensitive user data if leaked!
First, add the following import statement to the top of the component where you want to render Passbase: import { PassbaseSDK } from '@passbase/react-native-passbase'
Then, initialize Passbase with your own API key. You can do this via a promise like in the code snippet below, and replace YOUR_PUBLISHABLE_API_KEY for your own publishable API key from your developer dashboard's API settings:
const res = await PassbaseSDK.initialize('YOUR_PUBLISHABLE_API_KEY')
You can initialize the SDK either via a promise or a callback. The methods for these two possibilities slightly differ:
Type
Method
Promise Based
initialize(publishableApiKey)
Callback Based
initialize(publishableApiKey, onSuccess, onFailure)
You can find an example implementation with both types below:
import { PassbaseSDK } from '@passbase/react-native-passbase';
// 1. promise based implementation
const res = await PassbaseSDK.initialize('YOUR_PUBLISHABLE_API_KEY')
if (res && res.success) {
// Do your stuff here, you have successfully initialized.
} else {
// check res.message for the error message
}
// 2. Callback based implementation
PassbaseSDK.initialize('YOUR_PUBLISHABLE_API_KEY',
(res) => { // it is onSuccess callback.
// do your stuff here.
},
(err) => { // it is onError callback
// oops! something went wrong. analyze `err`
}
)
You have successfully initialized the Passbase SDK! 🎉

3. Start Verification

Keep in mind that in order to successfully finish a verification, you need to pass our liveness detection. Hence, if you develop on a Simulator (e.g. iPhone Simulator via Xcode), you won't be able to get past this step. Therefore please use a real device (e.g. an attached iPhone) to fully test and develop with our SDK.
There are two ways to start verification.
  1. 1.
    Either by using a PassbaseButton component
  2. 2.
    Or by using the startVerification method
Using a PassbaseButton component is the simplest way to show a Passbase Button and start the verification process. The following code snippet shows how to use the PassbaseButton component inside your components render method.
import { PassbaseButton } from '@passbase/react-native-passbase'; // import statement on top
// ...
render() {
return (
<PassbaseButton style={{ backgroundColor: 'white' }}/>
)
}
If you want to make your own UI or want to start verification programmatically, you can use thestartVerification method. As previously mentioned, you can receive callbacks or you can use a promise based approach. Below are examples of how to start the verification based on promise or callback:
Type
Method
Promise Based
startVerification()
Callback Based
startVerification(onSuccess, onError)
You can find an example implementation using both methods below:
import { PassbaseSDK } from '@passbase/react-native-passbase' // at the top import
// Promise based method call
const res = await PassbaseSDK.startVerification();
if (res.success) {
// successfully started verification.
}
//Callback based call
PassbaseSDK.startVerification((res) => {
if (res && res.success) {
// successfully started verification.
}
}, (err) => {
// ooops! something went wrong. analyze `err`
})

Prefilling Email Addresses

If you want to automatically prefill user's email address to skip the "Approve your Email" screen. This is available programmatically if you pass the prefillUserEmail parameter to the SDK like below.
PassbaseSDK.setPrefillUserEmail("[email protected]")

Prefilling Country

You can automatically prefill user's country in the drop-down list. This is available programmatically if you pass the prefillCountry parameter to the SDK like below. An ISO-3166 compliant country code, case insensitive. This will not enable skipping the country selection step.
PassbaseSDK.setPrefillCountry("de")

Prefilling metaData

If you are tracking end users in your backend through an internal UUID, transaction number, stripe ID, etc., you can use the metaData object to securely pass encrypted end user information to identify completed verifications. The metadata object requires an encrypted JSON string via the private key encoded in base64.
Value
metaData
Encrypted JSON string via the private key encoded in base64
// Signed and Armored Metadata, which contain {internal_customer_id: "XYZ", "email": "[email protected]", "country": "de", ...}
PassbaseSDK.setMetaData("AJIZZDIZJADIOAJDOIZJAOIZJDOIAJIODZJIAJDIOZJAIOZDJALANLIKESJIZZOIZDJAOIZJDOZIAJDOIAZJDAZD")

Add Encryption Key to your Project

Encryption should be completed on the server-side. Once you have completed the encryption, please enter the encryption keys for each individual project within the developer dashboard. The metaData object is then returned on the Passbase API.
Click here to view metaData encryption documentation.

Retrieve MetaData from Passbase API

After a user completes a verification and you receive the VERIFICATION_REVIEWED webhook event, it is time to call the Passbase Get Identity endpoint. Using this API endpoint, you will see the new metaData object returned.
If the public encryption key is not added to the developer dashboard, you will not see the metaData information returned on the API.
{
id: "1234-1234-1234-1234",
resources: [...],
metadata: { internal_customer_id: "XYZ" }
}
You have successfully started your first verification! 🎉

4. Handling Verifications

Often it is useful to know if a user completes the verification or ca oOur SDK currently supports a set of customization options that will influence the appearance. To customize the verification flow, please navigate to your developer dashboard's successfully completed identity verifications from the callback method and save them to your DB e.g. a user's profilencels it. For this, you can implement the following callback methods:
Method
Description
onStart
This callback method is triggered once a user starts the verification flow.
onSubmitted
Method that is being called once verification data is submitted to Passbase.
You receive an object called identityAccessKey which can be used to access the identity. Please see our section about Webhooks and API for more information.
onFinish
Method that is being called once a user clicks the "Finish" button. You receive an object called identityAccessKey which can be used to access the identity. Please see our section about Webhooks and API for more information.
onError
This callback method is triggered when a user canceled the verification flow or the verification finished with an error. You can use this to find out if people dropped out of your verification flow.
Error codes:
CANCELLED_BY_USER BIOMETRIC_AUTHENTICATION_FAILED
You can subscribe to those events like in the code example below.
import { NativeEventEmitter } from 'react-native';
import { PassbaseSDK } from '@passbase/react-native-passbase';
// now in your component's componentDidMount lifecycle method
componentDidMount () {
this.subscription = new NativeEventEmitter(PassbaseSDK);
this.subscription.addListener('onError', event => {
// do your stuff here
// event.errorCode
});
this.subscription.addListener('onFinish', event => {
// do your stuff here.
// event.identityAccessKey can be used for further interactions with passbase server
});
this.subscription.addListener('onSubmitted', event => {
// do your stuff here.
// event.identityAccessKey can be used for further interactions with passbase server
});
this.subscription.addListener('onStart', event => {
// do your stuff here.
});
}
// you should removeListeners on componentWillUnmout
componentWillUnmount(){
if (this.subscription) {
this.subscription.removeListener('onError', (event) => {})
this.subscription.removeListener('onFinish', (event) => {})
this.subscription.removeListener('onSubmitted', (event) => {})
this.subscription.removeListener('onStart', (event) => {})
}
}
We recommend the following process for handling identity verifications:
  1. 1.
    Obtain the identityAccessKey
  2. 2.
    Set up webhooks to be notified once the identity verification has been processed by our system. Also once you have approved or declined the user in your dashboard
  3. 3.
    Now you can use your own backend to query the details about this identity verification with e.g. the Get Identity call to obtain the details

Identity Access Key as Reference

In order for your application to interoperate with Passbase, you should reference to your users once the Verification is completed.
For that, you will need to keep track of the identityAccessKey returned by the onFinish or onSubmitted callbacks and associate it in your backend with your end users' id. We recommend to save this key after the onSubmitted method from your user's completed verification, or listen for the incoming webhooks to make a call to the Passbase API linking back the email address of the user.

5. UI Customizations

Appearance

Our SDK currently supports a set of customization options which will influence the appearance. To customize the verification flow, please navigate to your developer dashboard's customization section. Here you can choose amongst a variety of colors, fonts, accepted countries & much more.
Customization Section
We also offer a dark mode, which will be automatically started if a user has activated this in his system settings.
Dark Mode

Language

We support a variety of different languages for the verification flow. As of this writing more than 10 including (English, Spanish, German & many more). If one is missing and you want us to add support for it, please reach out to our customer support.
The SDK automatically detects the language of the user's phone settings. If we support the language, the verification flow will be set to it. Otherwise, the default is English.

6. ProGuard (Android)

If you are using ProGuard you might need to add the following options:
-dontwarn okio.**
-dontwarn retrofit2.Platform$Java8
-dontwarn com.facetec.zoom.sdk.**
to ProGuard exceptions
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

Example & Demo App

You can find a code example of a whole class in the code section below. Also, we have a full example on our Github: React Native Demo App
import React from 'react';
import { NativeEventEmitter, Platform, View, StyleSheet, TouchableOpacity, Text, Alert, ActivityIndicator } from 'react-native';
import { PassbaseSDK, PassbaseButton } from '@passbase/react-native-passbase';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
initSucceed: false,
loading: false
};
}
async componentDidMount() {
this.subscription = new NativeEventEmitter(PassbaseSDK);
this.subscription.addListener('onError', (event) => {
console.log("##onError##", event)
})
this.subscription.addListener('onFinish', (event) => {
console.log("##onFinish##", event)
})
this.subscription.addListener('onSubmitted', (event) => {
console.log("##onSubmitted##", event)
})
this.subscription.addListener('onStart', (event) => {
console.log("##onStart##", event)
})
}
handlePassbaseClick = async () => {
const { initSucceed, loading } = this.state
if (loading ) {
return
}
this.setState({loading: true}, async () => {
if (initSucceed) {
// Promise based method call
const res = await PassbaseSDK.startVerification();
this.setState({loading: false})
if (!res.success) {
alert('something went wrong. while starting verification.')
}
} else {
// promise based implementation
const res = await PassbaseSDK.init('YOUR_PUBLISHABLE_API_KEY')
console.log("initRes: ", res)
if (res && res.success) {
this.setState({initSucceed: true, loading: false})
}
}
})
}
render() {
const { initSucceed, loading } = this.state;
return (
<View style={styles.container}>
<TouchableOpacity style={styles.button}
onPress={this.handlePassbaseClick}>
<Text style={styles.btnText}>
{initSucceed ? 'start verification' : 'initialize SDK'}
</Text>
{
loading && <View style={styles.loadingContainer}>
<ActivityIndicator size={'large'}/>
</View>
}
</TouchableOpacity>
{
initSucceed && <PassbaseButton style={{ margin: 10, backgroundColor: 'white' }}/>
}
</View>
);
}
componentWillUnmount(){
if (this.subscription)
this.subscription.removeListener('onFinish', (event) => {
console.log("##removing listener onFinish##", event)
})
this.subscription.removeListener('onSubmitted', (event) => {
console.log("##removing listener onSubmitted##", event)
})
this.subscription.removeListener('onError', (event) => {
console.log("##removing listener onError##", event)
})
this.subscription.removeListener('onStart', (event) => {
console.log("##removing listener onStart##", event)
})
}
}
export default App;
const styles = StyleSheet.create({
container: {
width: '100%',
height: '100%',
alignItems: 'center',
justifyContent: 'center'
},
button: {
width: 250,
padding: 10,
margin: 10,
backgroundColor: 'blue',
alignItems: 'center',
justifyContent: 'center'
},
btnText: {
color: 'white',
fontWeight: 'bold'
},
component: {
width: 100,
height: 100,
margin: 5
},
loadingContainer: {
position: 'absolute',
left: 0, right: 0, top: 0, bottom: 0,
alignItems: 'center',
justifyContent: 'center'
}
});
You have completed the integration for React Native! 🎉

Troubleshooting

ZoomAuthenticationHybrid.framework, no image present

If you experience a crash with the error, "ZoomAuthenticationHybrid.framework, no image present," please add it manually. Otherwise, skip this step.
Sometimes, there is a bug where we need to add another framework to our iOS Project. Try to build and run your project. If the above bug occurs, please download the ZoomAuthenticationHybrid.framework from this link.
Unzip the file, locate the ZoomAuthenticationHybrid.framework file in the folder and copy it to your ios directory in the react native project.
Next, open your project's xcworkspace file and drag the ZoomAuthenticationHybrid.framework inside the left pane to your project's dependencies in XCode.
Tick the box for Copy items if needed
Add a copy file phase to your Xcode project and have ZoomAuthenticationHybrid.framework copied to destination Frameworks

For Xcode >= 11 only

Go to General -> Frameworks, Libraries, and Embedded Content & Select Embed & Sign for ZoomAuthenticationHybrid.framework.
Now clean project & build & run.

Gradle sync fails with OneSignal installed

The problem is both OneSignal and Passbase are requiring different versions of some of services from com.google.firebase & com.google.android.gms groups.
Add resolutionStrategy to the project level build.gradle inside the allProjects block as follows:
allprojects {
repositories {
// other repositories ...
maven { url 'https://maven.google.com' } // THIS ONE ADDED FOR ONE-SIGNAL
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://button.passbase.com/__android' }
}
configurations.all { // THIS BLOCK ADDED FOR ONE-SIGNAL & PASSBASE CONFLICTS
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.google.firebase') {
details.useVersion "+"
}
if (details.requested.group == 'com.google.android.gms') {
details.useVersion "+"
}
}
}
}
}
sync the project and then build and run

Gradle sync fails with Intercom installed

If you have a similar error in your project:
Could not determine the dependencies of task ':app:lintVitalRelease'.
> Could not resolve all artifacts for configuration ':app:releaseAndroidTestRuntimeClasspath'.
> Could not resolve io.intercom.android:intercom-sdk-base:5.+.
Required by:
project :app > project :react-native-intercom
> Failed to list versions for io.intercom.android:intercom-sdk-base.
> Unable to load Maven meta-data from https://button.passbase.com/__android/io/intercom/android/intercom-sdk-base/maven-metadata.xml.
> Could not get resource 'https://button.passbase.com/__android/io/intercom/android/intercom-sdk-base/maven-metadata.xml'.
> Could not GET 'https://button.passbase.com/__android/io/intercom/android/intercom-sdk-base/maven-metadata.xml'. Received status code 403 from server: Forbidden
A workaround may help:
maven {
url 'https://button.passbase.com/__android'
content {
excludeGroupByRegex "io\\.intercom.*"
}
}
sync the project and then build and run

Camera is not starting in release build on android

If you experience that camera is not starting in release build make sure you set enableProguardInReleaseBuilds in build.gradle to false. Or add exeptions as described in ProGuard section above.
Last modified 5mo ago