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.
- package/android/build.gradle +27 -87
- package/android/gradle/wrapper/gradle-wrapper.properties +3 -2
- package/android/gradle.properties +4 -3
- package/android/src/main/java/com/authsignal/react/AuthenticationActivity.kt +69 -0
- package/android/src/main/java/com/authsignal/react/AuthsignalEmailModule.kt +113 -0
- package/android/src/main/java/com/authsignal/react/AuthsignalModule.kt +115 -0
- package/android/src/main/java/com/authsignal/react/AuthsignalPackage.kt +23 -0
- package/android/src/main/java/com/authsignal/react/AuthsignalPasskeyModule.kt +103 -0
- package/android/src/main/java/com/authsignal/react/AuthsignalPushModule.kt +152 -0
- package/android/src/main/java/com/authsignal/react/AuthsignalSMSModule.kt +117 -0
- package/android/src/main/java/com/authsignal/react/AuthsignalTOTPModule.kt +95 -0
- package/android/src/main/java/com/authsignal/react/RedirectActivity.kt +17 -0
- package/package.json +1 -1
- package/android/src/main/java/com/authsignal/react/AuthenticationActivity.java +0 -73
- package/android/src/main/java/com/authsignal/react/AuthsignalEmailModule.java +0 -139
- package/android/src/main/java/com/authsignal/react/AuthsignalModule.java +0 -127
- package/android/src/main/java/com/authsignal/react/AuthsignalPackage.java +0 -29
- package/android/src/main/java/com/authsignal/react/AuthsignalPasskeyModule.java +0 -133
- package/android/src/main/java/com/authsignal/react/AuthsignalPushModule.java +0 -188
- package/android/src/main/java/com/authsignal/react/AuthsignalSMSModule.java +0 -139
- package/android/src/main/java/com/authsignal/react/AuthsignalTOTPModule.java +0 -116
- package/android/src/main/java/com/authsignal/react/RedirectActivity.java +0 -18
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
package com.authsignal.react
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.authsignal.push.AuthsignalPush
|
|
5
|
+
import com.facebook.react.bridge.Arguments
|
|
6
|
+
import com.facebook.react.bridge.Promise
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
9
|
+
import com.facebook.react.bridge.ReactMethod
|
|
10
|
+
import kotlinx.coroutines.CoroutineScope
|
|
11
|
+
import kotlinx.coroutines.Dispatchers
|
|
12
|
+
import kotlinx.coroutines.SupervisorJob
|
|
13
|
+
import kotlinx.coroutines.launch
|
|
14
|
+
|
|
15
|
+
class AuthsignalPushModule(private val reactContext: ReactApplicationContext) :
|
|
16
|
+
ReactContextBaseJavaModule(
|
|
17
|
+
reactContext
|
|
18
|
+
) {
|
|
19
|
+
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
|
|
20
|
+
private var authsignal: AuthsignalPush? = null
|
|
21
|
+
private var defaultError = "unexpected_error"
|
|
22
|
+
|
|
23
|
+
override fun getConstants(): Map<String, Any>? {
|
|
24
|
+
val constants: MutableMap<String, Any> = HashMap()
|
|
25
|
+
constants["bundleIdentifier"] = reactContext.applicationInfo.packageName
|
|
26
|
+
return constants
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
override fun getName(): String {
|
|
30
|
+
return "AuthsignalPushModule"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@ReactMethod
|
|
34
|
+
fun initialize(tenantID: String?, baseURL: String?, promise: Promise) {
|
|
35
|
+
authsignal = AuthsignalPush(tenantID!!, baseURL!!)
|
|
36
|
+
|
|
37
|
+
promise.resolve(null)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@ReactMethod
|
|
41
|
+
fun getCredential(promise: Promise) {
|
|
42
|
+
launch(promise) {
|
|
43
|
+
val response = it.getCredential()
|
|
44
|
+
|
|
45
|
+
if (response.error != null) {
|
|
46
|
+
val errorCode = response.errorType ?: defaultError
|
|
47
|
+
|
|
48
|
+
promise.reject(errorCode, response.error)
|
|
49
|
+
} else {
|
|
50
|
+
val credential = response.data
|
|
51
|
+
val map = Arguments.createMap()
|
|
52
|
+
map.putString("credentialId", credential!!.credentialId)
|
|
53
|
+
map.putString("createdAt", credential.createdAt)
|
|
54
|
+
map.putString("lastAuthenticatedAt", credential.lastAuthenticatedAt)
|
|
55
|
+
promise.resolve(map)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@ReactMethod
|
|
61
|
+
fun addCredential(
|
|
62
|
+
token: String?,
|
|
63
|
+
promise: Promise
|
|
64
|
+
) {
|
|
65
|
+
launch(promise) {
|
|
66
|
+
val response = it.addCredential(token, null)
|
|
67
|
+
|
|
68
|
+
if (response.error != null) {
|
|
69
|
+
val errorCode = response.errorType ?: defaultError
|
|
70
|
+
|
|
71
|
+
promise.reject(errorCode, response.error)
|
|
72
|
+
} else {
|
|
73
|
+
promise.resolve(response.data)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@ReactMethod
|
|
79
|
+
fun removeCredential(promise: Promise) {
|
|
80
|
+
launch(promise) {
|
|
81
|
+
val response = it.removeCredential()
|
|
82
|
+
|
|
83
|
+
if (response.error != null) {
|
|
84
|
+
val errorCode = response.errorType ?: defaultError
|
|
85
|
+
|
|
86
|
+
promise.reject(errorCode, response.error)
|
|
87
|
+
} else {
|
|
88
|
+
promise.resolve(response.data)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@ReactMethod
|
|
94
|
+
fun getChallenge(promise: Promise) {
|
|
95
|
+
launch(promise) {
|
|
96
|
+
val response = it.getChallenge()
|
|
97
|
+
|
|
98
|
+
if (response.error != null) {
|
|
99
|
+
val errorCode = response.errorType ?: defaultError
|
|
100
|
+
|
|
101
|
+
promise.reject(errorCode, response.error)
|
|
102
|
+
} else {
|
|
103
|
+
val challenge = response.data
|
|
104
|
+
|
|
105
|
+
if (challenge == null) {
|
|
106
|
+
promise.resolve(null)
|
|
107
|
+
} else {
|
|
108
|
+
val map = Arguments.createMap()
|
|
109
|
+
map.putString("challengeId", challenge.challengeId)
|
|
110
|
+
map.putString("actionCode", challenge.actionCode)
|
|
111
|
+
map.putString("idempotencyKey", challenge.idempotencyKey)
|
|
112
|
+
map.putString("ipAddress", challenge.ipAddress)
|
|
113
|
+
map.putString("deviceId", challenge.deviceId)
|
|
114
|
+
map.putString("userAgent", challenge.userAgent)
|
|
115
|
+
promise.resolve(map)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@ReactMethod
|
|
122
|
+
fun updateChallenge(
|
|
123
|
+
challengeId: String,
|
|
124
|
+
approved: Boolean,
|
|
125
|
+
verificationCode: String?,
|
|
126
|
+
promise: Promise
|
|
127
|
+
) {
|
|
128
|
+
launch(promise) {
|
|
129
|
+
val response = it.updateChallenge(challengeId, approved, verificationCode)
|
|
130
|
+
|
|
131
|
+
if (response.error != null) {
|
|
132
|
+
val errorCode = response.errorType ?: defaultError
|
|
133
|
+
|
|
134
|
+
promise.reject(errorCode, response.error)
|
|
135
|
+
} else {
|
|
136
|
+
promise.resolve(response.data)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private fun launch(promise: Promise, fn: suspend (client: AuthsignalPush) -> Unit) {
|
|
142
|
+
coroutineScope.launch {
|
|
143
|
+
authsignal?.let {
|
|
144
|
+
fn(it)
|
|
145
|
+
} ?: run {
|
|
146
|
+
Log.w("init_error", "AuthsignalPushModule is not initialized.")
|
|
147
|
+
|
|
148
|
+
promise.resolve(null)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
package com.authsignal.react
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.authsignal.models.AuthsignalResponse
|
|
5
|
+
import com.authsignal.models.ChallengeResponse
|
|
6
|
+
import com.authsignal.models.EnrollResponse
|
|
7
|
+
import com.authsignal.models.VerifyResponse
|
|
8
|
+
import com.authsignal.sms.AuthsignalSMS
|
|
9
|
+
import com.authsignal.totp.AuthsignalTOTP
|
|
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 kotlinx.coroutines.CoroutineScope
|
|
16
|
+
import kotlinx.coroutines.Dispatchers
|
|
17
|
+
import kotlinx.coroutines.SupervisorJob
|
|
18
|
+
import kotlinx.coroutines.launch
|
|
19
|
+
import java.util.function.Consumer
|
|
20
|
+
|
|
21
|
+
class AuthsignalSMSModule(private val reactContext: ReactApplicationContext) :
|
|
22
|
+
ReactContextBaseJavaModule(
|
|
23
|
+
reactContext
|
|
24
|
+
) {
|
|
25
|
+
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
|
|
26
|
+
private var authsignal: AuthsignalSMS? = null
|
|
27
|
+
private val defaultError = "unexpected_error"
|
|
28
|
+
|
|
29
|
+
override fun getConstants(): Map<String, Any>? {
|
|
30
|
+
val constants: MutableMap<String, Any> = HashMap()
|
|
31
|
+
constants["bundleIdentifier"] = reactContext.applicationInfo.packageName
|
|
32
|
+
return constants
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun getName(): String {
|
|
36
|
+
return "AuthsignalSMSModule"
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@ReactMethod
|
|
40
|
+
fun initialize(tenantID: String, baseURL: String, promise: Promise) {
|
|
41
|
+
val currentActivity = reactContext.currentActivity
|
|
42
|
+
|
|
43
|
+
if (currentActivity != null) {
|
|
44
|
+
authsignal = AuthsignalSMS(tenantID, baseURL)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
promise.resolve(null)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@ReactMethod
|
|
51
|
+
fun enroll(phoneNumber: String, promise: Promise) {
|
|
52
|
+
launch(promise) {
|
|
53
|
+
val response = it.enroll(phoneNumber)
|
|
54
|
+
|
|
55
|
+
if (response.error != null) {
|
|
56
|
+
val errorCode = response.errorType ?: defaultError
|
|
57
|
+
|
|
58
|
+
promise.reject(errorCode, response.error)
|
|
59
|
+
} else {
|
|
60
|
+
val enrollResponse = response.data
|
|
61
|
+
val map = Arguments.createMap()
|
|
62
|
+
map.putString("userAuthenticatorId", enrollResponse!!.userAuthenticatorId)
|
|
63
|
+
promise.resolve(map)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@ReactMethod
|
|
69
|
+
fun challenge(promise: Promise) {
|
|
70
|
+
launch(promise) {
|
|
71
|
+
val response = it.challenge()
|
|
72
|
+
|
|
73
|
+
if (response.error != null) {
|
|
74
|
+
val errorCode = response.errorType ?: defaultError
|
|
75
|
+
|
|
76
|
+
promise.reject(errorCode, response.error)
|
|
77
|
+
} else {
|
|
78
|
+
val challengeResponse = response.data
|
|
79
|
+
val map = Arguments.createMap()
|
|
80
|
+
map.putString("challengeId", challengeResponse!!.challengeId)
|
|
81
|
+
promise.resolve(map)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@ReactMethod
|
|
87
|
+
fun verify(code: String, promise: Promise) {
|
|
88
|
+
launch(promise) {
|
|
89
|
+
val response = it.verify(code)
|
|
90
|
+
|
|
91
|
+
if (response.error != null) {
|
|
92
|
+
val errorCode = response.errorType ?: defaultError
|
|
93
|
+
|
|
94
|
+
promise.reject(errorCode, response.error)
|
|
95
|
+
} else {
|
|
96
|
+
val verifyResponse = response.data
|
|
97
|
+
val map = Arguments.createMap()
|
|
98
|
+
map.putBoolean("isVerified", verifyResponse!!.isVerified)
|
|
99
|
+
map.putString("token", verifyResponse.token)
|
|
100
|
+
map.putString("failureReason", verifyResponse.failureReason)
|
|
101
|
+
promise.resolve(map)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private fun launch(promise: Promise, fn: suspend (client: AuthsignalSMS) -> Unit) {
|
|
107
|
+
coroutineScope.launch {
|
|
108
|
+
authsignal?.let {
|
|
109
|
+
fn(it)
|
|
110
|
+
} ?: run {
|
|
111
|
+
Log.w("init_error", "AuthsignalSMSModule is not initialized.")
|
|
112
|
+
|
|
113
|
+
promise.resolve(null)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
package com.authsignal.react
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.authsignal.totp.AuthsignalTOTP
|
|
5
|
+
import com.facebook.react.bridge.Arguments
|
|
6
|
+
import com.facebook.react.bridge.Promise
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
9
|
+
import com.facebook.react.bridge.ReactMethod
|
|
10
|
+
import kotlinx.coroutines.CoroutineScope
|
|
11
|
+
import kotlinx.coroutines.Dispatchers
|
|
12
|
+
import kotlinx.coroutines.SupervisorJob
|
|
13
|
+
import kotlinx.coroutines.launch
|
|
14
|
+
|
|
15
|
+
class AuthsignalTOTPModule(private val reactContext: ReactApplicationContext) :
|
|
16
|
+
ReactContextBaseJavaModule(
|
|
17
|
+
reactContext
|
|
18
|
+
) {
|
|
19
|
+
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
|
|
20
|
+
private var authsignal: AuthsignalTOTP? = null
|
|
21
|
+
private val defaultError = "unexpected_error"
|
|
22
|
+
|
|
23
|
+
override fun getConstants(): Map<String, Any>? {
|
|
24
|
+
val constants: MutableMap<String, Any> = HashMap()
|
|
25
|
+
constants["bundleIdentifier"] = reactContext.applicationInfo.packageName
|
|
26
|
+
return constants
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
override fun getName(): String {
|
|
30
|
+
return "AuthsignalTOTPModule"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@ReactMethod
|
|
34
|
+
fun initialize(tenantID: String, baseURL: String, promise: Promise) {
|
|
35
|
+
val currentActivity = reactContext.currentActivity
|
|
36
|
+
|
|
37
|
+
if (currentActivity != null) {
|
|
38
|
+
authsignal = AuthsignalTOTP(tenantID, baseURL)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
promise.resolve(null)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@ReactMethod
|
|
45
|
+
fun enroll(promise: Promise) {
|
|
46
|
+
launch(promise) {
|
|
47
|
+
val response = it.enroll()
|
|
48
|
+
|
|
49
|
+
if (response.error != null) {
|
|
50
|
+
val errorCode = response.errorType ?: defaultError
|
|
51
|
+
|
|
52
|
+
promise.reject(errorCode, response.error)
|
|
53
|
+
} else {
|
|
54
|
+
val enrollResponse = response.data
|
|
55
|
+
val map = Arguments.createMap()
|
|
56
|
+
map.putString("userAuthenticatorId", enrollResponse!!.userAuthenticatorId)
|
|
57
|
+
map.putString("uri", enrollResponse.uri)
|
|
58
|
+
map.putString("secret", enrollResponse.secret)
|
|
59
|
+
promise.resolve(map)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@ReactMethod
|
|
65
|
+
fun verify(code: String, promise: Promise) {
|
|
66
|
+
launch(promise) {
|
|
67
|
+
val response = it.verify(code)
|
|
68
|
+
|
|
69
|
+
if (response.error != null) {
|
|
70
|
+
val errorCode = response.errorType ?: "verify_error"
|
|
71
|
+
|
|
72
|
+
promise.reject(errorCode, response.error)
|
|
73
|
+
} else {
|
|
74
|
+
val verifyResponse = response.data
|
|
75
|
+
val map = Arguments.createMap()
|
|
76
|
+
map.putBoolean("isVerified", verifyResponse!!.isVerified)
|
|
77
|
+
map.putString("token", verifyResponse.token)
|
|
78
|
+
map.putString("failureReason", verifyResponse.failureReason)
|
|
79
|
+
promise.resolve(map)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private fun launch(promise: Promise, fn: suspend (client: AuthsignalTOTP) -> Unit) {
|
|
85
|
+
coroutineScope.launch {
|
|
86
|
+
authsignal?.let {
|
|
87
|
+
fn(it)
|
|
88
|
+
} ?: run {
|
|
89
|
+
Log.w("init_error", "AuthsignalTOTPModule is not initialized.")
|
|
90
|
+
|
|
91
|
+
promise.resolve(null)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.authsignal.react
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.content.Intent
|
|
5
|
+
import android.os.Bundle
|
|
6
|
+
import com.authsignal.react.AuthenticationActivity
|
|
7
|
+
|
|
8
|
+
class RedirectActivity : Activity() {
|
|
9
|
+
public override fun onCreate(savedInstanceBundle: Bundle?) {
|
|
10
|
+
super.onCreate(savedInstanceBundle)
|
|
11
|
+
val intent = Intent(this, AuthenticationActivity::class.java)
|
|
12
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
|
13
|
+
if (getIntent() != null) intent.setData(getIntent().data)
|
|
14
|
+
startActivity(intent)
|
|
15
|
+
finish()
|
|
16
|
+
}
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
package com.authsignal.react;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.content.Intent;
|
|
5
|
-
import android.net.Uri;
|
|
6
|
-
import android.os.Bundle;
|
|
7
|
-
|
|
8
|
-
import androidx.annotation.NonNull;
|
|
9
|
-
import androidx.annotation.Nullable;
|
|
10
|
-
import androidx.browser.customtabs.CustomTabsIntent;
|
|
11
|
-
|
|
12
|
-
public class AuthenticationActivity extends Activity {
|
|
13
|
-
static final int AUTHENTICATION_REQUEST = 1000;
|
|
14
|
-
static final String EXTRA_AUTHORIZE_URI = "com.authsignal.react.EXTRA_AUTHORIZE_URI";
|
|
15
|
-
private static final String EXTRA_INTENT_LAUNCHED = "com.authsignal.react.EXTRA_INTENT_LAUNCHED";
|
|
16
|
-
|
|
17
|
-
private boolean intentLaunched;
|
|
18
|
-
|
|
19
|
-
static void authenticateUsingBrowser(@NonNull Activity activity, @NonNull Uri authorizeUri) {
|
|
20
|
-
Intent intent = new Intent(activity, AuthenticationActivity.class);
|
|
21
|
-
intent.putExtra(AuthenticationActivity.EXTRA_AUTHORIZE_URI, authorizeUri);
|
|
22
|
-
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
23
|
-
activity.startActivityForResult(intent, AUTHENTICATION_REQUEST);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@Override
|
|
27
|
-
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
28
|
-
super.onCreate(savedInstanceState);
|
|
29
|
-
if (savedInstanceState != null) {
|
|
30
|
-
intentLaunched = savedInstanceState.getBoolean(EXTRA_INTENT_LAUNCHED, false);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@Override
|
|
35
|
-
protected void onResume() {
|
|
36
|
-
super.onResume();
|
|
37
|
-
final Intent authenticationIntent = getIntent();
|
|
38
|
-
|
|
39
|
-
if (!intentLaunched && authenticationIntent.getExtras() == null) {
|
|
40
|
-
finish();
|
|
41
|
-
return;
|
|
42
|
-
} else if (!intentLaunched) {
|
|
43
|
-
intentLaunched = true;
|
|
44
|
-
launchAuthenticationIntent();
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
boolean resultMissing = authenticationIntent.getData() == null;
|
|
49
|
-
if (resultMissing) setResult(RESULT_CANCELED);
|
|
50
|
-
else setResult(RESULT_OK, authenticationIntent);
|
|
51
|
-
finish();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@Override
|
|
55
|
-
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
|
56
|
-
super.onSaveInstanceState(outState);
|
|
57
|
-
outState.putBoolean(EXTRA_INTENT_LAUNCHED, intentLaunched);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@Override
|
|
61
|
-
protected void onNewIntent(@Nullable Intent intent) {
|
|
62
|
-
super.onNewIntent(intent);
|
|
63
|
-
setIntent(intent);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private void launchAuthenticationIntent() {
|
|
67
|
-
Bundle extras = getIntent().getExtras();
|
|
68
|
-
Uri authorizeUri = extras.getParcelable(EXTRA_AUTHORIZE_URI);
|
|
69
|
-
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
|
70
|
-
CustomTabsIntent customTabsIntent = builder.build();
|
|
71
|
-
customTabsIntent.launchUrl(this, authorizeUri);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -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.email.AuthsignalEmail;
|
|
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 AuthsignalEmailModule extends ReactContextBaseJavaModule {
|
|
21
|
-
private final ReactApplicationContext reactContext;
|
|
22
|
-
|
|
23
|
-
private AuthsignalEmail authsignalEmail;
|
|
24
|
-
|
|
25
|
-
private final String TAG = "AuthsignalEmailModule";
|
|
26
|
-
private final String INIT_WARNING = "AuthsignalEmailModule is not initialized.";
|
|
27
|
-
|
|
28
|
-
public AuthsignalEmailModule(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 "AuthsignalEmailModule";
|
|
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
|
-
authsignalEmail = new AuthsignalEmail(
|
|
52
|
-
tenantID,
|
|
53
|
-
baseURL
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
promise.resolve(null);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@ReactMethod
|
|
61
|
-
public void enroll(String email, Promise promise) {
|
|
62
|
-
if (authsignalEmail != null) {
|
|
63
|
-
authsignalEmail
|
|
64
|
-
.enrollAsync(email)
|
|
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 (authsignalEmail != null) {
|
|
89
|
-
authsignalEmail
|
|
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 (authsignalEmail != null) {
|
|
115
|
-
authsignalEmail
|
|
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
|
-
}
|