Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
FolderOrigin-RevId: /usr/src/app/bi-sdk-react-native
  • Loading branch information
turnipdabeets authored and bi-ci-bot committed Sep 28, 2023
1 parent 19acaec commit fba1e0d
Show file tree
Hide file tree
Showing 118 changed files with 11,482 additions and 5,984 deletions.
2 changes: 1 addition & 1 deletion BeyondIdentityEmbeddedReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ Pod::Spec.new do |s|
s.source_files = "ios/**/*.{h,m,mm,swift}"

s.dependency "React-Core"
s.dependency "BeyondIdentityEmbedded", '2.0.0'
s.dependency "BeyondIdentityEmbedded", '2.0.1'

end
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.1] - 2023-09-25

### Added

- New function getAuthenticationContext to retrieve authentication parameters for the ongoing transaction.
- New function authenticateOtp to enable authentication with a one time password.
- New function redeemOtp to enable redeeming a one time password.

## [2.0.0] - 2023-01-09

### Added

- A new expo config plugin to support development builds or prebuilds on expo

### Changed

- Rename instances of `Credential` to `Passkey`
- Update example app to authenticate with Beyond Identity by using Invocation Type `manual`
- Prefixed `Credential` properties to prevent name conflicts
- Nest tenantId, realmId, and identityId under appropriate objects in the `Credential`
- Update support links in the example app

### Fixed

- Scheme without a path is now recognized as a valid URL when binding a credential

## [1.0.0] - 2022-09-21

