Integrate Firebase phone number validation with your backend

David Magalhães
Sep 26, 2018 · 4 min read
  1. Use their Authy product that already provide an API to handle the authentication and validation.
public void onCodeSent(
String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPhoneNumber?key={FIREBASE_SERVER_KEY}{
"sessionInfo": "6-seBr9nJHXxPoA-NjqGfDyoIKMGmiJec7wUfT7vSZ0DOGSy",
"code": "123456"
}
{
“idToken”: “eyJhbGciOiJEanNZspytaJL4wDZmu2OcwQujC360AJ_Q”,
“refreshToken”: “AGdpqez1qnYIzh8cm7JD9fHmoPK30PGNEGY3iP8l”,
“expiresIn”: “3600”,
“localId”: “LRrMOTY0gj1”,
“isNewUser”: false,
“phoneNumber”: “+351966666666”
}
POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo?key={FIREBASE_SERVER_KEY}{
“idToken”: “eyJhbGciOiJEanNZspytaJL4wDZmu2OcwQujC360AJ_Q”
}
{
…,
“users”: [
{
…,
“phoneNumber”: “+351966666666”,

}
]
}

Final thoughts

That’s it! This is enough to validate your accounts with users phone numbers.

Coletiv

Thoughts, dreams and rants about technology and work life from the Coletiv team

Thanks to Tiago Duarte.

David Magalhães

Written by

Software Developer

Coletiv

Coletiv

Thoughts, dreams and rants about technology and work life from the Coletiv team