Enable MFA for a user
The enableMFA method is used to trigger MFA setup flow for users. If you are using default sign-in providers, you don't need to pass LoginParams. If the user signed in with a custom auth connection that needs extra sign-in options (for example, Auth0), pass the same LoginParams you used to sign in.
enableMFA returns a CompletableFuture<Boolean>. It fails with MFA already enabled if the user has already enabled MFA, and with No user found, please login again! if there's no active session.
The SDK fills in the auth connection details from the current session, so the authConnection value you pass doesn't change which connection is used.
warning
- Don't pass
idTokeninLoginParams. The method fails withEnabling MFA is not allowed for this user.ifidTokenis set. - This method isn't available for users who signed in with SFA (
connectTowithidToken).
Usage
- Default Verifier
- Custom Auth Connection
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() }
...
}
...
}
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() {
// Use the same LoginParams you used to sign in, without idToken
val loginParams = LoginParams(
AuthConnection.CUSTOM,
authConnectionId = "your_auth_connection_id",
extraLoginOptions = ExtraLoginOptions(
domain = "https://YOUR_AUTH0_DOMAIN"
)
)
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() }
...
}
...
}