Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Firebase Authentication
2.1.
Key Capabilities
2.2.
FirebaseUI Auth
2.3.
Firebase SDK Authentication
3.
Firebase Authentication with Identity Platform
3.1.
Features
3.2.
Usage Limits
3.2.1.
No Cost (Spark)
3.2.2.
Pay as You Go (Blaze)
4.
How it Works
5.
Implementation Paths
5.1.
Using FirebaseUI Auth
5.2.
Using Firebase Authentication SDK
6.
Frequently Asked Questions
6.1.
Does Firebase authentication use JWT?
6.2.
How many OTPs in Firebase are free?
6.3.
Can we create a user in Firebase using the same credentials?
6.4.
How long does the firebase auth session last?
7.
Conclusion
Last Updated: Mar 27, 2024

Firebase Authentication

Introduction

When implementing an online system, it is critical to maintain track of whether the individual using the platform is the person who is supposed to access it or not. One of the most excellent methods to check this is to use a procedure that tests the individual. This process is known as authentication. It can be done in several ways, with SMS, phone, and email verification being the most popular. The related account or contact can ensure that no unauthorised users use this authentication mechanism to access the platform. The majority of apps need the user's identity. When an app has access to a user's identification, it can preserve user data securely in the cloud and provide a consistent, personalised experience across all of the user's devices. To help developers authenticate users for their projects, Firebase Authentication offers backend services, easy SDKs, and ready-made UI frameworks. For authentication, it takes passwords, phone numbers, and well-known federated identity providers like Google, Facebook, and Twitter.

Firebase Authentication

Firebase Authentication works in tandem with other Firebase services. It uses industry standards such as OAuth 2.0 and OpenID Connect to integrate users' bespoke backends easily. We gain access to new capabilities when we upgrade to Firebase Authentication with Identity Platform. Among the other features are multi-factor authentication, blocking functions, user activity and audit logging, SAML and generic OpenID Connect compatibility. It also supports multi-tenancy and enterprise-level support.

Firebase Authentication

Key Capabilities

We can sign users into our Firebase app utilising FirebaseUI as a complete drop-in auth solution. We can also do it by manually integrating one or more sign-in methods into our app using the Firebase Authentication SDK.

  • FirebaseUI Auth
  • Firebase SDK Authentication
  • Firebase Authentication with Identity Platform

FirebaseUI Auth

The Firebase Authentication SDK is built on top of the FirebaseUI library, which offers drop-in UI flows for the project.

  • Drop-in authentication solution: It is the recommended method for adding an entire sign-in system to an app. FirebaseUI provides a drop-in auth solution for signing in users with email addresses, passwords, phone numbers, and popular federated identity providers. Google Sign-In and Facebook Login are further examples. The FirebaseUI Auth component provides best practices for mobile device and website authentication, which can increase sign-in and sign-up conversion for our app. It also handles security-sensitive and error-prone edge cases such as account recovery and linking. FirebaseUI is customisable to match the rest of our app's visual style. Because it is open source, we are not limited in our ability to create the desired user experience.

Firebase SDK Authentication

  • Email and password-based: This authentication method verifies users using their email addresses and passwords. The Firebase Authentication SDK includes methods for creating and managing users who sign in with their email addresses and passwords. Firebase Authentication also handles password reset emails.
  • Federated identity provider integration: This authentication Integrates with federated identity providers to authenticate users. The Firebase Authentication SDK includes methods for signing in with Google, Facebook, Twitter, and GitHub accounts.
  • Phone number authentication: This authentication method verifies users' identities by delivering SMS messages to their phones.
  • Custom authentication system integration: We may connect our app's existing sign-in system to the Firebase Authentication SDK with this authentication. This would also let us receive access to the Firebase Realtime Database and other Firebase services using this type of authentication.
  • Anonymous authentication: This lets us use features that require authentication without requiring users to sign in first by creating temporary anonymous accounts. Suppose the user later chooses to sign up. In that case, we can upgrade the anonymous account to a regular account, so the user can continue where they left off.

Firebase Authentication with Identity Platform

An optional update that expands Firebase Authentication's capabilities is Identity Platform with Firebase Authentication. There is no need for migration for this upgrade. The code for the admin SDK and client SDK will function as before. Additionally, we will have immediate access to SLAs, enterprise-grade support, and improved logging. Multi-factor authentication, blocking features, and support for SAML and OpenID Connect providers may all be added with some extra code.

Features

  • Multi-factor authentication: SMS-based multi-factor authentication adds an extra layer of protection to the app, protecting users' data.
  • Blocking functions: It enables us to execute custom code that alters an app user's registration or sign-in result.
  • SAML and OpenID Connect providers: Support sign-in with SAML (web only) and OpenID Connect service providers that Firebase does not by default support.
  • User activity and audit logging: It enables us to keep track of and monitor end-user and organisational behaviour.
  • Admin activity audit logs in Cloud Logging are automatically enabled when we upgrade our project. On the Authentication Settings page of the Firebase console, we can additionally turn on user activity logging.
  • Multi-tenancy: Within a single project, we can employ tenants to build a variety of distinct user and configuration silos.
  • Enterprise support and SLA: Upgraded projects get access to enterprise-level support and uptime guarantees for Auth services per the Identity Platform Service Level Agreement (SLA).

Usage Limits

Firebase Authentication is subject to new restrictions following an upgrade to Firebase Authentication with Identity Platform.

No Cost (Spark)

For most sign-in providers, projects on the free (Spark) plan now have 3,000 daily active users (DAUs). The number of unique users who sign in within 24 hours determines the daily usage.

No Cost (Spark)

Pay as You Go (Blaze)

The Blaze plan's pricing depends on monthly active users (MAUs), including a free tier of 50,000 users. Anyone who utilises their account during the billing month is considered an active user.

Pay as You Go

How it Works

Before signing the user into the app, we require their authentication credentials. These credentials can be the user's email address and password or an OAuth token from a federated identity provider. After that, these credentials are sent to the Firebase Authentication SDK. After validating those credentials, our backend services will reply to the client.
Once a user has successfully logged in, we can obtain basic profile data about them and manage their access to data held by other Firebase products. The authentication token can also confirm a user's identity in the backend services.

Firebase image

Implementation Paths

Using FirebaseUI Auth

The following steps are to be followed for the implementation of Firebase Authentication using FirebaseUI Auth:

  • Set up the Sign-in options: We need to set up the options we wish to enable, including phone sign-in, email address and password sign-in, and federated identity providers. Set the OAuth redirect URL and carry out any further configurations necessary by the identity provider after enabling them in the Firebase interface. It must be exclusive to our Google Cloud project.
  • Customise Sign-in UI: We may further personalise the sign-in UI by configuring FirebaseUI parameters or forking the source code on GitHub.
  • Use FirebaseUI for Sign-in Flow: Set the sign-in methods we wish to support, import the FirebaseUI library, and start the FirebaseUI sign-in flow.

Using Firebase Authentication SDK

The following steps are to be followed for the implementation of Firebase Authentication using Firebase Authentication SDK:

  • Set up Sign-in methods: We enable them in the Firebase panel and finish any configuration necessary by the federated identity provider. Such as configuring the OAuth redirect URL for any email address, password, or phone number sign-in methods we want to support.
  • Implement UI flows: Create a flow that asks users to enter their email addresses and passwords in order to sign in using their email addresses and passwords. Create a flow that asks users for their phone number and the code from the SMS message they receive for phone number sign-in. Implement the flow required by each provider for federated sign-in.
  • Pass User credentials: Send the Firebase Authentication SDK the user's email address, password, or OAuth token obtained from the federated identity provider.

Frequently Asked Questions

Does Firebase authentication use JWT?

Firebase gives us complete control over authentication by enabling us to employ secure JSON Web Tokens to verify users or devices (JWTs). These tokens are created on the server, sent to the client device, and used to authenticate via the signInWithCustomToken() method.

How many OTPs in Firebase are free?

OTP verification with a phone number from Firebase is cost-free. Ten thousand authentications are allowed every month under Firebase's free plan. However, if we go beyond this amount, we must pay.

Can we create a user in Firebase using the same credentials?

Users can sign into the same account using several authentication providers using the Firebase account linkage. The user can sign into the same account using either of the sign-in providers by connecting their Facebook and Twitter credentials.

How long does the firebase auth session last?

By default, a session expires (times out) following 30 minutes of inactivity from the user. The duration of a session is unrestricted.

Conclusion

The Firebase Authentication service was discussed in this article. It described its benefits, SMS, and other forms of authentication. We also talked about the expenses and methods for implementation. Along with these, the article also covered the essential features of Firebase Authentication. The system's simplicity of use and interaction with other Firebase services are its key benefits. You can learn about Cloud Computing and find our courses on Data Science and machine learning. Do not forget to check out more blogs on GCP to follow.

Thank you image

Explore Coding Ninjas Studio to find more exciting stuff. Happy Coding!

Live masterclass