Setup Phone Authentication

Enable “Phone Authentication” on the Firebase console.

Firebase Console -> Develop (on the left menu) -> Authentication -> Sign-In Method -> Phone is enabled.

Add SHA certificate to Firebase console

This step is necessary for Android Phone auth, without the authentication will not work.

You can run this command or visit https://developers.google.com/android/guides/client-auth for more details

To get the debug certificate fingerprint:

keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore

you be asked for a password, it should: android

the result will be like the following, you have to copy the SHA1 and SHA-256.

> Task :app:signingReport
Variant: debug
Config: debug
Store: ~/.android/debug.keystore
Alias: AndroidDebugKey
MD5: A5:88:41:04:8D:06:71:6D:FE:33:76:87:AC:AD:19:23
SHA1: A7:89:E5:05:C8:17:A1:22:EA:90:6E:A6:EA:A3:D4:8B:3A:30:AB:18
SHA-256: 05:A2:2C:35:EE:F2:51:23:72:4D:72:67:A5:6C:8C:58:22:2A:00:D6:DB:F6:45:D5:C1:82:D2:80:A4:69:A8:FE
Valid until: Wednesday, August 10, 2044

The same thing is for release, you have to refer to your keystore location, the one below is for testing purposes.

keytool -list -v -alias key0 -keystore ./android/app/test_keystore

key0 is the alias key and ./android/app/test_keystore is path to your Keystore file

you will be asked to add password, for the testing key, it's12345678

Copy the two SHA1 and SHA-256 keys to Firebase Console

iOS Phone Authentication setup

For phone authentication to work properly on iOS and receive sms. the next words are taken from official firebase website https://firebase.google.com/docs/auth/ios/phone-auth

To use phone number authentication, Firebase must be able to verify that phone number sign-in requests are coming from your app. There are two ways Firebase Authentication accomplishes this:

  • Silent APNs notifications: When you sign in a user with their phone number for the first time on a device, Firebase Authentication sends a token to the device using a silent push notification. If your app successfully receives the notification from Firebase, phone number sign-in can proceed.

    For iOS 8.0 and newer, silent notifications do not require explicit user consent and is therefore unaffected by a user declining to receive APNs notifications in the app. Thus, the app does not need to request user permission to receive push notifications when implementing Firebase phone number auth.

  • reCAPTCHA verification: In the event that sending or receiving a silent push notification is not possible, such as when the user has disabled background refresh for your app, or when testing your app on an iOS simulator, Firebase Authentication uses reCAPTCHA verification to complete the phone sign-in flow. The reCAPTCHA challenge can often be completed without the user having to solve anything.

When silent push notifications are properly configured, only a very small percentage of users will experience the reCAPTCHA flow. Nonetheless, you should ensure that phone number sign-in functions correctly whether or not silent push notifications are available.To ensure that both scenarios are working correctly, test your app on a physical iOS device with background app refresh both enabled and disabled. When background app refresh is disabled, you should be able to successfully sign in after completing the reCAPTCHA challenge. You can also test the reCAPTCHA flow by running your app on an iOS simulator, which always uses the reCAPTCHA flow.

Start receiving silent notifications

To enable APNs notifications for use with Firebase Authentication:

  1. In Xcode, enable push notifications for your project.

  2. Upload your APNs authentication key to Firebase. If you don't already have an APNs authentication key, see Configuring APNs with FCM.

    1. Inside your project in the Firebase console, select the gear icon, select Project Settings, and then select the Cloud Messaging tab.

    2. In APNs authentication key under iOS app configuration, click the Upload button.

    3. Browse to the location where you saved your key, select it, and click Open. Add the key ID for the key (available in Certificates, Identifiers & Profiles in the Apple Developer Member Center) and click Upload.

    If you already have an APNs certificate, you can upload the certificate instead.

Set up reCAPTCHA verification

To enable the Firebase SDK to use reCAPTCHA verification:

  1. Add custom URL schemes to your Xcode project:

    1. Open your project configuration: double-click the project name in the left tree view. Select your app from the TARGETS section, then select the Info tab, and expand the URL Types section.

    2. Click the + button, and add a URL scheme for your reversed client ID. To find this value, open the GoogleService-Info.plist configuration file, and look for the REVERSED_CLIENT_ID key. Copy the value of that key, and paste it into the URL Schemes box on the configuration page. Leave the other fields blank.

      When completed, your config should look something similar to the following (but with your application-specific values):

Last updated