Firebase: Facebook Sign-In Authentication FIREBASE
- Firebase Tutorial
- Features of Firebase
- Android Studio
- Firebase - Environment Setup (with android studio)
- Firebase Assistance - Android Studio
- Firebase Authentication
- Firebase: Google Sign-In Authentication
- Firebase: Facebook Sign-In Authentication
- Firebase: Sign-In Authentication Using Phone Number
- Firebase UI: Authentication using email/password
- Firebase UI: Authentication using email link
- Firebase SDK: Authentication using email/password
- Firebase SDK: Authentication using the email link
- Firebase: Realtime Database
- Firebase: Real-time database setup and configuration
- Firebase: Data Organization in Real-time Database
- Firebase: Realtime Database Reading and Writing
- Firebase: Realtime Database Update and Delete
Firebase: Facebook Sign-In Authentication
Facebook sign-in authentication is quite typical to implement. The users can authenticate with Firebase using their Facebook accounts by integrating Facebook logging into our application.
13 steps to implement Facebook sign-in authentication. with image examples.
Let's create an Android and Firebase project, and then add the Firebase project with the application. Also, add SHA-1 and SHA-256 keys in the Firebase console. After that, add all the required dependencies, i.e., firebase-core, firebase-auth, and plugin in 'app.build.gradle' file and classpath in 'build.gradle' file.
And let's add the Facebook login dependency in the 'app.build.gradle' file'.
Now, we have to create an application on 'Facebook for developer' website. For creating a request, you have a Facebook account. Login with the Facebook account. Then, go to the Facebook developer site with the help of the following link:
Once your developer account is logged in, then click on Docs to move on to the document page.
In the document page, scroll down and click on the Facebook login. And from the Facebook login page, select Android to move an android page from there, now select an app or create a new app.
If we are not a developer, then we have to register as a developer by clicking on Register.
Click on next to register as a Facebook developer.
After clicking on the next, a new screen will be visible from where select the developer option.
After selecting the developer, the welcome page will be opened.
From the welcome page, select Create First App and give it a name for display and contact email and click on Create App ID.
Perform a security check.
Now, go to Home->Doc->facebook login->android and select the app which we have created before and copied the App ID.
Now, move to the 'string.xml' file of Android Studio and create two strings, i.e., facebook_app_id and fb_login_protocol_scheme. For facebook_app_id, and paste the app id, which we have copied before, and for fb_login_protocol_scheme, we will add prefix FB in our app_id and use it as a protocol string.
You need to add permission for the Internet to our Android Manifest file.
Now add the Metadata. For this, and go to the Facebook developer site and copy the code of step 5.
After copying the code, now paste it in Manifest files after the MainActivity code.
Now, associate our package name and default class with our app. So add the package name and default activity class name in the developer site.
In the next step, add the Development Key Hashes for our app. For this, you need OpenSSL open library. If you don't have this library, then we first have to download the OpenSSL library. And after that we will execute the following command in the command prompt:
keytool -export cert -alias androiddebugkey - Keystore "C:\Users\USERNAME\.android\debug.keystore" | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" sha1 -binary | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" base64
Now copy this key and paste it in the developer site's Key Hashes.
Now you have to enable single sign-on for our app in Facebook developer sites.
Now, go to the basic setting of our app on the Facebook developer site. And from here, we have to copy the App Secret that will be used in Firebase console.
The App Secret, which we have copied from the Facebook developer site, will be pasted in the firebase console. When you enable the Facebook sign-in method, it will ask for the App ID and App Secret and provide OAuth redirect URL, which will be added to our app on the Facebook developer site.
Now, let's go to the Facebook setting page. Here, we will add the OAuth redirect URL to Facebook login settings.
Now create a Facebook login button from the SDK. It is a UI element that wraps functionality available in the login manager.
Now modify our MainActivity.java file to perform the authentication using Facebook in the following way: