Skip to content

Commit

Permalink
Merge pull request #2 from TransmitSecurity/feature/MOB-862
Browse files Browse the repository at this point in the history
MOB-862 Updated API Signature, added new functionality
  • Loading branch information
shachartransmit authored Apr 1, 2024
2 parents 04b8174 + c0aba79 commit ea050a2
Show file tree
Hide file tree
Showing 34 changed files with 309 additions and 101 deletions.
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ private onAppReady = async (): Promise<void> => {
```js
onStartRegistrationProcess = async (): Promise<void> => {
try {
const response = await TSAuthenticationSDKModule.register(username, displayName);
const response = await TSAuthenticationSDKModule.registerWebAuthn(username, displayName);
// use the response.result string to complete a successful registration in your backend.
} catch (error) {
console.error(`Error authentication the user: ${error}`);
console.error(`Error during registration process: ${error}`);
}
}
```
Expand All @@ -108,10 +108,10 @@ onStartRegistrationProcess = async (): Promise<void> => {
```js
onStartAuthenticationProcess = async (): Promise<void> => {
try {
const response = await TSAuthenticationSDKModule.authenticate(username);
const response = await TSAuthenticationSDKModule.authenticateWebAuthn(username);
// use the response.result string to complete a successful authentication in your backend.
} catch (error) {
console.error(`Error authentication the user: ${error}`);
console.error(`Error authenticating the user: ${error}`);
}
}
```
Expand All @@ -120,10 +120,32 @@ onStartAuthenticationProcess = async (): Promise<void> => {
```js
onStartSignTransactionProcess = async (): Promise<void> => {
try {
const response = await TSAuthenticationSDKModule.signTransaction(username);
const response = await TSAuthenticationSDKModule.signWebauthnTransaction(username);
// use the response.result string to complete a signing a transaction in your backend.
} catch (error) {
console.error(`Error authentication the user: ${error}`);
console.error(`Error signing a transaction: ${error}`);
}
}
```

#### Get Device Info
```js
onGetDeviceInfo = async (): Promise<void> => {
try {
const response = await TSAuthenticationSDKModule.getDeviceInfo();
} catch (error) {
console.error(`Error getting device info: ${error}`);
}
}
```

#### Check if the device supports webAuthn
```js
onIsWebAuthenSupported = async (): Promise<void> => {
try {
const isSupported = await TSAuthenticationSDKModule.isWebAuthnSupported();
} catch (error) {
console.error(`Error checking if the device supports webAuthn: ${error}`);
}
}
```
Expand Down
102 changes: 61 additions & 41 deletions android/src/main/java/com/tsauthentication/TsAuthenticationModule.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.tsauthentication;

import static androidx.work.ListenableWorker.Result.success;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.module.annotations.ReactModule;
import com.transmit.authentication.AuthenticationError;
import com.transmit.authentication.TSDeviceInfoError;
import com.transmit.authentication.TSWebAuthnAuthenticationError;
import com.transmit.authentication.AuthenticationResult;
import com.transmit.authentication.RegistrationResult;
import com.transmit.authentication.TSAuthCallback;
import com.transmit.authentication.TSAuthentication;
import com.transmit.authentication.TSWebAuthnRegistrationError;
import com.transmit.authentication.network.completereg.DeviceInfo;

import java.util.HashMap;

Expand All @@ -39,9 +39,8 @@ public String getName() {
@NonNull public void initialize(String clientId, String domain, String baseUrl, Promise promise) {

if(reactContext.getCurrentActivity() != null) {
TSAuthentication.init(
TSAuthentication.initialize(
reactContext,
baseUrl,
clientId
);
promise.resolve(true);
Expand All @@ -51,44 +50,38 @@ public String getName() {
// Registration

@ReactMethod
@NonNull public void register(
@NonNull public void registerWebAuthn(
String username,
String displayName,
Promise promise) {

if(reactContext.getCurrentActivity() != null) {
TSAuthentication.isPlatformAuthenticatorSupported(
reactContext.getCurrentActivity(),
new TSAuthCallback<Boolean>() {
@Override
public void success(Boolean aBoolean) {
continueRegistration(username, displayName, promise);
}
Boolean isSupported = TSAuthentication.isWebAuthnSupported();
if (!isSupported) {
promise.reject(new Error("Unsupported platform"));
return;
}

@Override
public void error(@NonNull AuthenticationError authenticationError) {
promise.reject(new Error("Unsupported platform"));
}
}
);
continueRegistration(username, displayName, promise);
}
}

private void continueRegistration(String username, String displayName, Promise promise) {
if(reactContext.getCurrentActivity() != null) {
TSAuthentication.register(
TSAuthentication.registerWebAuthn(
reactContext.getCurrentActivity(),
username,
displayName,
new TSAuthCallback<RegistrationResult>() {
new TSAuthCallback<RegistrationResult, TSWebAuthnRegistrationError>() {
@Override
public void success(RegistrationResult registrationResult) {
WritableMap map = new WritableNativeMap();
map.putString(registrationResult.result(), NAME);
map.putString("result",registrationResult.result());
promise.resolve(map);
}

@Override
public void error(@NonNull AuthenticationError authenticationError) {
promise.reject(NAME, authenticationError.toString());
public void error(TSWebAuthnRegistrationError tsWebAuthnRegistrationError) {
promise.reject("result", tsWebAuthnRegistrationError.getEM());
}
}
);
Expand All @@ -97,49 +90,76 @@ public void error(@NonNull AuthenticationError authenticationError) {

// Authentication
@ReactMethod
@NonNull public void authenticate(String username, Promise promise) {
@NonNull public void authenticateWebAuthn(String username, Promise promise) {
if(reactContext.getCurrentActivity() != null) {
TSAuthentication.authenticate(
TSAuthentication.authenticateWebAuthn(
reactContext.getCurrentActivity(),
username,
new TSAuthCallback<AuthenticationResult>() {
new TSAuthCallback<AuthenticationResult, TSWebAuthnAuthenticationError>() {
@Override
public void success(AuthenticationResult authenticationResult) {
WritableMap map = new WritableNativeMap();
map.putString(authenticationResult.result(), NAME);
map.putString("result", authenticationResult.result());
promise.resolve(map);
}

@Override
public void error(@NonNull AuthenticationError authenticationError) {
promise.reject(NAME, authenticationError.toString());
public void error(TSWebAuthnAuthenticationError tsWebAuthnAuthenticationError) {
promise.reject("result", tsWebAuthnAuthenticationError.toString());
}
}
);
});
}
}

// Transaction
@ReactMethod
@NonNull public void signTransaction(String username, Promise promise) {
@NonNull public void signTransactionWebAuthn(String username, Promise promise) {
if(reactContext.getCurrentActivity() != null) {
TSAuthentication.signTransaction(
TSAuthentication.signTransactionWebAuthn(
reactContext.getCurrentActivity(),
username,
new TSAuthCallback<AuthenticationResult>() {
new TSAuthCallback<AuthenticationResult, TSWebAuthnAuthenticationError>() {
@Override
public void success(AuthenticationResult authenticationResult) {
WritableMap map = new WritableNativeMap();
map.putString(authenticationResult.result(), NAME);
map.putString("result", authenticationResult.result());
promise.resolve(map);
}

@Override
public void error(@NonNull AuthenticationError authenticationError) {
promise.reject(NAME, authenticationError.toString());
public void error(TSWebAuthnAuthenticationError tsWebAuthnAuthenticationError) {
promise.reject("result", tsWebAuthnAuthenticationError.toString());
}
}
);
}
}

@ReactMethod
@NonNull public void getDeviceInfo(Promise promise) {
if(reactContext.getCurrentActivity() != null) {
TSAuthentication.getDeviceInfo(
reactContext.getCurrentActivity(),
new TSAuthCallback<DeviceInfo, TSDeviceInfoError>() {
@Override
public void success(DeviceInfo deviceInfo) {
WritableMap map = new WritableNativeMap();
map.putString("publicKeyId", deviceInfo.getPublicKeyId());
map.putString("publicKey", deviceInfo.getPublicKey());
promise.resolve(map);
}

@Override
public void error(TSDeviceInfoError tsDeviceInfoError) {
promise.reject("result", tsDeviceInfoError.toString());
}
}
);
}
}

@ReactMethod
@NonNull public void isWebAuthnSupported(Promise promise) {
promise.resolve(TSAuthentication.isWebAuthnSupported());
}
}

2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ android {

namespace "com.tsauthenticationexample"
defaultConfig {
applicationId "com.transmitsecurity.authsdk_rn_example"
applicationId "com.tsauthenticationexample"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
Expand Down
1 change: 1 addition & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="asset_statements" android:resource="@string/asset_statements" />
</activity>
</application>
</manifest>
5 changes: 5 additions & 0 deletions example/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<resources>
<string name="app_name">TsAuthenticationExample</string>
<string name="asset_statements" translatable="false">
[{
\"include\": \"https://mobile.idsec-dev.com/.well-known/assetlinks.json\"
}]
</string>
</resources>
16 changes: 8 additions & 8 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ PODS:
- React-jsinspector (0.72.7)
- React-logger (0.72.7):
- glog
- react-native-ts-authentication (0.1.0):
- react-native-ts-authentication (0.1.2):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- TSAuthentication (~> 1.0.2)
- TSAuthentication (~> 1.0.5)
- React-NativeModulesApple (0.72.7):
- hermes-engine
- React-callinvoker
Expand Down Expand Up @@ -492,9 +492,9 @@ PODS:
- RNCAsyncStorage (1.21.0):
- React-Core
- SocketRocket (0.6.1)
- TSAuthentication (1.0.2):
- TSCoreSDK (~> 1.0.17)
- TSCoreSDK (1.0.17)
- TSAuthentication (1.0.5):
- TSCoreSDK (~> 1.0.20)
- TSCoreSDK (1.0.21)
- Yoga (1.14.0)
- YogaKit (1.18.1):
- Yoga (~> 1.14)
Expand Down Expand Up @@ -704,7 +704,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: c49502e5d02112247ee4526bc3ccfc891ae3eb9b
React-jsinspector: 8baadae51f01d867c3921213a25ab78ab4fbcd91
React-logger: 8edc785c47c8686c7962199a307015e2ce9a0e4f
react-native-ts-authentication: fa1fdbf7f401515476cce2fe7aeb2d49e6affbe5
react-native-ts-authentication: 27e08992c0ef968c01c2655b43984bcdc5c1daf7
React-NativeModulesApple: b6868ee904013a7923128892ee4a032498a1024a
React-perflogger: 31ea61077185eb1428baf60c0db6e2886f141a5a
React-RCTActionSheet: 392090a3abc8992eb269ef0eaa561750588fc39d
Expand All @@ -724,8 +724,8 @@ SPEC CHECKSUMS:
ReactCommon: 5f704096ccf7733b390f59043b6fa9cc180ee4f6
RNCAsyncStorage: 618d03a5f52fbccb3d7010076bc54712844c18ef
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
TSAuthentication: a94a6f2bacf0bc518bf8974e9795b1bd28647d59
TSCoreSDK: c602d0392aef99325911a9c1431903976d64e23a
TSAuthentication: 401287772614dd4fc2d9e7120d6857fee0faa344
TSCoreSDK: e30a537480334e5b9971f955ec3d3cdaa334f0a4
Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Expand Down
2 changes: 2 additions & 0 deletions example/ios/TsAuthenticationExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@
DEVELOPMENT_TEAM = C88675TMZW;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = TsAuthenticationExample/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "TS Authentication";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -521,6 +522,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = C88675TMZW;
INFOPLIST_FILE = TsAuthenticationExample/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "TS Authentication";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ea050a2

Please sign in to comment.