react-native-authsignal 1.0.13 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. package/android/build.gradle +27 -87
  2. package/android/gradle/wrapper/gradle-wrapper.properties +3 -2
  3. package/android/gradle.properties +4 -3
  4. package/android/src/main/java/com/authsignal/react/AuthenticationActivity.kt +69 -0
  5. package/android/src/main/java/com/authsignal/react/AuthsignalEmailModule.kt +113 -0
  6. package/android/src/main/java/com/authsignal/react/AuthsignalModule.kt +115 -0
  7. package/android/src/main/java/com/authsignal/react/AuthsignalPackage.kt +23 -0
  8. package/android/src/main/java/com/authsignal/react/AuthsignalPasskeyModule.kt +103 -0
  9. package/android/src/main/java/com/authsignal/react/AuthsignalPushModule.kt +152 -0
  10. package/android/src/main/java/com/authsignal/react/AuthsignalSMSModule.kt +117 -0
  11. package/android/src/main/java/com/authsignal/react/AuthsignalTOTPModule.kt +95 -0
  12. package/android/src/main/java/com/authsignal/react/RedirectActivity.kt +17 -0
  13. package/package.json +1 -1
  14. package/android/src/main/java/com/authsignal/react/AuthenticationActivity.java +0 -73
  15. package/android/src/main/java/com/authsignal/react/AuthsignalEmailModule.java +0 -139
  16. package/android/src/main/java/com/authsignal/react/AuthsignalModule.java +0 -127
  17. package/android/src/main/java/com/authsignal/react/AuthsignalPackage.java +0 -29
  18. package/android/src/main/java/com/authsignal/react/AuthsignalPasskeyModule.java +0 -133
  19. package/android/src/main/java/com/authsignal/react/AuthsignalPushModule.java +0 -188
  20. package/android/src/main/java/com/authsignal/react/AuthsignalSMSModule.java +0 -139
  21. package/android/src/main/java/com/authsignal/react/AuthsignalTOTPModule.java +0 -116
  22. package/android/src/main/java/com/authsignal/react/RedirectActivity.java +0 -18
