Enable MFA for a user
The enableMFA method is used to trigger MFA setup flow for users. The method takes LoginParams which will used during custom verifiers. If you are using default sign-in providers, you don't need to pass LoginParams. If you are using custom JWT verifiers, you need to pass the JWT token in loginParams as well.
Usage
- Default Verifier
- Custom JWT Verifier
Usage
import android.widget.Button
import com.web3auth.core.Web3Auth
import android.os.Bundle
class MainActivity : AppCompatActivity() {
private lateinit var web3Auth: Web3Auth
private fun enableMFA() {
val completableFuture = web3Auth.enableMFA()
completableFuture.whenComplete{_, error ->
if (error == null) {
Log.d("MainActivity_Web3Auth", "Launched successfully")
// Add your logic
} else {
// Add your logic on error
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
...
// Setup UI and event handlers
val enableMFAButton = findViewById<Button>(R.id.enableMFAButton)
enableMFAButton.setOnClickListener { enableMFA() }
...
}
...
}
warning
enableMFA does not accept an idToken in LoginParams. Passing idToken will cause the SDK to throw an ENABLE_MFA_NOT_ALLOWED error. For custom JWT verifiers, pass an empty LoginParams with the authConnection only; the SDK automatically uses the session's auth connection to re-authenticate.
Usage
import android.widget.Button
import com.web3auth.core.Web3Auth
import android.os.Bundle
class MainActivity : AppCompatActivity() {
private lateinit var web3Auth: Web3Auth
private fun enableMFA() {
val loginParams = LoginParams(
AuthConnection.CUSTOM,
authConnectionId = "your_auth_connection_id"
)
val completableFuture = web3Auth.enableMFA(loginParams)
completableFuture.whenComplete { _, error ->
if (error == null) {
Log.d("MainActivity_Web3Auth", "Launched successfully")
// Add your logic
} else {
// Add your logic on error
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
...
// Setup UI and event handlers
val enableMFAButton = findViewById<Button>(R.id.enableMFAButton)
enableMFAButton.setOnClickListener { enableMFA() }
...
}
...
}