initialize
The initialize function sets up the Beyond Identity SDK and gives your app access to the rest of the SDK functions. The initialize function must be called first, before any other SDK functions.
Dependencies​
The initialize function requires the Beyond Identity SDK.
- JavaScript
- Kotlin
- Swift
- React Native
- Flutter
yarn add @beyondidentity/bi-sdk-js
or
npm install @beyondidentity/bi-sdk-js
Requirements​
minSdkVersion26 or later.- Apps with Java sources that call the SDK must build with JDK 21. Kotlin-only apps are unaffected.
- Biometric prompts require a
FragmentActivity, such asAppCompatActivity.
Gradle​
To enable the retrieval of Cloudsmith hosted packages via Gradle, we need to add the Cloudsmith repository to
the root/build.gradle file.
repositories {
maven {
url "https://packages.beyondidentity.com/public/bi-sdk-android/maven/"
}
}
After the repository is added, we can specify the Beyond Identity dependencies.
dependencies {
implementation 'com.beyondidentity.android.sdk:embedded:[version]'
}
Requirements​
The SDK supports iOS 15.0 or later.
Swift Package Manager​
From Xcode​
- From the Xcode
Filemenu, selectAdd Packagesand add the following url:
https://github.com/gobeyondidentity/bi-sdk-swift
- Select a version and hit Next.
- Select a target matching the SDK you wish to use.
From Package.swift​
- With Swift Package Manager,
add the following
dependencyto yourPackage.swift:
dependencies: [
.package(url: "https://github.com/gobeyondidentity/bi-sdk-swift.git", from: [version])
]
- Run
swift build
Cocoapods​
Add the pod to your Podfile:
pod 'BeyondIdentityEmbedded'
And then run:
pod install
After installing import with
import BeyondIdentityEmbedded
Using react-native init or an expo app.​
- react-native init
- expo
The SDK requires React Native 0.88.0 or later.
Install the SDK with yarn or npm:
yarn add @beyondidentity/bi-sdk-react-native
npm install @beyondidentity/bi-sdk-react-native
Update native requirements in your ios and android folders:
iOS​
Make sure your ios/Podfile supports "minimum deployment target" 15.1 or later
platform :ios, '15.1'
Navigate to your ios folder and run:
cd ios && pod install
Android​
Make sure your android/build.gradle supports minSdkVersion 26 or later
buildscript {
ext {
minSdkVersion = 26
}
}
Add the following maven url to your repositories in your android/build.gradle
allprojects {
repositories {
maven {
url "https://packages.beyondidentity.com/public/bi-sdk-android/maven/"
}
}
}
For biometric prompts to work on Android, your Activity must extend FragmentActivity. The default ReactActivity already does.
This package requires custom native code and can be used with Development builds or prebuild and cannot be used with Expo Go.
npx expo install @beyondidentity/bi-sdk-react-native
Add the SDK config plugin to the plugins array of your app.{json,config.js,config.ts}:
{
"expo": {
"plugins": [["@beyondidentity/bi-sdk-react-native"]]
}
}
The SDK requires certain minimum native versions. Set these requirments with expo-build-properties.
npx expo install expo-build-properties
{
"expo": {
"plugins": [
["@beyondidentity/bi-sdk-react-native"],
[
"expo-build-properties",
{
"android": {
"minSdkVersion": 26
},
"ios": {
"deploymentTarget": "15.1"
}
}
]
]
}
}
Finally, rebuild your app as described in Expo's Adding custom native code guide.
The SDK requires Flutter 3.44.0 or later.
Pub.Dev​
Add the Beyond Identity Embedded SDK to your dependencies
dependencies:
bi_sdk_flutter: x.y.z
and run an implicit flutter pub get.
Update Android​
Please make sure your android/build.gradle supports minSdkVersion 26 or later.
buildscript {
ext {
minSdkVersion = 26
}
}
For biometric prompts to work on Android, your Activity must extend FragmentActivity. Use FlutterFragmentActivity instead of FlutterActivity:
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity : FlutterFragmentActivity()
Update iOS​
Please make sure your project supports "minimum deployment target" 15.1 or later.
In your ios/Podfile set:
platform :ios, '15.1'
Prerequisites​
Before making a call to initialize, you must import the SDK.
- JavaScript
- Kotlin
- Swift
- React Native
- Flutter
import { Embedded } from '@beyondidentity/bi-sdk-js';
import com.beyondidentity.embedded.sdk.EmbeddedSdk
import BeyondIdentityEmbedded
import { Embedded } from '@beyondidentity/bi-sdk-react-native';
import 'package:bi_sdk_flutter/embeddedsdk.dart';
Parameters​
- JavaScript
- Kotlin
- Swift
- React Native
- Flutter
| Parameter | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
| config | Config | An optional configuration object. | ||||||
| ||||||||
| Parameter | Type | Description |
|---|---|---|
| app | Application | Required. The application context. |
| biometricAskPrompt | String | The title of the biometric prompt the user sees when authenticating or binding a passkey. Defaults to app.getString(R.string.embedded_export_biometric_prompt_title). |
| logger | (String) -> Unit | Required. Custom logger to get logs from the SDK. |
| allowedDomains | List<String>? | Optional array of domains that we whitelist against for network operations. This will default to Beyond Identity's allowed domains. |
| Parameter | Type | Description |
|---|---|---|
| allowedDomains | [String]? | An optional array of whitelisted domains for network operations. This will default to Beyond Identity's allowed domains when not provided or is empty. |
| biometricAskPrompt | String | Required. The title of the biometric prompt the user sees when authenticating or binding a passkey. |
| logger | ((OSLogType, String) -> Void)? | Optional function to log output. |
| callback | @escaping (Result<Void, BISDKError>) -> Void | Required. A callback function that returns the result of the initialization operation. |
The async throws variant takes the same parameters without callback, returns the result directly, and throws a BISDKError on failure.
| Parameter | Type | Description |
|---|---|---|
| biometricAskPrompt | string | Required. The title of the biometric prompt the user sees when authenticating or binding a passkey. |
| allowedDomains | string[]? | An optional array of whitelisted domains for network operations. This will default to Beyond Identity's allowed domains when not provided or is empty. |
| Parameter | Type | Description |
|---|---|---|
| biometricAskPrompt | String | Required. The title of the biometric prompt the user sees when authenticating or binding a passkey. |
| allowedDomains | List<String>? | Optional array of domains that we whitelist against for network operations. This will default to Beyond Identity's allowed domains. |
| logger | Future<Function>? | Custom logger to get logs from the SDK. To enable logging, pass EmbeddedSdk.enableLogger(), otherwise, pass null. |
Returns​
- JavaScript
- Kotlin
- Swift
- React Native
- Flutter
On success, returns a Promise that resolves to an instance of the Embedded class. Call the other SDK functions on this instance.
EmbeddedSdk is a singleton object, so init returns nothing. Call the other SDK functions on EmbeddedSdk once it returns.
init throws a DatabaseSetupException if the SDK cannot set up its local database. The other functions report failure as a Throwable in their Result.
The callback receives .success(()), or .failure(BISDKError). The async throws variant returns nothing and throws a BISDKError on failure. Once it succeeds, call the other SDK functions on Embedded.shared.
Every Swift SDK function reports failure as a BISDKError:
| Case | Meaning |
|---|---|
description(String) | A failure described by the associated message. |
passkeyNotFound | The passkey does not exist on this device. |
invalidUrlType | The URL is not valid for this function. |
initializationIncomplete | Embedded.shared was used before Embedded.initialize completed. |
outOfMemory | There is not enough disk space to complete the operation. |
insufficientWritePermission(String), insufficientReadPermission(String) | The SDK cannot write to or read from the directory at the given path. |
unknownWritePermission(String), unknownReadPermission(String) | An unknown error occurred writing to or reading from the directory at the given path. |
On success, returns a Promise that resolves to the string 'success'. Call the other SDK functions on Embedded once it resolves. On failure, the Promise rejects with an error.
Returns a Future<void> that completes once the SDK is initialized, and completes with an error if initialization fails. Call the other SDK functions on EmbeddedSdk once it completes.
Examples​
Example: initialize the SDK before calling its functions​
- JavaScript
- Kotlin
- Swift
- React Native
- Flutter
// --- Initialize with required arguments
try {
const embedded = await Embedded.initialize();
console.log("Initialization successful", embedded);
} catch (error) {
console.error("Initialization failed:", error);
}
// --- Initialize with required and optional arguments
const config = {
allowedDomains: ["example.com", "another-example.com"],
logger: function (logType, message) {
console.log(`[${logType}] ${message}`);
},
};
try {
const embedded = await Embedded.initialize(config);
console.log("Initialization successful", embedded);
} catch (error) {
console.error("Initialization failed:", error);
}
// --- Initialize with required arguments
EmbeddedSdk.init(
app = this,
logger = { logMessage ->
Log.d("BeyondIdentityLog", logMessage)
}
)
// --- Initialize with required and optional arguments
EmbeddedSdk.init(
app = this,
biometricAskPrompt = "Please provide your biometric",
logger = { logMessage ->
Log.d("BeyondIdentityLog", logMessage)
},
allowedDomains = listOf("example.com", "another-example.com")
)
// --- Initialize from an Activity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
EmbeddedSdk.init(
app = application,
logger = { logMessage ->
Log.d("BeyondIdentityLog", logMessage)
}
)
// Hand the SDK the Activity that called init()
EmbeddedSdk.setActivity(this)
}
}
// --- Initialize with required arguments
Embedded.initialize(
biometricAskPrompt: "Please provide your biometric"
) { result in
switch result {
case .success():
print("Initialization successful")
case .failure(let error):
print("Initialization failed: \(error)")
}
}
// --- Initialize with required and optional arguments
Embedded.initialize(
allowedDomains: ["example.com", "another-example.com"],
biometricAskPrompt: "Please provide your biometric",
logger: { (logType, message) in
print("\(logType): \(message)")
}
) { result in
switch result {
case .success():
print("Initialization successful")
case .failure(let error):
print("Initialization failed: \(error)")
}
}
// --- Initialize with required arguments
try {
const response = await Embedded.initialize("Please provide your biometric");
console.log(response);
} catch (error) {
console.error("Initialization failed:", error);
}
// --- Initialize with required and optional arguments
try {
const response = await Embedded.initialize(
"Please provide your biometric",
["example.com", "another-example.com"]
);
console.log(response);
Embedded.logEventEmitter.addListener(
"BeyondIdentityLogger",
(message: string) => {
console.log(message);
}
);
} catch (error) {
console.error("Initialization failed:", error);
}
// --- Initialize with required arguments
EmbeddedSdk.initialize('Please provide your biometric');
// --- Initialize with required and optional arguments
EmbeddedSdk.initialize(
'Please provide your biometric',
allowedDomains: ["example.com", "another-example.com"],
logger: EmbeddedSdk.enableLogger(),
).then((_) {
print('Initialization successful');
}).catchError((error) {
print('Initialization failed: $error');
});