@@ -1,127 +0,0 @@
1
- package com.authsignal.react;
2
-
3
- import android.app.Activity;
4
- import android.content.Intent;
5
- import android.content.ActivityNotFoundException;
6
- import android.net.Uri;
7
- import androidx.annotation.NonNull;
8
-
9
- import com.authsignal.TokenCache;
10
- import com.facebook.react.bridge.ActivityEventListener;
11
- import com.facebook.react.bridge.Arguments;
12
- import com.facebook.react.bridge.Callback;
13
- import com.facebook.react.bridge.Promise;
14
- import com.facebook.react.bridge.ReactApplicationContext;
15
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
16
- import com.facebook.react.bridge.ReactMethod;
17
- import com.facebook.react.bridge.WritableMap;
18
-
19
- import java.net.URLDecoder;
20
- import java.util.HashMap;
21
- import java.util.Map;
22
-
23
- import static android.app.Activity.RESULT_OK;
24
-
25
- public class AuthsignalModule extends ReactContextBaseJavaModule implements ActivityEventListener {
26
- private final ReactApplicationContext reactContext;
27
- private Callback callback;
28
-
29
- public AuthsignalModule(ReactApplicationContext reactContext) {
30
- super(reactContext);
31
- this.reactContext = reactContext;
32
- this.reactContext.addActivityEventListener(this);
33
- }
34
-
35
- @Override
36
- public Map<String, Object> getConstants() {
37
- final Map<String, Object> constants = new HashMap<>();
38
- constants.put("bundleIdentifier", reactContext.getApplicationInfo().packageName);
39
- return constants;
40
- }
41
-
42
- @NonNull
43
- @Override
44
- public String getName() {
45
- return "AuthsignalModule";
46
- }
47
-
48
- @ReactMethod
49
- public void setToken(String token, Promise promise) {
50
- TokenCache.Companion.getShared().setToken(token);
51
-
52
- promise.resolve("token_set");
53
- }
54
-
55
- @ReactMethod
56
- public void launch(String url, Callback callback) {
57
- final Activity activity = getCurrentActivity();
58
- final Uri parsedUrl = Uri.parse(url);
59
- this.callback = callback;
60
-
61
- try {
62
- if (activity != null) {
63
- AuthenticationActivity.authenticateUsingBrowser(activity, parsedUrl);
64
- } else {
65
- final WritableMap error = Arguments.createMap();
66
- error.putString("error", "activity_not_available");
67
- error.putString("error_description", "Android Activity is null.");
68
- callback.invoke(error);
69
- }
70
- } catch (ActivityNotFoundException e){
71
- final WritableMap error = Arguments.createMap();
72
- error.putString("error", "browser_not_available");
73
- error.putString("error_description", "No browser app is installed");
74
- callback.invoke(error);
75
- }
76
- }
77
-
78
- @Override
79
- public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
80
- Callback cb = AuthsignalModule.this.callback;
81
-
82
- if (cb == null) {
83
- return;
84
- }
85
-
86
- boolean hasResult = resultCode == RESULT_OK &&
87
- requestCode == AuthenticationActivity.AUTHENTICATION_REQUEST &&
88
- data.getData() != null;
89
-
90
- if (hasResult) {
91
- try {
92
- String redirectUrl = data.getData().toString();
93
- String query = redirectUrl.split("[?]")[1];
94
- String[] pairs = query.split("&");
95
- String token = null;
96
- for (String pair : pairs) {
97
- int index = pair.indexOf("=");
98
- String name = URLDecoder.decode(pair.substring(0, index), "UTF-8");
99
- String value = URLDecoder.decode(pair.substring(index + 1), "UTF-8");
100
- if (name.equals("token")) {
101
- token = value;
102
-
103
- TokenCache.Companion.getShared().setToken(value);
104
- }
105
- }
106
- cb.invoke(null, token);
107
- } catch (Exception ex) {
108
- final WritableMap error = Arguments.createMap();
109
- error.putString("error", "malformed_url");
110
- error.putString("error_description", "Malformed redirect url");
111
- cb.invoke(error);
112
- }
113
-
114
- } else {
115
- final WritableMap error = Arguments.createMap();
116
- error.putString("error", "user_cancelled");
117
- error.putString("error_description", "User cancelled");
118
- cb.invoke(error);
119
- }
120
-
121
- AuthsignalModule.this.callback = null;
122
- }
123
-
124
- @Override
125
- public void onNewIntent(Intent intent) {
126
- }
127
- }
@@ -1,29 +0,0 @@
1
- package com.authsignal.react;
2
-
3
- import java.util.Arrays;
4
- import java.util.Collections;
5
- import java.util.List;
6
-
7
- import com.facebook.react.ReactPackage;
8
- import com.facebook.react.bridge.NativeModule;
9
- import com.facebook.react.bridge.ReactApplicationContext;
10
- import com.facebook.react.uimanager.ViewManager;
11
-
12
- public class AuthsignalPackage implements ReactPackage {
13
- @Override
14
- public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
15
- return Arrays.asList(
16
- new AuthsignalModule(reactContext),
17
- new AuthsignalEmailModule(reactContext),
18
- new AuthsignalPasskeyModule(reactContext),
19
- new AuthsignalPushModule(reactContext),
20
- new AuthsignalSMSModule(reactContext),
21
- new AuthsignalTOTPModule(reactContext)
22
- );
23
- }
24
-
25
- @Override
26
- public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
27
- return Collections.emptyList();
28
- }
29
- }
@@ -1,133 +0,0 @@
1
- package com.authsignal.react;
2
-
3
- import android.app.Activity;
4
- import android.util.Log;
5
-
6
- import androidx.annotation.NonNull;
7
-
8
- import com.authsignal.passkey.AuthsignalPasskey;
9
- import com.authsignal.passkey.models.*;
10
- import com.facebook.react.bridge.Arguments;
11
- import com.facebook.react.bridge.Promise;
12
- import com.facebook.react.bridge.ReactApplicationContext;
13
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
14
- import com.facebook.react.bridge.ReactMethod;
15
- import com.facebook.react.bridge.WritableMap;
16
-
17
- import java.util.HashMap;
18
- import java.util.Map;
19
-
20
- public class AuthsignalPasskeyModule extends ReactContextBaseJavaModule {
21
- private final ReactApplicationContext reactContext;
22
-
23
- private AuthsignalPasskey authsignalPasskey;
24
-
25
- private final String TAG = "AuthsignalPasskeyModule";
26
- private final String INIT_WARNING = "AuthsignalPasskeyModule is not initialized.";
27
-
28
- public AuthsignalPasskeyModule(ReactApplicationContext reactContext) {
29
- super(reactContext);
30
- this.reactContext = reactContext;
31
- }
32
-
33
- @Override
34
- public Map<String, Object> getConstants() {
35
- final Map<String, Object> constants = new HashMap<>();
36
- constants.put("bundleIdentifier", reactContext.getApplicationInfo().packageName);
37
- return constants;
38
- }
39
-
40
- @NonNull
41
- @Override
42
- public String getName() {
43
- return "AuthsignalPasskeyModule";
44
- }
45
-
46
- @ReactMethod
47
- public void initialize(String tenantID, String baseURL, Promise promise) {
48
- Activity currentActivity = reactContext.getCurrentActivity();
49
-
50
- if (currentActivity != null) {
51
- authsignalPasskey = new AuthsignalPasskey(
52
- tenantID,
53
- baseURL,
54
- reactContext,
55
- reactContext.getCurrentActivity()
56
- );
57
- }
58
-
59
- promise.resolve(null);
60
- }
61
-
62
- @ReactMethod
63
- public void signUp(String token, String username, String displayName, Promise promise) {
64
- if (authsignalPasskey != null) {
65
- authsignalPasskey
66
- .signUpAsync(token, username, displayName)
67
- .thenAcceptAsync(response -> {
68
- if (response.getError() != null) {
69
- String errorCode = response.getErrorType() != null ?
70
- response.getErrorType() :
71
- "sign_up_error";
72
-
73
- promise.reject(errorCode, response.getError());
74
- } else {
75
- SignUpResponse signUpResponse = response.getData();
76
- WritableMap map = Arguments.createMap();
77
- map.putString("token", signUpResponse.getToken());
78
- promise.resolve(map);
79
- }
80
- });
81
- } else {
82
- Log.w(TAG, INIT_WARNING);
83
-
84
- promise.resolve(null);
85
- }
86
- }
87
-
88
- @ReactMethod
89
- public void signIn(String action, String token, Promise promise) {
90
- if (authsignalPasskey != null) {
91
- authsignalPasskey
92
- .signInAsync(action, token)
93
- .thenAcceptAsync(response -> {
94
- if (response.getError() != null) {
95
- String errorCode = response.getErrorType() != null ?
96
- response.getErrorType() :
97
- "sign_in_error";
98
-
99
- promise.reject(errorCode, response.getError());
100
- } else {
101
- SignInResponse signInResponse = response.getData();
102
- WritableMap map = Arguments.createMap();
103
- map.putBoolean("isVerified", signInResponse.isVerified());
104
- map.putString("token", signInResponse.getToken());
105
- map.putString("userId", signInResponse.getUserId());
106
- map.putString("userAuthenticatorId", signInResponse.getUserAuthenticatorId());
107
- map.putString("username", signInResponse.getUsername());
108
- map.putString("displayName", signInResponse.getDisplayName());
109
- promise.resolve(map);
110
- }
111
- });
112
- } else {
113
- Log.w(TAG, INIT_WARNING);
114
-
115
- promise.resolve(null);
116
- }
117
- }
118
-
119
- @ReactMethod
120
- public void isAvailableOnDevice(Promise promise) {
121
- if (authsignalPasskey != null) {
122
- authsignalPasskey
123
- .isAvailableOnDeviceAsync()
124
- .thenAcceptAsync(response -> {
125
- promise.resolve(response.getData() != null ? response.getData() : false);
126
- });
127
- } else {
128
- Log.w(TAG, INIT_WARNING);
129
-
130
- promise.resolve(false);
131
- }
132
- }
133
- }
@@ -1,188 +0,0 @@
1
- package com.authsignal.react;
2
-
3
- import android.util.Log;
4
-
5
- import androidx.annotation.NonNull;
6
-
7
- import com.authsignal.push.AuthsignalPush;
8
- import com.authsignal.push.models.PushChallenge;
9
- import com.authsignal.push.models.PushCredential;
10
- import com.facebook.react.bridge.Arguments;
11
- import com.facebook.react.bridge.Promise;
12
- import com.facebook.react.bridge.ReactApplicationContext;
13
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
14
- import com.facebook.react.bridge.ReactMethod;
15
- import com.facebook.react.bridge.WritableMap;
16
-
17
- import java.util.HashMap;
18
- import java.util.Map;
19
-
20
- public class AuthsignalPushModule extends ReactContextBaseJavaModule {
21
- private final ReactApplicationContext reactContext;
22
-
23
- private AuthsignalPush authsignalPush;
24
-
25
- private final String TAG = "AuthsignalPasskeyModule";
26
- private final String INIT_WARNING = "AuthsignalPasskeyModule is not initialized.";
27
-
28
- public AuthsignalPushModule(ReactApplicationContext reactContext) {
29
- super(reactContext);
30
- this.reactContext = reactContext;
31
- }
32
-
33
- @Override
34
- public Map<String, Object> getConstants() {
35
- final Map<String, Object> constants = new HashMap<>();
36
- constants.put("bundleIdentifier", reactContext.getApplicationInfo().packageName);
37
- return constants;
38
- }
39
-
40
- @NonNull
41
- @Override
42
- public String getName() {
43
- return "AuthsignalPushModule";
44
- }
45
-
46
- @ReactMethod
47
- public void initialize(String tenantID, String baseURL, Promise promise) {
48
- authsignalPush = new AuthsignalPush(tenantID, baseURL);
49
-
50
- promise.resolve(null);
51
- }
52
-
53
- @ReactMethod
54
- public void getCredential(Promise promise) {
55
- if (authsignalPush != null) {
56
- authsignalPush
57
- .getCredentialAsync()
58
- .thenAcceptAsync((response) -> {
59
- if (response.getError() != null) {
60
- promise.reject("get_credential_error", response.getError());
61
- } else {
62
- PushCredential credential = response.getData();
63
- WritableMap map = Arguments.createMap();
64
- map.putString("credentialId", credential.getCredentialId());
65
- map.putString("createdAt", credential.getCreatedAt());
66
- map.putString("lastAuthenticatedAt", credential.getLastAuthenticatedAt());
67
- promise.resolve(map);
68
- }
69
- });
70
- } else {
71
- Log.w(TAG, INIT_WARNING);
72
-
73
- promise.resolve(null);
74
- }
75
- }
76
-
77
- @ReactMethod
78
- public void addCredential(
79
- String token,
80
- Promise promise) {
81
- if (authsignalPush != null) {
82
- authsignalPush
83
- .addCredentialAsync(token, null)
84
- .thenAcceptAsync(response -> {
85
- String errorCode = response.getErrorType() != null ?
86
- response.getErrorType() :
87
- "add_credential_error";
88
-
89
- if (response.getError() != null) {
90
- promise.reject(errorCode, response.getError());
91
- } else {
92
- promise.resolve(response.getData());
93
- }
94
- });
95
- } else {
96
- Log.w(TAG, INIT_WARNING);
97
-
98
- promise.resolve(false);
99
- }
100
- }
101
-
102
- @ReactMethod
103
- public void removeCredential(Promise promise) {
104
- if (authsignalPush != null) {
105
- authsignalPush
106
- .removeCredentialAsync()
107
- .thenAcceptAsync(response -> {
108
- if (response.getError() != null) {
109
- String errorCode = response.getErrorType() != null ?
110
- response.getErrorType() :
111
- "remove_credential_error";
112
-
113
- promise.reject(errorCode, response.getError());
114
- } else {
115
- promise.resolve(response.getData());
116
- }
117
- });
118
- } else {
119
- Log.w(TAG, INIT_WARNING);
120
-
121
- promise.resolve(false);
122
- }
123
- }
124
-
125
- @ReactMethod
126
- public void getChallenge(Promise promise) {
127
- if (authsignalPush != null) {
128
- authsignalPush
129
- .getChallengeAsync()
130
- .thenAcceptAsync(response -> {
131
- if (response.getError() != null) {
132
- String errorCode = response.getErrorType() != null ?
133
- response.getErrorType() :
134
- "get_challenge_error";
135
-
136
- promise.reject(errorCode, response.getError());
137
- } else {
138
- PushChallenge challenge = response.getData();
139
-
140
- if (challenge == null) {
141
- promise.resolve(null);
142
- } else {
143
- WritableMap map = Arguments.createMap();
144
- map.putString("challengeId", challenge.getChallengeId());
145
- map.putString("actionCode", challenge.getActionCode());
146
- map.putString("idempotencyKey", challenge.getIdempotencyKey());
147
- map.putString("ipAddress", challenge.getIpAddress());
148
- map.putString("deviceId", challenge.getDeviceId());
149
- map.putString("userAgent", challenge.getUserAgent());
150
- promise.resolve(map);
151
- }
152
- }
153
- });
154
- } else {
155
- Log.w(TAG, INIT_WARNING);
156
-
157
- promise.resolve(null);
158
- }
159
- }
160
-
161
- @ReactMethod
162
- public void updateChallenge(
163
- String challengeId,
164
- Boolean approved,
165
- String verificationCode,
166
- Promise promise
167
- ) {
168
- if (authsignalPush != null) {
169
- authsignalPush
170
- .updateChallengeAsync(challengeId, approved, verificationCode)
171
- .thenAcceptAsync(response -> {
172
- if (response.getError() != null) {
173
- String errorCode = response.getErrorType() != null ?
174
- response.getErrorType() :
175
- "update_challenge_error";
176
-
177
- promise.reject(errorCode, response.getError());
178
- } else {
179
- promise.resolve(response.getData());
180
- }
181
- });
182
- } else {
183
- Log.w(TAG, INIT_WARNING);
184
-
185
- promise.resolve(false);
186
- }
187
- }
188
- }
@@ -1,139 +0,0 @@
1
- package com.authsignal.react;
2
-
3
- import android.app.Activity;
4
- import android.util.Log;
5
-
6
- import androidx.annotation.NonNull;
7
-
8
- import com.authsignal.sms.AuthsignalSMS;
9
- import com.authsignal.models.*;
10
- import com.facebook.react.bridge.Arguments;
11
- import com.facebook.react.bridge.Promise;
12
- import com.facebook.react.bridge.ReactApplicationContext;
13
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
14
- import com.facebook.react.bridge.ReactMethod;
15
- import com.facebook.react.bridge.WritableMap;
16
-
17
- import java.util.HashMap;
18
- import java.util.Map;
19
-
20
- public class AuthsignalSMSModule extends ReactContextBaseJavaModule {
21
- private final ReactApplicationContext reactContext;
22
-
23
- private AuthsignalSMS authsignalSMS;
24
-
25
- private final String TAG = "AuthsignalSMSModule";
26
- private final String INIT_WARNING = "AuthsignalSMSModule is not initialized.";
27
-
28
- public AuthsignalSMSModule(ReactApplicationContext reactContext) {
29
- super(reactContext);
30
- this.reactContext = reactContext;
31
- }
32
-
33
- @Override
34
- public Map<String, Object> getConstants() {
35
- final Map<String, Object> constants = new HashMap<>();
36
- constants.put("bundleIdentifier", reactContext.getApplicationInfo().packageName);
37
- return constants;
38
- }
39
-
40
- @NonNull
41
- @Override
42
- public String getName() {
43
- return "AuthsignalSMSModule";
44
- }
45
-
46
- @ReactMethod
47
- public void initialize(String tenantID, String baseURL, Promise promise) {
48
- Activity currentActivity = reactContext.getCurrentActivity();
49
-
50
- if (currentActivity != null) {
51
- authsignalSMS = new AuthsignalSMS(
52
- tenantID,
53
- baseURL
54
- );
55
- }
56
-
57
- promise.resolve(null);
58
- }
59
-
60
- @ReactMethod
61
- public void enroll(String phoneNumber, Promise promise) {
62
- if (authsignalSMS != null) {
63
- authsignalSMS
64
- .enrollAsync(phoneNumber)
65
- .thenAcceptAsync(response -> {
66
- if (response.getError() != null) {
67
- String errorCode = response.getErrorType() != null ?
68
- response.getErrorType() :
69
- "enroll_error";
70
-
71
- promise.reject(errorCode, response.getError());
72
- } else {
73
- EnrollResponse enrollResponse = response.getData();
74
- WritableMap map = Arguments.createMap();
75
- map.putString("userAuthenticatorId", enrollResponse.getUserAuthenticatorId());
76
- promise.resolve(map);
77
- }
78
- });
79
- } else {
80
- Log.w(TAG, INIT_WARNING);
81
-
82
- promise.resolve(null);
83
- }
84
- }
85
-
86
- @ReactMethod
87
- public void challenge(Promise promise) {
88
- if (authsignalSMS != null) {
89
- authsignalSMS
90
- .challengeAsync()
91
- .thenAcceptAsync(response -> {
92
- if (response.getError() != null) {
93
- String errorCode = response.getErrorType() != null ?
94
- response.getErrorType() :
95
- "challenge_error";
96
-
97
- promise.reject(errorCode, response.getError());
98
- } else {
99
- ChallengeResponse challengeResponse = response.getData();
100
- WritableMap map = Arguments.createMap();
101
- map.putString("challengeId", challengeResponse.getChallengeId());
102
- promise.resolve(map);
103
- }
104
- });
105
- } else {
106
- Log.w(TAG, INIT_WARNING);
107
-
108
- promise.resolve(null);
109
- }
110
- }
111
-
112
- @ReactMethod
113
- public void verify(String code, Promise promise) {
114
- if (authsignalSMS != null) {
115
- authsignalSMS
116
- .verifyAsync(code)
117
- .thenAcceptAsync(response -> {
118
- if (response.getError() != null) {
119
- String errorCode = response.getErrorType() != null ?
120
- response.getErrorType() :
121
- "verify_error";
122
-
123
- promise.reject(errorCode, response.getError());
124
- } else {
125
- VerifyResponse verifyResponse = response.getData();
126
- WritableMap map = Arguments.createMap();
127
- map.putBoolean("isVerified", verifyResponse.isVerified());
128
- map.putString("token", verifyResponse.getToken());
129
- map.putString("failureReason", verifyResponse.getFailureReason());
130
- promise.resolve(map);
131
- }
132
- });
133
- } else {
134
- Log.w(TAG, INIT_WARNING);
135
-
136
- promise.resolve(null);
137
- }
138
- }
139
- }