### Changed
- Updated the React Native SDK to support our newly released Secure Customer product. See the [documentation](https://developer.beyondidentity.com/docs/v1/sdks/react-native-sdk/overview) for more details.

- Updated the React Native SDK to support our newly released Secure Customer product. See the [documentation](https://developer.beyondidentity.com) for more details.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@

### Embedded SDK

Goodbye, passwords! The Beyond Identity SDK for React Native is a wrapper around our Native Embedded SDKs ([Android](https://github.com/gobeyondidentity/bi-sdk-android) and [iOS](https://github.com/gobeyondidentity/bi-sdk-swift)), which allows you to embed the Passwordless experience into your product. Users will not need to download the Beyond Identity Authenticator. This SDK supports OIDC and OAuth2.
Goodbye, passwords! The Beyond Identity SDK for React Native is a wrapper around our native SDKs ([Android](https://github.com/gobeyondidentity/bi-sdk-android) and [iOS](https://github.com/gobeyondidentity/bi-sdk-swift)), which allows you to embed the Passwordless experience into your product. A set of functions are provided to you through the Embedded namespace. This SDK supports OIDC and OAuth 2.0.

## Installation

### Using a [bare expo](https://docs.expo.dev/bare/hello-world/) or [react-native init](https://reactnative.dev/docs/environment-setup) app.
### Using [react-native init](https://reactnative.dev/docs/environment-setup).

1. Install the SDK:

```
yarn add @beyondidentity/bi-sdk-react-native
```

or

```
npm install @beyondidentity/bi-sdk-react-native
```

2. Update Native Requirements in your ios/android folders:

Please make sure your iOS project supports "minimum deployment target" 13.0 or later.
Expand Down Expand Up @@ -67,14 +71,17 @@ allprojects {
```

### Using `expo`
> :warning: This package cannot be used in "Expo Go" because [it requires custom native code](https://docs.expo.io/workflow/customizing/). However you can leverage this library with a [development build](https://docs.expo.dev/development/introduction/) or [prebuild](https://docs.expo.dev/workflow/prebuild/).

> :warning: This package [requires custom native code](https://docs.expo.io/workflow/customizing/) and can be used with [Development builds](https://docs.expo.dev/develop/development-builds/introduction/) or [prebuild](https://docs.expo.dev/workflow/prebuild/) and cannot be used with Expo Go.
1. Install the SDK:

```
expo install @beyondidentity/bi-sdk-react-native
npx expo install @beyondidentity/bi-sdk-react-native
```

2. Add the SDK [config plugin](https://docs.expo.dev/guides/config-plugins/) to the [plugins array](https://docs.expo.dev/versions/latest/config/app/#plugins) of your app.{json,config.js,config.ts}:

```
{
"expo": {
Expand All @@ -85,26 +92,10 @@ expo install @beyondidentity/bi-sdk-react-native
}
```

3. Set native requirments either with [expo-build-properties](https://docs.expo.dev/versions/latest/sdk/build-properties/) or modify project [static files](https://docs.expo.dev/guides/config-plugins/#static-modification)

A. Modify the following static files

android/gradle.properties
```
android.minSdkVersion=26
```
ios/Podfile.properties.json
```
"ios.deploymentTarget": "13.0"
```

*or*

B. Add [expo-build-properties](https://docs.expo.dev/versions/latest/sdk/build-properties/) to your app.{json,config.js,config.ts}:

3. Set native requirments with [expo-build-properties](https://docs.expo.dev/versions/latest/sdk/build-properties/). Add [expo-build-properties](https://docs.expo.dev/versions/latest/sdk/build-properties/) to your app.{json,config.js,config.ts}:

```
expo install expo-build-properties
npx expo install expo-build-properties
```

```
Expand All @@ -128,7 +119,7 @@ expo install expo-build-properties
}
```

4. Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.dev/workflow/customizing/) guide.
4. Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.dev/workflow/customizing/#generate-native-projects-with-prebuild) guide.

## Usage

Expand All @@ -149,6 +140,15 @@ Embedded.initialize(

You may also add a listener to log native events with `Embedded.logEventEmitter` after initializing.

```javascript
Embedded.logEventEmitter.addListener(
'BeyondIdentityLogger',
(message: string) => {
console.log(message);
}
);
```

## Example App

Clone the following repo and use the available comands to see the SDK in action!
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.1'
classpath 'com.android.tools.build:gradle:7.4.2'
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Expand Down Expand Up @@ -141,7 +141,7 @@ dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

implementation "com.beyondidentity.android.sdk:embedded:2.0.0"
implementation "com.beyondidentity.android.sdk:embedded:2.0.1"

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2"
}
4 changes: 2 additions & 2 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
BiSdkReactNative_kotlinVersion=1.6.10
BiSdkReactNative_compileSdkVersion=31
BiSdkReactNative_kotlinVersion=1.8.0
BiSdkReactNative_compileSdkVersion=33
BiSdkReactNative_targetSdkVersion=31
101 changes: 97 additions & 4 deletions android/src/main/java/com/bisdkreactnative/BiSdkReactNativeModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import android.content.Context
import android.content.Intent
import android.util.Log
import com.beyondidentity.embedded.sdk.EmbeddedSdk
import com.beyondidentity.embedded.sdk.models.AuthenticateResponse
import com.beyondidentity.embedded.sdk.models.AuthenticationContext
import com.beyondidentity.embedded.sdk.models.Passkey
import com.beyondidentity.embedded.sdk.models.OtpChallengeResponse
import com.beyondidentity.embedded.sdk.models.RedeemOtpResponse
import com.beyondidentity.embedded.sdk.models.State
import com.beyondidentity.embedded.sdk.models.State.ACTIVE
import com.beyondidentity.embedded.sdk.models.State.REVOKED
Expand Down Expand Up @@ -79,10 +83,26 @@ class BiSdkReactNativeModule(reactContext: ReactApplicationContext) :

EmbeddedSdk.authenticate(url, passkeyId) { authResult ->
authResult.onSuccess { authResponse ->
val n = WritableNativeMap()
n.putString("redirectUrl", authResponse.redirectUrl ?: "")
n.putString("message", authResponse.message ?: "")
promise.resolve(n)
promise.resolve(makeAuthenticationResponseMap(authResponse))
}
authResult.onFailure { t -> promise.reject(t) }
}
}

@ReactMethod
fun authenticateOtp(
url: String,
email: String,
promise: Promise
) {
if (!isEmbeddedSdkInitialized) {
promise.reject(Throwable(INITIALIZE_ERROR))
return
}

EmbeddedSdk.authenticateOtp(url, email) { authResult ->
authResult.onSuccess { otpChallengeResponse ->
promise.resolve(makeOtpChallengeResponseMap(otpChallengeResponse))
}
authResult.onFailure { t -> promise.reject(t) }
}
Expand Down Expand Up @@ -121,6 +141,21 @@ class BiSdkReactNativeModule(reactContext: ReactApplicationContext) :
}
}

@ReactMethod
fun getAuthenticationContext(url: String, promise: Promise) {
if (!isEmbeddedSdkInitialized) {
promise.reject(Throwable(INITIALIZE_ERROR))
return
}

EmbeddedSdk.getAuthenticationContext(url) { authContextResult ->
authContextResult.onSuccess { authContextResponse ->
promise.resolve(makeAuthenticationContextResponseMap(authContextResponse))
}
authContextResult.onFailure { t -> promise.reject(t) }
}
}

@ReactMethod
fun getPasskeys(promise: Promise) {
if (!isEmbeddedSdkInitialized) {
Expand Down Expand Up @@ -185,6 +220,30 @@ class BiSdkReactNativeModule(reactContext: ReactApplicationContext) :
promise.resolve(EmbeddedSdk.isBindPasskeyUrl(url))
}

@ReactMethod
fun redeemOtp(url: String, otp: String, promise: Promise) {
if (!isEmbeddedSdkInitialized) {
promise.reject(Throwable(INITIALIZE_ERROR))
return
}

EmbeddedSdk.redeemOtp(url, otp) { redeemResult ->
redeemResult.onSuccess { redeemOtpResponse ->
when (redeemOtpResponse) {
is RedeemOtpResponse.Success -> {
val authResponse = redeemOtpResponse.authenticateResponse
promise.resolve(makeAuthenticationResponseMap(authResponse))
}
is RedeemOtpResponse.FailedOtp -> {
val otpChallengeResponse = redeemOtpResponse.otpChallengeResponse
promise.resolve(makeOtpChallengeResponseMap(otpChallengeResponse))
}
}
}
redeemResult.onFailure { t -> promise.reject(t) }
}
}

@ReactMethod
fun addListener(eventName: String?) {
// Keep: Required for RN built in Event Emitter Calls.
Expand Down Expand Up @@ -221,6 +280,40 @@ class BiSdkReactNativeModule(reactContext: ReactApplicationContext) :
}
}

private fun makeAuthenticationContextResponseMap(authContextResponse: AuthenticationContext): WritableNativeMap {
val map = WritableNativeMap()
map.putString("authUrl", authContextResponse.authUrl)

val applicationMap = WritableNativeMap()
applicationMap.putString("id", authContextResponse.application.id)
applicationMap.putString("displayName", authContextResponse.application.displayName ?: "")
map.putMap("application", applicationMap)

val originMap = WritableNativeMap()
originMap.putString("sourceIp", authContextResponse.origin.sourceIp ?: "")
originMap.putString("userAgent", authContextResponse.origin.userAgent ?: "")
originMap.putString("geolocation", authContextResponse.origin.geolocation ?: "")
originMap.putString("referer", authContextResponse.origin.referer ?: "")
map.putMap("origin", originMap)

return map
}

private fun makeAuthenticationResponseMap(authResponse: AuthenticateResponse): WritableNativeMap {
val map = WritableNativeMap()
map.putString("redirectUrl", authResponse.redirectUrl ?: "")
map.putString("message", authResponse.message ?: "")
map.putString("passkeyBindingToken", authResponse.passkeyBindingToken ?: "")

return map
}

private fun makeOtpChallengeResponseMap(otpChallengeResponse: OtpChallengeResponse): WritableNativeMap {
val map = WritableNativeMap()
map.putString("url", otpChallengeResponse.url)
return map
}

private fun makePasskeyMap(passkey: Passkey): WritableNativeMap {
val map = WritableNativeMap()
map.putString("id", passkey.id)
Expand Down
2 changes: 2 additions & 0 deletions example/.bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1
3 changes: 2 additions & 1 deletion example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
root: true,
extends: '@react-native-community',
extends: "@react-native-community",
quotes: [1, "double", "avoid-escape"],
};
66 changes: 0 additions & 66 deletions example/.flowconfig

This file was deleted.

Loading

0 comments on commit fba1e0d

Please sign in to comment.