Skip to content

Commit ea050a2

Browse files
Merge pull request #2 from TransmitSecurity/feature/MOB-862
MOB-862 Updated API Signature, added new functionality
2 parents 04b8174 + c0aba79 commit ea050a2

File tree

34 files changed

+309
-101
lines changed

34 files changed

+309
-101
lines changed

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ private onAppReady = async (): Promise<void> => {
9696
```js
9797
onStartRegistrationProcess = async (): Promise<void> => {
9898
try {
99-
const response = await TSAuthenticationSDKModule.register(username, displayName);
99+
const response = await TSAuthenticationSDKModule.registerWebAuthn(username, displayName);
100100
// use the response.result string to complete a successful registration in your backend.
101101
} catch (error) {
102-
console.error(`Error authentication the user: ${error}`);
102+
console.error(`Error during registration process: ${error}`);
103103
}
104104
}
105105
```
@@ -108,10 +108,10 @@ onStartRegistrationProcess = async (): Promise<void> => {
108108
```js
109109
onStartAuthenticationProcess = async (): Promise<void> => {
110110
try {
111-
const response = await TSAuthenticationSDKModule.authenticate(username);
111+
const response = await TSAuthenticationSDKModule.authenticateWebAuthn(username);
112112
// use the response.result string to complete a successful authentication in your backend.
113113
} catch (error) {
114-
console.error(`Error authentication the user: ${error}`);
114+
console.error(`Error authenticating the user: ${error}`);
115115
}
116116
}
117117
```
@@ -120,10 +120,32 @@ onStartAuthenticationProcess = async (): Promise<void> => {
120120
```js
121121
onStartSignTransactionProcess = async (): Promise<void> => {
122122
try {
123-
const response = await TSAuthenticationSDKModule.signTransaction(username);
123+
const response = await TSAuthenticationSDKModule.signWebauthnTransaction(username);
124124
// use the response.result string to complete a signing a transaction in your backend.
125125
} catch (error) {
126-
console.error(`Error authentication the user: ${error}`);
126+
console.error(`Error signing a transaction: ${error}`);
127+
}
128+
}
129+
```
130+
131+
#### Get Device Info
132+
```js
133+
onGetDeviceInfo = async (): Promise<void> => {
134+
try {
135+
const response = await TSAuthenticationSDKModule.getDeviceInfo();
136+
} catch (error) {
137+
console.error(`Error getting device info: ${error}`);
138+
}
139+
}
140+
```
141+
142+
#### Check if the device supports webAuthn
143+
```js
144+
onIsWebAuthenSupported = async (): Promise<void> => {
145+
try {
146+
const isSupported = await TSAuthenticationSDKModule.isWebAuthnSupported();
147+
} catch (error) {
148+
console.error(`Error checking if the device supports webAuthn: ${error}`);
127149
}
128150
}
129151
```
Lines changed: 61 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package com.tsauthentication;
22

3-
import static androidx.work.ListenableWorker.Result.success;
4-
53
import androidx.annotation.NonNull;
6-
74
import com.facebook.react.bridge.Promise;
85
import com.facebook.react.bridge.ReactApplicationContext;
96
import com.facebook.react.bridge.ReactContextBaseJavaModule;
107
import com.facebook.react.bridge.ReactMethod;
118
import com.facebook.react.bridge.WritableMap;
129
import com.facebook.react.bridge.WritableNativeMap;
1310
import com.facebook.react.module.annotations.ReactModule;
14-
import com.transmit.authentication.AuthenticationError;
11+
import com.transmit.authentication.TSDeviceInfoError;
12+
import com.transmit.authentication.TSWebAuthnAuthenticationError;
1513
import com.transmit.authentication.AuthenticationResult;
1614
import com.transmit.authentication.RegistrationResult;
1715
import com.transmit.authentication.TSAuthCallback;
1816
import com.transmit.authentication.TSAuthentication;
17+
import com.transmit.authentication.TSWebAuthnRegistrationError;
18+
import com.transmit.authentication.network.completereg.DeviceInfo;
1919

2020
import java.util.HashMap;
2121

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

4141
if(reactContext.getCurrentActivity() != null) {
42-
TSAuthentication.init(
42+
TSAuthentication.initialize(
4343
reactContext,
44-
baseUrl,
4544
clientId
4645
);
4746
promise.resolve(true);
@@ -51,44 +50,38 @@ public String getName() {
5150
// Registration
5251

5352
@ReactMethod
54-
@NonNull public void register(
53+
@NonNull public void registerWebAuthn(
5554
String username,
5655
String displayName,
5756
Promise promise) {
57+
5858
if(reactContext.getCurrentActivity() != null) {
59-
TSAuthentication.isPlatformAuthenticatorSupported(
60-
reactContext.getCurrentActivity(),
61-
new TSAuthCallback<Boolean>() {
62-
@Override
63-
public void success(Boolean aBoolean) {
64-
continueRegistration(username, displayName, promise);
65-
}
59+
Boolean isSupported = TSAuthentication.isWebAuthnSupported();
60+
if (!isSupported) {
61+
promise.reject(new Error("Unsupported platform"));
62+
return;
63+
}
6664

67-
@Override
68-
public void error(@NonNull AuthenticationError authenticationError) {
69-
promise.reject(new Error("Unsupported platform"));
70-
}
71-
}
72-
);
65+
continueRegistration(username, displayName, promise);
7366
}
7467
}
68+
7569
private void continueRegistration(String username, String displayName, Promise promise) {
7670
if(reactContext.getCurrentActivity() != null) {
77-
TSAuthentication.register(
71+
TSAuthentication.registerWebAuthn(
7872
reactContext.getCurrentActivity(),
7973
username,
8074
displayName,
81-
new TSAuthCallback<RegistrationResult>() {
75+
new TSAuthCallback<RegistrationResult, TSWebAuthnRegistrationError>() {
8276
@Override
8377
public void success(RegistrationResult registrationResult) {
8478
WritableMap map = new WritableNativeMap();
85-
map.putString(registrationResult.result(), NAME);
79+
map.putString("result",registrationResult.result());
8680
promise.resolve(map);
8781
}
88-
8982
@Override
90-
public void error(@NonNull AuthenticationError authenticationError) {
91-
promise.reject(NAME, authenticationError.toString());
83+
public void error(TSWebAuthnRegistrationError tsWebAuthnRegistrationError) {
84+
promise.reject("result", tsWebAuthnRegistrationError.getEM());
9285
}
9386
}
9487
);
@@ -97,49 +90,76 @@ public void error(@NonNull AuthenticationError authenticationError) {
9790

9891
// Authentication
9992
@ReactMethod
100-
@NonNull public void authenticate(String username, Promise promise) {
93+
@NonNull public void authenticateWebAuthn(String username, Promise promise) {
10194
if(reactContext.getCurrentActivity() != null) {
102-
TSAuthentication.authenticate(
95+
TSAuthentication.authenticateWebAuthn(
10396
reactContext.getCurrentActivity(),
10497
username,
105-
new TSAuthCallback<AuthenticationResult>() {
98+
new TSAuthCallback<AuthenticationResult, TSWebAuthnAuthenticationError>() {
10699
@Override
107100
public void success(AuthenticationResult authenticationResult) {
108101
WritableMap map = new WritableNativeMap();
109-
map.putString(authenticationResult.result(), NAME);
102+
map.putString("result", authenticationResult.result());
110103
promise.resolve(map);
111104
}
112-
113105
@Override
114-
public void error(@NonNull AuthenticationError authenticationError) {
115-
promise.reject(NAME, authenticationError.toString());
106+
public void error(TSWebAuthnAuthenticationError tsWebAuthnAuthenticationError) {
107+
promise.reject("result", tsWebAuthnAuthenticationError.toString());
116108
}
117-
}
118-
);
109+
});
119110
}
120111
}
121112

113+
// Transaction
122114
@ReactMethod
123-
@NonNull public void signTransaction(String username, Promise promise) {
115+
@NonNull public void signTransactionWebAuthn(String username, Promise promise) {
124116
if(reactContext.getCurrentActivity() != null) {
125-
TSAuthentication.signTransaction(
117+
TSAuthentication.signTransactionWebAuthn(
126118
reactContext.getCurrentActivity(),
127119
username,
128-
new TSAuthCallback<AuthenticationResult>() {
120+
new TSAuthCallback<AuthenticationResult, TSWebAuthnAuthenticationError>() {
129121
@Override
130122
public void success(AuthenticationResult authenticationResult) {
131123
WritableMap map = new WritableNativeMap();
132-
map.putString(authenticationResult.result(), NAME);
124+
map.putString("result", authenticationResult.result());
133125
promise.resolve(map);
134126
}
135127

136128
@Override
137-
public void error(@NonNull AuthenticationError authenticationError) {
138-
promise.reject(NAME, authenticationError.toString());
129+
public void error(TSWebAuthnAuthenticationError tsWebAuthnAuthenticationError) {
130+
promise.reject("result", tsWebAuthnAuthenticationError.toString());
139131
}
140132
}
141133
);
142134
}
143135
}
136+
137+
@ReactMethod
138+
@NonNull public void getDeviceInfo(Promise promise) {
139+
if(reactContext.getCurrentActivity() != null) {
140+
TSAuthentication.getDeviceInfo(
141+
reactContext.getCurrentActivity(),
142+
new TSAuthCallback<DeviceInfo, TSDeviceInfoError>() {
143+
@Override
144+
public void success(DeviceInfo deviceInfo) {
145+
WritableMap map = new WritableNativeMap();
146+
map.putString("publicKeyId", deviceInfo.getPublicKeyId());
147+
map.putString("publicKey", deviceInfo.getPublicKey());
148+
promise.resolve(map);
149+
}
150+
151+
@Override
152+
public void error(TSDeviceInfoError tsDeviceInfoError) {
153+
promise.reject("result", tsDeviceInfoError.toString());
154+
}
155+
}
156+
);
157+
}
158+
}
159+
160+
@ReactMethod
161+
@NonNull public void isWebAuthnSupported(Promise promise) {
162+
promise.resolve(TSAuthentication.isWebAuthnSupported());
163+
}
144164
}
145165

example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ android {
7575

7676
namespace "com.tsauthenticationexample"
7777
defaultConfig {
78-
applicationId "com.transmitsecurity.authsdk_rn_example"
78+
applicationId "com.tsauthenticationexample"
7979
minSdkVersion rootProject.ext.minSdkVersion
8080
targetSdkVersion rootProject.ext.targetSdkVersion
8181
versionCode 1

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<action android:name="android.intent.action.MAIN" />
2121
<category android:name="android.intent.category.LAUNCHER" />
2222
</intent-filter>
23+
<meta-data android:name="asset_statements" android:resource="@string/asset_statements" />
2324
</activity>
2425
</application>
2526
</manifest>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
<resources>
22
<string name="app_name">TsAuthenticationExample</string>
3+
<string name="asset_statements" translatable="false">
4+
[{
5+
\"include\": \"https://mobile.idsec-dev.com/.well-known/assetlinks.json\"
6+
}]
7+
</string>
38
</resources>

example/ios/Podfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,10 @@ PODS:
375375
- React-jsinspector (0.72.7)
376376
- React-logger (0.72.7):
377377
- glog
378-
- react-native-ts-authentication (0.1.0):
378+
- react-native-ts-authentication (0.1.2):
379379
- RCT-Folly (= 2021.07.22.00)
380380
- React-Core
381-
- TSAuthentication (~> 1.0.2)
381+
- TSAuthentication (~> 1.0.5)
382382
- React-NativeModulesApple (0.72.7):
383383
- hermes-engine
384384
- React-callinvoker
@@ -492,9 +492,9 @@ PODS:
492492
- RNCAsyncStorage (1.21.0):
493493
- React-Core
494494
- SocketRocket (0.6.1)
495-
- TSAuthentication (1.0.2):
496-
- TSCoreSDK (~> 1.0.17)
497-
- TSCoreSDK (1.0.17)
495+
- TSAuthentication (1.0.5):
496+
- TSCoreSDK (~> 1.0.20)
497+
- TSCoreSDK (1.0.21)
498498
- Yoga (1.14.0)
499499
- YogaKit (1.18.1):
500500
- Yoga (~> 1.14)
@@ -704,7 +704,7 @@ SPEC CHECKSUMS:
704704
React-jsiexecutor: c49502e5d02112247ee4526bc3ccfc891ae3eb9b
705705
React-jsinspector: 8baadae51f01d867c3921213a25ab78ab4fbcd91
706706
React-logger: 8edc785c47c8686c7962199a307015e2ce9a0e4f
707-
react-native-ts-authentication: fa1fdbf7f401515476cce2fe7aeb2d49e6affbe5
707+
react-native-ts-authentication: 27e08992c0ef968c01c2655b43984bcdc5c1daf7
708708
React-NativeModulesApple: b6868ee904013a7923128892ee4a032498a1024a
709709
React-perflogger: 31ea61077185eb1428baf60c0db6e2886f141a5a
710710
React-RCTActionSheet: 392090a3abc8992eb269ef0eaa561750588fc39d
@@ -724,8 +724,8 @@ SPEC CHECKSUMS:
724724
ReactCommon: 5f704096ccf7733b390f59043b6fa9cc180ee4f6
725725
RNCAsyncStorage: 618d03a5f52fbccb3d7010076bc54712844c18ef
726726
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
727-
TSAuthentication: a94a6f2bacf0bc518bf8974e9795b1bd28647d59
728-
TSCoreSDK: c602d0392aef99325911a9c1431903976d64e23a
727+
TSAuthentication: 401287772614dd4fc2d9e7120d6857fee0faa344
728+
TSCoreSDK: e30a537480334e5b9971f955ec3d3cdaa334f0a4
729729
Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5
730730
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
731731

example/ios/TsAuthenticationExample.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@
492492
DEVELOPMENT_TEAM = C88675TMZW;
493493
ENABLE_BITCODE = NO;
494494
INFOPLIST_FILE = TsAuthenticationExample/Info.plist;
495+
INFOPLIST_KEY_CFBundleDisplayName = "TS Authentication";
495496
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
496497
LD_RUNPATH_SEARCH_PATHS = (
497498
"$(inherited)",
@@ -521,6 +522,7 @@
521522
CURRENT_PROJECT_VERSION = 1;
522523
DEVELOPMENT_TEAM = C88675TMZW;
523524
INFOPLIST_FILE = TsAuthenticationExample/Info.plist;
525+
INFOPLIST_KEY_CFBundleDisplayName = "TS Authentication";
524526
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
525527
LD_RUNPATH_SEARCH_PATHS = (
526528
"$(inherited)",
2.89 KB
Loading
56.3 KB
Loading
3.15 KB
Loading

0 commit comments

Comments
 (0)