Skip to content

Commit b7c402b

Browse files
committed
feat: auth-service v10 changes
Signed-off-by: Gaurav Goel <[email protected]>
1 parent 848a65c commit b7c402b

File tree

14 files changed

+72
-73
lines changed

14 files changed

+72
-73
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.web3auth.app
2+
3+
import com.web3auth.core.types.AUTH_CONNECTION
4+
5+
data class AuthConnectionLogin(
6+
val name: String,
7+
val authConnection: AUTH_CONNECTION
8+
)

app/src/main/java/com/web3auth/app/LoginVerifier.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

app/src/main/java/com/web3auth/app/MainActivity.kt

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ import com.google.gson.JsonArray
2121
import com.web3auth.core.Web3Auth
2222
import com.web3auth.core.isEmailValid
2323
import com.web3auth.core.isPhoneNumberValid
24+
import com.web3auth.core.types.AUTH_CONNECTION
25+
import com.web3auth.core.types.AuthConnection
26+
import com.web3auth.core.types.AuthConnectionConfig
2427
import com.web3auth.core.types.BuildEnv
2528
import com.web3auth.core.types.ChainConfig
2629
import com.web3auth.core.types.ChainNamespace
2730
import com.web3auth.core.types.ExtraLoginOptions
2831
import com.web3auth.core.types.Language
29-
import com.web3auth.core.types.LoginConfigItem
3032
import com.web3auth.core.types.LoginParams
3133
import com.web3auth.core.types.MFALevel
3234
import com.web3auth.core.types.Network
33-
import com.web3auth.core.types.Provider
3435
import com.web3auth.core.types.ThemeModes
35-
import com.web3auth.core.types.TypeOfLogin
3636
import com.web3auth.core.types.UserInfo
3737
import com.web3auth.core.types.Web3AuthOptions
3838
import com.web3auth.core.types.Web3AuthResponse
@@ -44,31 +44,31 @@ import java.util.concurrent.CompletableFuture
4444
class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
4545
private lateinit var web3Auth: Web3Auth
4646

47-
private val verifierList: List<LoginVerifier> = listOf(
48-
LoginVerifier("Google", Provider.GOOGLE),
49-
LoginVerifier("Facebook", Provider.FACEBOOK),
50-
LoginVerifier("Twitch", Provider.TWITCH),
51-
LoginVerifier("Discord", Provider.DISCORD),
52-
LoginVerifier("Reddit", Provider.REDDIT),
53-
LoginVerifier("Apple", Provider.APPLE),
54-
LoginVerifier("Github", Provider.GITHUB),
55-
LoginVerifier("LinkedIn", Provider.LINKEDIN),
56-
LoginVerifier("Twitter", Provider.TWITTER),
57-
LoginVerifier("Line", Provider.LINE),
58-
LoginVerifier("Hosted Email Passwordless", Provider.EMAIL_PASSWORDLESS),
59-
LoginVerifier("SMS Passwordless", Provider.SMS_PASSWORDLESS),
60-
LoginVerifier("JWT", Provider.JWT),
61-
LoginVerifier("Farcaster", Provider.FARCASTER)
47+
private val authConnectionList: List<AuthConnectionLogin> = listOf(
48+
AuthConnectionLogin("Google", AUTH_CONNECTION.GOOGLE),
49+
AuthConnectionLogin("Facebook", AUTH_CONNECTION.FACEBOOK),
50+
AuthConnectionLogin("Twitch", AUTH_CONNECTION.TWITCH),
51+
AuthConnectionLogin("Discord", AUTH_CONNECTION.DISCORD),
52+
AuthConnectionLogin("Reddit", AUTH_CONNECTION.REDDIT),
53+
AuthConnectionLogin("Apple", AUTH_CONNECTION.APPLE),
54+
AuthConnectionLogin("Github", AUTH_CONNECTION.GITHUB),
55+
AuthConnectionLogin("LinkedIn", AUTH_CONNECTION.LINKEDIN),
56+
AuthConnectionLogin("Twitter", AUTH_CONNECTION.TWITTER),
57+
AuthConnectionLogin("Line", AUTH_CONNECTION.LINE),
58+
AuthConnectionLogin("Hosted Email Passwordless", AUTH_CONNECTION.EMAIL_PASSWORDLESS),
59+
AuthConnectionLogin("SMS Passwordless", AUTH_CONNECTION.SMS_PASSWORDLESS),
60+
AuthConnectionLogin("JWT", AUTH_CONNECTION.JWT),
61+
AuthConnectionLogin("Farcaster", AUTH_CONNECTION.FARCASTER)
6262
)
6363

64-
private var selectedLoginProvider: Provider = Provider.GOOGLE
64+
private var selectedLoginProvider: AUTH_CONNECTION = AUTH_CONNECTION.GOOGLE
6565

6666
private val gson = Gson()
6767

6868
private fun signIn() {
6969
val hintEmailEditText = findViewById<EditText>(R.id.etEmailHint)
7070
var extraLoginOptions: ExtraLoginOptions? = null
71-
if (selectedLoginProvider == Provider.EMAIL_PASSWORDLESS) {
71+
if (selectedLoginProvider == AUTH_CONNECTION.EMAIL_PASSWORDLESS) {
7272
val hintEmail = hintEmailEditText.text.toString()
7373
if (hintEmail.isBlank() || !hintEmail.isEmailValid()) {
7474
Toast.makeText(this, "Please enter a valid Email.", Toast.LENGTH_LONG).show()
@@ -77,7 +77,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
7777
extraLoginOptions = ExtraLoginOptions(login_hint = hintEmail)
7878
}
7979

80-
if (selectedLoginProvider == Provider.SMS_PASSWORDLESS) {
80+
if (selectedLoginProvider == AUTH_CONNECTION.SMS_PASSWORDLESS) {
8181
val hintPhNo = hintEmailEditText.text.toString()
8282
if (hintPhNo.isBlank() || !hintPhNo.isPhoneNumberValid()) {
8383
Toast.makeText(this, "Please enter a valid Number.", Toast.LENGTH_LONG).show()
@@ -124,7 +124,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
124124
val signMsgButton = findViewById<Button>(R.id.signMsgButton)
125125
val btnSetUpMfa = findViewById<Button>(R.id.btnSetUpMfa)
126126
val btnManageMfa = findViewById<Button>(R.id.btn_manageMfa)
127-
val spinner = findViewById<TextInputLayout>(R.id.verifierList)
127+
val spinner = findViewById<TextInputLayout>(R.id.authConnectionList)
128128
val hintEmailEditText = findViewById<EditText>(R.id.etEmailHint)
129129
var key: String? = null
130130
var userInfo: UserInfo? = null
@@ -180,14 +180,14 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
180180
"onPrimary" to "#0000FF"
181181
)
182182
),
183-
loginConfig = hashMapOf(
184-
"loginConfig" to LoginConfigItem(
185-
"web3auth-auth0-email-passwordless-sapphire-devnet",
186-
typeOfLogin = TypeOfLogin.JWT,
187-
clientId = "d84f6xvbdV75VTGmHiMWfZLeSPk8M07C",
183+
authConnectionConfig = listOf(
184+
AuthConnectionConfig(
185+
authConnectionId = "web3auth-auth0-email-passwordless-sapphire-devnet",
186+
authConnection = AuthConnection.JWT,
187+
clientId = "d84f6xvbdV75VTGmHiMWfZLeSPk8M07C"
188188
)
189189
),
190-
buildEnv = BuildEnv.PRODUCTION,
190+
buildEnv = BuildEnv.TESTING,
191191
sessionTime = 86400,
192192
)
193193

@@ -288,7 +288,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
288288
}
289289

290290
val spinner = findViewById<AutoCompleteTextView>(R.id.spinnerTextView)
291-
val loginVerifierList: List<String> = verifierList.map { item ->
291+
val loginVerifierList: List<String> = authConnectionList.map { item ->
292292
item.name
293293
}
294294
val adapter: ArrayAdapter<String> =
@@ -312,17 +312,17 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
312312
}
313313

314314
override fun onItemClick(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
315-
selectedLoginProvider = verifierList[p2].loginProvider
315+
selectedLoginProvider = authConnectionList[p2].authConnection
316316

317317
val hintEmailEditText = findViewById<EditText>(R.id.etEmailHint)
318318

319-
if (selectedLoginProvider == Provider.EMAIL_PASSWORDLESS) {
319+
if (selectedLoginProvider == AUTH_CONNECTION.EMAIL_PASSWORDLESS) {
320320
hintEmailEditText.hint = "Enter Email"
321-
} else if (selectedLoginProvider == Provider.SMS_PASSWORDLESS) {
321+
} else if (selectedLoginProvider == AUTH_CONNECTION.SMS_PASSWORDLESS) {
322322
hintEmailEditText.hint = "Enter Phone Number"
323323
}
324324

325-
if (selectedLoginProvider == Provider.EMAIL_PASSWORDLESS || selectedLoginProvider == Provider.SMS_PASSWORDLESS) {
325+
if (selectedLoginProvider == AUTH_CONNECTION.EMAIL_PASSWORDLESS || selectedLoginProvider == AUTH_CONNECTION.SMS_PASSWORDLESS) {
326326
hintEmailEditText.visibility = View.VISIBLE
327327
} else {
328328
hintEmailEditText.visibility = View.GONE

app/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
tools:context="com.web3auth.app.MainActivity">
88

99
<com.google.android.material.textfield.TextInputLayout
10-
android:id="@+id/verifierList"
10+
android:id="@+id/authConnectionList"
1111
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
1212
android:layout_width="match_parent"
1313
android:layout_height="wrap_content"
@@ -39,7 +39,7 @@
3939
android:backgroundTint="@color/black"
4040
app:layout_constraintStart_toStartOf="parent"
4141
app:layout_constraintEnd_toEndOf="parent"
42-
app:layout_constraintTop_toBottomOf="@id/verifierList" />
42+
app:layout_constraintTop_toBottomOf="@id/authConnectionList" />
4343

4444

4545
<TextView

core/src/main/java/com/web3auth/core/Web3Auth.kt

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import com.web3auth.core.types.ErrorCode
1717
import com.web3auth.core.types.ExtraLoginOptions
1818
import com.web3auth.core.types.InitOptions
1919
import com.web3auth.core.types.InitParams
20-
import com.web3auth.core.types.LoginConfigItem
2120
import com.web3auth.core.types.LoginParams
2221
import com.web3auth.core.types.MFALevel
2322
import com.web3auth.core.types.REDIRECT_URL
@@ -73,7 +72,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
7372
network = web3AuthOption.network.name.lowercase(Locale.ROOT),
7473
redirectUrl = web3AuthOption.redirectUrl.toString(),
7574
whiteLabel = web3AuthOption.whiteLabel?.let { gson.toJson(it) },
76-
loginConfig = web3AuthOption.loginConfig?.let { gson.toJson(it) },
75+
authConnectionConfig = web3AuthOption.authConnectionConfig?.let { gson.toJson(it) },
7776
buildEnv = web3AuthOption.buildEnv?.name?.lowercase(Locale.ROOT),
7877
mfaSettings = web3AuthOption.mfaSettings?.let { gson.toJson(it) },
7978
sessionTime = web3AuthOption.sessionTime,
@@ -90,7 +89,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
9089
*/
9190
private fun getInitParams(params: LoginParams?): InitParams {
9291
return InitParams(
93-
loginProvider = params?.loginProvider?.name?.lowercase(Locale.ROOT),
92+
authConnection = params?.authConnection?.name?.lowercase(Locale.ROOT),
9493
extraLoginOptions = params?.extraLoginOptions?.let { gson.toJson(it) },
9594
redirectUrl = params?.redirectUrl?.toString() ?: web3AuthOption.redirectUrl.toString(),
9695
mfaLevel = params?.mfaLevel?.name?.lowercase(Locale.ROOT),
@@ -145,7 +144,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
145144
existingExtraLoginOptions =
146145
gson.fromJson(extraOptionsString, ExtraLoginOptions::class.java)
147146
}
148-
existingExtraLoginOptions.login_hint = userInfo?.verifierId
147+
existingExtraLoginOptions.login_hint = userInfo?.userId
149148
initParamsJson.put("extraLoginOptions", gson.toJson(existingExtraLoginOptions))
150149
initParamsJson.put("mfaLevel", MFALevel.MANDATORY.name.lowercase(Locale.ROOT))
151150
val loginIdObject = mapOf("loginId" to sessionId, "platform" to "android")
@@ -296,8 +295,8 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
296295

297296
if (web3AuthResponse?.userInfo?.dappShare?.isNotEmpty() == true) {
298297
KeyStoreManagerUtils.encryptData(
299-
web3AuthResponse?.userInfo?.verifier.plus(" | ")
300-
.plus(web3AuthResponse?.userInfo?.verifierId),
298+
web3AuthResponse?.userInfo?.authConnectionId.plus(" | ")
299+
.plus(web3AuthResponse?.userInfo?.userId),
301300
web3AuthResponse?.userInfo?.dappShare!!,
302301
)
303302
}
@@ -326,23 +325,22 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
326325
* @return A CompletableFuture<Web3AuthResponse> representing the asynchronous operation, containing the Web3AuthResponse upon successful login.
327326
*/
328327
fun login(loginParams: LoginParams): CompletableFuture<Web3AuthResponse> {
329-
//check for share
330-
if (web3AuthOption.loginConfig != null) {
331-
val loginConfigItem: LoginConfigItem? = web3AuthOption.loginConfig?.values?.first()
332-
val share: String? =
333-
KeyStoreManagerUtils.decryptData(loginConfigItem?.verifier.toString())
334-
if (share?.isNotEmpty() == true) {
335-
loginParams.dappShare = share
328+
web3AuthOption.authConnectionConfig
329+
?.firstOrNull()
330+
?.let { config ->
331+
val decryptedShare = KeyStoreManagerUtils.decryptData(config.authConnectionId)
332+
if (!decryptedShare.isNullOrEmpty()) {
333+
loginParams.dappShare = decryptedShare
334+
}
336335
}
337-
}
338336

339-
//login
340337
processRequest("login", loginParams)
341338

342-
loginCompletableFuture = CompletableFuture<Web3AuthResponse>()
339+
loginCompletableFuture = CompletableFuture()
343340
return loginCompletableFuture
344341
}
345342

343+
346344
/**
347345
* Logs out the user asynchronously.
348346
*

core/src/main/java/com/web3auth/core/types/LoginConfigItem.kt renamed to core/src/main/java/com/web3auth/core/types/AuthConnectionConfig.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package com.web3auth.core.types
33
import androidx.annotation.Keep
44

55
@Keep
6-
data class LoginConfigItem(
7-
@Keep var verifier: String,
8-
@Keep var typeOfLogin: TypeOfLogin,
6+
data class AuthConnectionConfig(
7+
@Keep var authConnectionId: String,
8+
@Keep var authConnection: AuthConnection,
99
@Keep var name: String? = null,
1010
@Keep var description: String? = null,
1111
@Keep var clientId: String,

core/src/main/java/com/web3auth/core/types/InitOptions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data class InitOptions(
88
@Keep val network: String,
99
@Keep var redirectUrl: String? = null,
1010
@Keep val whiteLabel: String? = null,
11-
@Keep val loginConfig: String? = null,
11+
@Keep val authConnectionConfig: String? = null,
1212
@Keep val buildEnv: String? = null,
1313
@Keep val mfaSettings: String? = null,
1414
@Keep val sessionTime: Int? = null,

core/src/main/java/com/web3auth/core/types/InitParams.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import androidx.annotation.Keep
44

55
@Keep
66
data class InitParams(
7-
@Keep val loginProvider: String? = null,
7+
@Keep val authConnection: String? = null,
88
@Keep val extraLoginOptions: String? = null,
99
@Keep val redirectUrl: String,
1010
@Keep val mfaLevel: String? = null,

core/src/main/java/com/web3auth/core/types/LoginParams.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import androidx.annotation.Keep
55

66
@Keep
77
data class LoginParams(
8-
@Keep val loginProvider: Provider,
8+
@Keep val authConnection: AUTH_CONNECTION,
99
@Keep var dappShare: String? = null,
1010
@Keep val extraLoginOptions: ExtraLoginOptions? = null,
1111
@Keep @Transient var redirectUrl: Uri? = null,

core/src/main/java/com/web3auth/core/types/Provider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import androidx.annotation.Keep
44
import com.google.gson.annotations.SerializedName
55

66
@Keep
7-
enum class Provider {
7+
enum class AUTH_CONNECTION {
88
@SerializedName("google")
99
GOOGLE,
1010

@@ -48,7 +48,7 @@ enum class Provider {
4848
EMAIL_PASSWORDLESS,
4949

5050
@SerializedName("jwt")
51-
JWT,
51+
JWT, // needs to check whether removed or not
5252

5353
@SerializedName("sms_passwordless")
5454
SMS_PASSWORDLESS,

0 commit comments

Comments
 (0)