Android example demonstrating custom authentication with Firebase using MetaMask Embedded Wallets (formerly Web3Auth Plug and Play). Firebase authenticates the user, then the Firebase ID token is passed directly to Web3Auth to derive the user's EVM wallet.
- Firebase Email/Password authentication
- Custom JWT flow: Firebase ID token → Web3Auth wallet derivation
- EVM wallet creation and management
- Get wallet address, Sepolia balance, sign messages, and send transactions
- Session persistence across app restarts
- Android Studio Hedgehog (2023.1.1) or later
- Android API 24+, Compile SDK 34
- JDK 17+
- Firebase account with a project configured
- MetaMask Embedded Wallets Dashboard account
git clone https://github.com/Web3Auth/web3auth-android-examples.git
cd web3auth-android-examples/android-firebase-example- Create an Android app in Firebase Console.
- Enable Email/Password sign-in under Authentication → Sign-in methods.
- Download
google-services.jsonand place it in theapp/directory. - Add the SHA-1 fingerprint of your debug keystore in Firebase Console (Project Settings → Your App).
- Create a project on the Embedded Wallets Dashboard.
- Go to Authentication → create a custom connection with:
- Type: Firebase
- JWKS Endpoint:
https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com - User ID field:
sub - JWT Validation:
audfield equals your Firebase project ID
- Note your Auth Connection ID (verifier name). This example uses
w3a-firebase-demo. - Allowlist your redirect URI:
com.sbz.web3authdemoapp://auth
<string name="web3auth_project_id">YOUR_WEB3AUTH_CLIENT_ID</string>web3Auth = Web3Auth(
Web3AuthOptions(
clientId = getString(R.string.web3auth_project_id),
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET,
redirectUrl = "com.sbz.web3authdemoapp://auth",
authConnectionConfig = listOf(
AuthConnectionConfig(
authConnection = AuthConnection.CUSTOM,
authConnectionId = "w3a-firebase-demo", // your Auth Connection ID from dashboard
clientId = getString(R.string.web3auth_project_id)
)
)
), this
)
web3Auth.setResultUrl(intent?.data)
val sessionResponse: CompletableFuture<Void> = web3Auth.initialize()
sessionResponse.whenComplete { _, error ->
if (error == null) {
val credentials = Credentials.create(web3Auth.getPrivateKey())
}
}// 1. Sign in with Firebase
Firebase.auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
// 2. Get the Firebase ID token (must be fresh — max 60s old)
Firebase.auth.currentUser?.getIdToken(true)
?.addOnSuccessListener { result ->
val idToken = result.token ?: return@addOnSuccessListener
// 3. Pass the ID token directly to Web3Auth
val loginFuture: CompletableFuture<Web3AuthResponse> =
web3Auth.connectTo(
LoginParams(
authConnection = AuthConnection.CUSTOM,
authConnectionId = "w3a-firebase-demo",
idToken = idToken
)
)
loginFuture.whenComplete { _, error ->
if (error == null) {
val credentials = Credentials.create(web3Auth.getPrivateKey())
}
}
}
}
}override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
web3Auth.setResultUrl(intent?.data)
}
override fun onResume() {
super.onResume()
if (Web3Auth.getCustomTabsClosed()) {
web3Auth.setResultUrl(null)
Web3Auth.setCustomTabsClosed(false)
}
}- Android SDK Documentation
- Custom Authentication Guide
- Firebase Android Setup
- MetaMask Embedded Wallets Docs
- Dashboard
- Builder Hub Community
MIT — see LICENSE for details.