Quickstart for React Native
Introduction
This is a proof of concept demonstrator for React-Native used with Android and iOS digi.me SDKs to make content and data requests. For details on the digi.me API and the Private Sharing architecture please visit our developer docs.
The React-Native demo requires the digi.me app installed on the target platform to enable user authentication of Private Sharing requests.
This demo app has been created using the React Native CLI command npx react-native init
to create a new React Native project, and then the digi.me SDKs added to the native projects.
Requirements
Important Please ensure that the development environment is setup according to the React Native Setting up the development environment guide for React Native CLI Quickstart.
Please also see Android and iOS repositories for specific platform digi.me SDK requirements.
Configuring SDKs
The Contract ID and App ID
Before accessing the public APIs, a valid Contract ID and App ID are required. The Contract ID uniquely identifies a contract with the user that defines what type of data you want and how much you will get etc.
This demo app references a demo contract from the sample contracts page.
The .p12 File
All content retrieved is encrypted in transit using the public key bound to its Private Sharing contract. For the SDK to be able to decrypt content transparently, a matching private key must be provided. The .p12 file is an archive format used to bundle the private key with its certificate. The digi.me SDKs accepts PKCS12 encoded files as the default key storage format.
To register a custom Private Sharing contract, please check out custom sharing contracts page.
Getting Started
1. Obtaining your Contract ID, Application ID & Private Key:
To access the digi.me platform, you need to obtain an AppID for your application. You can get yours by registering for one here.
In a production environment, you will also be required to obtain your own Contract ID and Private Key from digi.me support. However, for sandbox purposes, we provide the following example values:
Example Contract ID: fJI8P5Z4cIhP3HawlXVvxWBrbyj5QkTF
Example Private Key:
Download: p12 Key Store
Password: monkey periscope
The p12 file has already been included in the assets folder for both Android and iOS projects
2. Configuring the demo app
a. Updating the credentials in JavaScript
The NativeBridge is used to communicate between JavaScript and Native iOS/Android code.
The initSDK
function accepts the contractID, appId, p12 filename, and p12 password.
In App.js, update to add your AppID:
js
nativeBridge.initSDK("fJI8P5Z4cIhP3HawlXVvxWBrbyj5QkTF","YOUR_APP_ID","fJI8P5Z4cIhP3HawlXVvxWBrbyj5QkTF","monkey periscope");
where YOUR_APP_ID
should be replaced with your AppID
.
b. iOS: Updating the URL Scheme
Update the custom URL scheme so that the app can receive the callback from the digi.me app.
In Info.plist, update to add your AppID:
xml
<key>CFBundleURLSchemes</key><array><string>digime-ca-YOUR_APP_ID</string></array></dict>
where YOUR_APP_ID
should be replaced with your AppID
.
Using a different contract ID
To use a different contract ID, the assets and references must be updated,
- Add your .p12 file to 'android/app/src/main/assets'
- Import the .p12 file to the ios project using xCode and set the target membership to 'digimedemo'
- Update the contract ID, .p12 file, and .p12 password referenced in the App.js NativeBridge.initSDK() call
Installation and First Run
1. Install dependencies
npm install
2. Configure demo properties
Add the AppID to App.js. See Configuring demo app for more information.
3. Run the app
for Android:
npm run android
for iOS
npm run ios
Copyright © 2021 digi.me Ltd. All rights reserved.