Skip to content

Commit

Permalink
merge 5.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Dubovik committed Jul 6, 2022
2 parents 6066a30 + 09de8c8 commit 9e071e6
Show file tree
Hide file tree
Showing 16 changed files with 463 additions and 363 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## next-version

## [5.4.0] - 2022-06-22

### Changed:
- Public:
- Public: Update underlying Onfido native SDK versions:
- Android 12.2.0 (up from 11.5.0)
- iOS 25.1.0 (up from 24.6.0)

## [5.3.0] - 2022-05-02

### Changed:
Expand Down
2 changes: 2 additions & 0 deletions SampleApp/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class App extends Component {
message: '--',
sdkToken: null,
sdkFlowComplete: false,
workflowRunId: null,
};

componentDidMount() {
Expand All @@ -38,6 +39,7 @@ export default class App extends Component {
startSDK = () => {
Onfido.start({
sdkToken: this.state.sdkToken,
workflowRunId: this.state.workflowRunId,
localisation: {
ios_strings_file_name: 'Localizable',
},
Expand Down
2 changes: 1 addition & 1 deletion SampleApp/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ android {
}
}
// TODO: ET-385 Remove this workaround for React 0.62.2 when upgrading to a React 0.63+.
force "com.facebook.soloader:soloader:0.8.2"
force "com.facebook.soloader:soloader:0.9.0+"
}
}

Expand Down
47 changes: 47 additions & 0 deletions SampleApp/backend-server-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
*
* The applicant must be created in your backend server. The apiToken must never be in code or in
* memory of the client code, or nefarious actors will be able to mis-use it.
* If the workflowId is provided, the standard steps will be ovewritten.
*
* The code below is meant to demo a working integration of the Onfido React Native SDK.
*/

const createSdkToken = async (applicant, applicationId) => {
const apiToken = 'YOUR_API_TOKEN_HERE'; // DO NOT expose your api token in client code: keep it on the backend server.
const workflowId = null; // This is not mandatory for the standard integration, and make sure to keep it on the backend server.

const applicantResponse = await fetch(
'https://api.onfido.com/v3/applicants',
Expand Down Expand Up @@ -82,8 +84,53 @@ const createSdkToken = async (applicant, applicationId) => {
sdkToken: null,
};
});

let workflowRunId;
if (workflowId) {
const workflowRunIdBody = {
workflow_id: workflowId,
applicant_id: sdkRequestBody.applicant_id,
};
const workflowRunIdResponse = await fetch(
'https://api.onfido.com/v4/workflow_runs',
{
method: 'POST',
headers: {
Authorization: 'Token token=' + apiToken,
'Content-Type': 'application/json',
},
body: JSON.stringify(workflowRunIdBody),
},
);

if (!workflowRunIdResponse.ok) {
console.log(workflowRunIdResponse, 'error');
return {
status: 'Unable to start the SDK',
message: 'Error retrieving workflow run id from server',
sdkToken: sdkToken,
workflowRunId: null,
};
}

await workflowRunIdResponse
.json()
.then((responseJson) => (workflowRunId = responseJson.id))
.catch((err) => {
console.log(err, 'error');
return {
status: 'Unable to start the SDK',
message:
'Unexpected error occurred while trying to get the workflow run id from the response.',
sdkToken: sdkToken,
workflowRunId: null,
};
});
}

return {
sdkToken,
workflowRunId,
};
};

Expand Down
10 changes: 5 additions & 5 deletions SampleApp/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ PODS:
- ReactCommon/turbomodule/core (= 0.67.2)
- fmt (6.2.1)
- glog (0.3.5)
- Onfido (24.6.0)
- onfido-react-native-sdk (5.2.0):
- Onfido (= 24.6.0)
- Onfido (25.1.0)
- onfido-react-native-sdk (5.3.0):
- Onfido (= 25.1.0)
- React
- RCT-Folly (2021.06.28.00-v2):
- boost
Expand Down Expand Up @@ -391,8 +391,8 @@ SPEC CHECKSUMS:
FBReactNativeSpec: c94002c1d93da3658f4d5119c6994d19961e3d52
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 85ecdd10ee8d8ec362ef519a6a45ff9aa27b2e85
Onfido: 7b63c00ed1a41574a6d1549d372613b4c01de269
onfido-react-native-sdk: afb741637b6afb083a790818f46694c2da855ce4
Onfido: a1645279c7b6ca8de5bb95d27af53c523ffd731c
onfido-react-native-sdk: 6f6e18b2dece6203cba5483fdcf46664b09c8795
RCT-Folly: 803a9cfd78114b2ec0f140cfa6fa2a6bafb2d685
RCTRequired: cd47794163052d2b8318c891a7a14fcfaccc75ab
RCTTypeSafety: 393bb40b3e357b224cde53d3fec26813c52428b1
Expand Down
140 changes: 68 additions & 72 deletions SampleApp/ios/SampleApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ repositories {
dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation "com.onfido.sdk.capture:onfido-capture-sdk:11.5.0"
implementation "com.onfido.sdk.capture:onfido-capture-sdk:12.2.0"
implementation "com.squareup.okhttp3:logging-interceptor:3.8.0"
implementation "com.squareup.okhttp3:okhttp:3.8.0"
// Fix for crash due to 'java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/swiperefreshlayout/widget/SwipeRefreshLayout;''
Expand Down
145 changes: 78 additions & 67 deletions android/src/main/java/com/onfido/reactnative/sdk/OnfidoSdkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.UnexpectedNativeTypeException;

import java.util.List;
import java.util.ArrayList;

import com.facebook.react.bridge.Arguments;

import com.onfido.android.sdk.capture.Onfido;
import com.onfido.android.sdk.capture.DocumentType;
import com.onfido.android.sdk.capture.EnterpriseFeatures;
import com.onfido.android.sdk.capture.ui.options.FlowStep;
import com.onfido.android.sdk.capture.Onfido;
import com.onfido.android.sdk.capture.OnfidoConfig;
import com.onfido.android.sdk.capture.OnfidoFactory;
import com.onfido.android.sdk.capture.errors.EnterpriseFeatureNotEnabledException;
import com.onfido.android.sdk.capture.errors.EnterpriseFeaturesInvalidLogoCobrandingException;
import com.onfido.android.sdk.capture.ui.camera.face.FaceCaptureStep;
import com.onfido.android.sdk.capture.ui.camera.face.FaceCaptureVariant;
import com.onfido.android.sdk.capture.DocumentType;
import com.onfido.android.sdk.capture.utils.CountryCode;
import com.onfido.android.sdk.capture.ui.options.CaptureScreenStep;
import com.onfido.android.sdk.capture.errors.*;
import com.onfido.android.sdk.capture.ui.options.FlowStep;
import com.onfido.android.sdk.capture.utils.CountryCode;
import com.onfido.android.sdk.workflow.OnfidoWorkflow;
import com.onfido.android.sdk.workflow.WorkflowConfig;

import java.util.ArrayList;
import java.util.List;

public class OnfidoSdkModule extends ReactContextBaseJavaModule {

Expand All @@ -38,7 +38,7 @@ public OnfidoSdkModule(final ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
this.client = OnfidoFactory.create(reactContext).getClient();
this.activityEventListener = new OnfidoSdkActivityEventListener(client);
activityEventListener = new OnfidoSdkActivityEventListener(client);
reactContext.addActivityEventListener(activityEventListener);
}

Expand All @@ -58,7 +58,9 @@ public String getName() {
return "OnfidoSdk";
}

/** NOTE: This indirection is used to allow unit tests to mock this method */
/**
* NOTE: This indirection is used to allow unit tests to mock this method
*/
protected Activity getCurrentActivityInParentClass() {
return super.getCurrentActivity();
}
Expand All @@ -70,10 +72,8 @@ public void start(final ReadableMap config, final Promise promise) {

try {
final String sdkToken;
final FlowStep[] flowStepsWithOptions;
try {
sdkToken = getSdkTokenFromConfig(config);
flowStepsWithOptions = getFlowStepsFromConfig(config);
} catch (Exception e) {
currentPromise.reject("config_error", e);
currentPromise = null;
Expand All @@ -88,72 +88,87 @@ public void start(final ReadableMap config, final Promise promise) {
}

try {
/* Native SDK seems to have a bug that if an empty EnterpriseFeatures is passed to it,
the logo will still be hidden, even if explicitly set to false */
EnterpriseFeatures.Builder enterpriseFeaturesBuilder = EnterpriseFeatures.builder();
boolean hasSetEnterpriseFeatures = false;

if (getBooleanFromConfig(config, "hideLogo")) {
enterpriseFeaturesBuilder.withHideOnfidoLogo(true);
hasSetEnterpriseFeatures = true;
} else if (getBooleanFromConfig(config, "logoCobrand")) {
int cobrandLogoLight = currentActivity.getApplicationContext().getResources().getIdentifier(
"cobrand_logo_light",
"drawable",
currentActivity.getApplicationContext().getPackageName()
);
int cobrandLogoDark = currentActivity.getApplicationContext().getResources().getIdentifier(
"cobrand_logo_dark",
"drawable",
currentActivity.getApplicationContext().getPackageName()
);
if (cobrandLogoLight == 0 || cobrandLogoDark == 0) {
currentPromise.reject("error", new Exception("Cobrand logos were not found"));
currentPromise = null;
return;
}
enterpriseFeaturesBuilder.withCobrandingLogo(cobrandLogoLight, cobrandLogoDark);
hasSetEnterpriseFeatures = true;
}

OnfidoConfig.Builder onfidoConfigBuilder = OnfidoConfig.builder(currentActivity)
.withSDKToken(sdkToken)
.withCustomFlow(flowStepsWithOptions);
final String workflowRunId = getWorkflowRunIdFromConfig(config);

if (hasSetEnterpriseFeatures) {
onfidoConfigBuilder.withEnterpriseFeatures(enterpriseFeaturesBuilder.build());
if (!workflowRunId.isEmpty()) {
workflowSDKConfiguration(currentActivity, workflowRunId, sdkToken);
} else {
defaultSDKConfiguration(config, currentActivity, sdkToken);
}

client.startActivityForResult(currentActivity, 1, onfidoConfigBuilder.build());
}
catch (final EnterpriseFeaturesInvalidLogoCobrandingException e) {
} catch (final EnterpriseFeaturesInvalidLogoCobrandingException e) {
currentPromise.reject("error", new EnterpriseFeaturesInvalidLogoCobrandingException());
currentPromise = null;
return;
}
catch (final EnterpriseFeatureNotEnabledException e) {
} catch (final EnterpriseFeatureNotEnabledException e) {
currentPromise.reject("error", new EnterpriseFeatureNotEnabledException("logoCobrand"));
currentPromise = null;
return;
}
catch (final Exception e) {
} catch (final Exception e) {
currentPromise.reject("error", new Exception(e.getMessage(), e));
currentPromise = null;
return;
}

} catch (final Exception e) {
e.printStackTrace();
// Wrap all unexpected exceptions.
currentPromise.reject("error", new Exception("Unexpected error starting Onfido page", e));
currentPromise = null;
return;
}
}

private void workflowSDKConfiguration(Activity currentActivity, String workflowRunId, String sdkToken) {
OnfidoWorkflow.create(currentActivity)
.startActivityForResult(currentActivity,
1,
new WorkflowConfig.Builder(sdkToken, workflowRunId).build());
}

private void defaultSDKConfiguration(final ReadableMap config, Activity currentActivity, String sdkToken) throws Exception {
final FlowStep[] flowStepsWithOptions = getFlowStepsFromConfig(config);
/* Native SDK seems to have a bug that if an empty EnterpriseFeatures is passed to it,
the logo will still be hidden, even if explicitly set to false */
EnterpriseFeatures.Builder enterpriseFeaturesBuilder = EnterpriseFeatures.builder();
boolean hasSetEnterpriseFeatures = false;

if (getBooleanFromConfig(config, "hideLogo")) {
enterpriseFeaturesBuilder.withHideOnfidoLogo(true);
hasSetEnterpriseFeatures = true;
} else if (getBooleanFromConfig(config, "logoCobrand")) {
int cobrandLogoLight = currentActivity.getApplicationContext().getResources().getIdentifier(
"cobrand_logo_light",
"drawable",
currentActivity.getApplicationContext().getPackageName()
);
int cobrandLogoDark = currentActivity.getApplicationContext().getResources().getIdentifier(
"cobrand_logo_dark",
"drawable",
currentActivity.getApplicationContext().getPackageName()
);
if (cobrandLogoLight == 0 || cobrandLogoDark == 0) {
currentPromise.reject("error", new Exception("Cobrand logos were not found"));
currentPromise = null;
return;
}
enterpriseFeaturesBuilder.withCobrandingLogo(cobrandLogoLight, cobrandLogoDark);
hasSetEnterpriseFeatures = true;
}

OnfidoConfig.Builder onfidoConfigBuilder = OnfidoConfig.builder(currentActivity)
.withSDKToken(sdkToken)
.withCustomFlow(flowStepsWithOptions);

if (hasSetEnterpriseFeatures) {
onfidoConfigBuilder.withEnterpriseFeatures(enterpriseFeaturesBuilder.build());
}

client.startActivityForResult(currentActivity, 1, onfidoConfigBuilder.build());
}

public static String getSdkTokenFromConfig(final ReadableMap config) {
final String sdkToken = config.getString("sdkToken");
return sdkToken;
return config.getString("sdkToken");
}

public static String getWorkflowRunIdFromConfig(final ReadableMap config) {
final String key = "workflowRunId";
return config.hasKey(key) ? config.getString(key) : "";
}

public static FlowStep[] getFlowStepsFromConfig(final ReadableMap config) throws Exception {
Expand Down Expand Up @@ -196,10 +211,6 @@ public static FlowStep[] getFlowStepsFromConfig(final ReadableMap config) throws
flowStepList.add(FlowStep.WELCOME);
}

if (userConsentIsIncluded) {
flowStepList.add(FlowStep.USER_CONSENT);
}

if (captureDocumentBoolean != null && captureDocumentBoolean) {
flowStepList.add(FlowStep.CAPTURE_DOCUMENT);
} else if (captureDocument != null) {
Expand All @@ -219,7 +230,7 @@ public static FlowStep[] getFlowStepsFromConfig(final ReadableMap config) throws
String countryCodeString = captureDocument.getString("alpha2CountryCode");
CountryCode countryCodeEnum = findCountryCodeByAlpha2(countryCodeString);

if (countryCodeEnum ==null) {
if (countryCodeEnum == null) {
System.err.println("Unexpected countryCode value: [" + countryCodeString + "]");
throw new Exception("Unexpected countryCode value.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Document {
public Identifiable front;
public Identifiable back;
}
public class Face extends Identifiable {
public class Face extends Response.Identifiable {
public Face(String id, String variant) {
super(id);
this.variant = variant;
Expand Down Expand Up @@ -47,4 +47,4 @@ private void initFace(String faceId, String faceVariant) {
face = new Face(faceId, faceVariant);
}
}
}
}
Loading

0 comments on commit 9e071e6

Please sign in to comment.