Firebase Authentication in swift

Updated 2 July 2022

Save

Today, we are going to learn Firebase Authentication(Phone Number authentication.)

Google Firebase provides many services, for example, notification(Firebase messaging), real-time database, analytics, etc.

Firebase authentication provides many authentication methods for instance,

Phone Number authentication is very easy and commonly used when users want to log in or sign in through a Phone Number. firebase sends the 6-digit (One Time Password) to the user’s phone via SMS messaging.

After that, the user has to send type the OTP in the input field in the app then the app has to send this OTP with verification ID to the firebase for verification.

Moreover, Firebase uses reCAPTCHA and silent push notifications to prevent bots from spamming the system

Implement Phone Number Authentication

Step -1

Configure a firebase project with an iOS app. A GoogleService-Info.plist file will be generated, add this file to your swift project.

After that, Add the REVERSED_CLIENT_ID value to the “URL Schemes” field at the Info tab

Step – 2

Now install ‘Firebase/Auth’ pod into your project

Step – 3

Enable Phone number Authentication in the firebase project

Step – 4

Now we have to generate APN’s certificate.

Firebase uses silent push notifications to send tokens to the user’s device to verify the request is coming from a real user, after that import them to the keychain access.

And export the private key. Upload the exported .p12 file to the firebase project

Add the Push Notifications capability to your swift project

Step – 5

Request a OTP with a phone number

This will verify the user’s phone number and the user receives a confirmation SMS with OTP.

Note:- You need to add the country code with the phone number(+91)

Step – 6

In the last step, we need to call PhoneAuthProvider credential method by sending verificationID and OTP in the arguments

After that , we can use this credentails to sign in using Auth.auth().signIn(with: credential) method.

In Conclusion, Phone number authentication is very easy with Firebase

Lastly, If you have any queries or suggestions, you can leave your query/suggestion in the comment section.

For other blogs Please click here

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home