Configuration
Introduction
This section describes the first steps to integrate the OneWelcome React Native SDK with an existing React Native project. In this topic we will describe how you can configure your project to use our SDK.
The SDK consists of a react-native wrapper for the OneWelcome Android and iOS SDKs. You will need explicit access to the Android and iOS SDKs, the wrapper is public.
Requirements
Android:
- Minium API level 23
For more information see android SDK documentation
iOS:
- Minimum iOS version 13
For more information see iOS SDK documentation
React Native
- Minimum version 0.63
Lower versions of React Native might or might not work and have not been tested.
Adding the dependency
We start by installing the sdk with your prefered package manager.
npm: npm install @onewelcome/react-native-sdk --save
yarn: yarn add @onewelcome/react-native-sdk
SDK Configuration
- Get access to https://repo.onewelcome.com/artifactory/onegini-sdk
- Use https://github.com/onewelcome/sdk-configurator on your application (instructions can be found there)
Android:
Please note, that adding a lot of dependencies to the project can lead to a build exception that indicates your app has reached a limit of the Android app build architecture. In such case you should use multidex.
Make sure you are running a minSdkVersion of 23.
Modify android/app/build.gradle
: Add to android-> defaultConfig section:
The OneWelcome Android SDK is uploaded to a private artifactory repository. In order to obtain credentials, navigate to https://onewelcome.atlassian.net/servicedesk/customer/portals and submit a request for access. Assuming you already have access to this repository, you will have to provide credentials in order to access the repository.
Set onegini artifactory user and onegini_artifactory_ password at android/gradle.properties
or globally for Gradle in ~/gradle/gradle.properties
(recommended).
You will have to manually add this repository to your android/build.gradle
for it to be able to download the Native Android SDK.
Add in allprojects->repositories in android/build.grade
.
Modify android/app/src/main/AndroidManifest.xml
. Add <intent-filter> to your MainActivity for listening for browser redirects, this is how the browser communicates back to the app after successful authentication. The scheme="reactnativeexample"
should be changed to your schema (will be provided by onegini-sdk-configurator):
Setup the OneWelcome config: Generate a OneginiConfigModel
and keystore.bks
with SDK Configurator. The configurator will put OneginiConfigModel
into the RN application's package_classpath.OneginiConfigModel (e.g. com.exampleapp.OneginiConfigModel) and the keystore.bks
into /res/raw.
After using the configurator - you have 2 options:
- Keep it as it is.
- If there is a need to move
OneginiConfigModel
to another place - it's required to specify custom classpath for OneWelcomeSdk:setConfigModelClassName(className)
. More information HERE.
Set up the security controller
In order to change security options you should create your own instance of SecurityController and pass it to OneWelcomeSdk - See the setSecurityControllerClassName(className)
. More information HERE.
By default, debug detection and root detection are enabled in the SDK. This also means that you can not run the SDK on an android emulator without adjusting these settings.
You should add the path to this SecurityController class in the in config when instantiating the SDK in react native. See HERE for how to set up the config.
When minifying is enabled, proguard will change the names of classes. This prevents the SDK from loading a class with reflection. The following rule prevents proguard from modifying the SecurityController class. Make sure to replace the classPath here with the one in your project.
Add to android/app/proguard-rules.pro
Add in your project package_classpath e.g.. com.rnexampleapp
These settings are for development only. In production you should have debugDetection and rootDetection enabled.
iOS:
This section describes how to set up the OneWelcome Native iOS SDK and configurations for iOS
Adding the native sdk
The Onegini SDK is uploaded to the Onegini Artifactory repository. In order to let CocoaPods use an Artifactory repository you need to install a specific plugin.
Run the following command to install the CocoaPods plugin.
It is strongly recommended that you install CocoaPods as a Rubygem and not through Homebrew. Installing with Homebrew may cause issues with the CocoaPods hooks mechanism that the plugin relies on.
The Onegini SDK repository is not a public repository. You must provide credentials in order to access the repo.
Create a file named .netrc in your Home folder (~/) and add the following contents to it. (Replace the <username> and <password> with the credentials that you use to login to support.onegini.com.)
The Onegini CocoaPods repository must be added to your local machine using the following command:
In order to update the Repository you must manually perform an update:
Add next toios/Podfile
(before app target):
Add the following into your post install script in ios/Podfile
Run pod install
Add SecurityController.h
and SecurityController.m
as described HERE
Optional: In order to support FaceID or TouchID add next to ios/<project-name>/info.plist
:
Biometrics will not work on iOS simulator, only on the real devices
Linking Native Code
RN >= 60.0
cd ios && pod install
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜onewelcome-react-native-sdk
and addRNOnewelcomeSdk.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNOneginiSdk.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
-
Open up
android/app/src/main/java/[...]/MainActivity.java
-
Add
import com.onewelcome.mobile.RNOneWelcomeSdkPackage;
to the imports at the top of the file -
Add
new RNOneWelcomeSdkPackage()
to the list returned by thegetPackages()
method -
Append the following lines to
android/settings.gradle
:
- Insert the following lines inside the dependencies block in
android/app/build.gradle: