Click here to Skip to main content
13,664,842 members
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 11 Sep 2017
Licenced CPOL

Facebook & LinkedIn Login with Firebase and Xamarin

, 12 Sep 2017
Rate this:
Please Sign up or sign in to vote.
Facebook & LinkedIn login with Firebase and Xamarin


Firebase is a mobile app development framework from Google and provides various services and seamless integration with google Cloud. Xamarin has provided a good example of integration of Firebase with Google IDP.

I will show how to extend the same with Facebook and even with LinkedIn. Firebase has few major authentication providers which are managed identity providers through firebase but so far Instagram, LinkedIn have not been included which are unmanaged identity providers and can be maintained by firebase with the use of custom firebase token.

Find the source code in


While I was investigating on various authentication mechanisms for one of my pet projects, I picked Firebase for some of my basic needs.

On the other hand, I am not good at Java and do not even want to think about it so Xamarin is a wonderful alternative for the developer who has already been infected by C# (notice I used the word “infected”) as well as Visual Studio 2017 (any version of studios -hands down -most beautiful & efficient IDE of the galaxy).

So, my objective is very simple - using Microsoft development products (Visual Studio/VSTS/C#/Xamarin) to develop a product and never using any additional Microsoft services (or limiting them to an insignificant amount) like Azure/Cognitive-API/API management etc. – no matter how appealing or easy to implement they are, whenever I need any additional services, I look for other alternatives like for the security and user management of my app I chose firebase.

Using the Code

So, to start with, you must have an account with firebase - it’s best to have an account with Google Cloud to get access to google cloud control and then to firebase.

Go ahead and create/import your Android app project and get “google-services.json” folks who do not know what it is you have lot to catch. Replace the Json file of your own!

My project has a sample “google-services.json” file copied from FirebaseAuthQuickStart example - have a look at this URL to have the basic clear

FirebaseAuthQuickStart sample already has Google sign in implemented with firebase.

Firebase has few major authentication providers which are managed identity providers through firebase but so far Instagram, LinkedIn has not been included which are unmanaged identity providers and can be maintained by firebase with the use of custom firebase token.

When you have decided to use Firebase to manage app users and broker authentication, it’s better if we can manage unmanaged authentication providers too with firebase.

The source code will provide a best practice to follow while implementing Facebook sign in with firebase -implemented with Xamarin Facebook SDK and Firebase SDK. As well as a way to maintain LinkedIn users with Firebase with xamarin.auth and Firebase SDK.

Both of the implementations have different flavors for managed authentication providers like Google and Facebook respective auth SDK will handle the heavy lifting- like in the case of Facebook -specific activity should implement IFacebookCallback (Xamarin.Facebook) and IOnCompleteListener (Android.Gms.Tasks) and then firebase SDK will do the rest it has to use “AuthStateChanged” to check if a user logged in or not and handle the Facebook access token just like the following simple example once an authentication credential is created, it will make an entry to firebase table.

// handleFacebookAccessToken

private void handleFacebookAccessToken(AccessToken accessToken)
    AuthCredential credential = FacebookAuthProvider.GetCredential(accessToken.Token);
    mAuth.SignInWithCredential(credential).AddOnCompleteListener(this, this);

But in case of LinkedIn, its simple oAuth2 implementation complexity lies in creating the custom firebase token.

I have kept the token creation process in a separate shared project with a single class “Firebasetoken” - make sure you have shared project template installed in your Visual Studio.

Remember this is just an example of how to do it – do not include this code or implement this at client side. It involves a service account and other secrets which are potential security variabilities - this is supposed to be implemented at server end. Following are the steps to follow:

  • In the Firebase console, click the setting icon which is top left, next to the project name, and click 'Permissions'.

  • At the IAM and Admin page, click 'Service Accounts' on the left
  • Click 'Create Service Account' at the top, enter a 'Service Account Name', select 'Project->Editor' in the Role selection, tick the 'Furnish a new private key' checkbox and select JSON.
  • Click 'Create' and download the Service Account JSON file and keep it safe.
  • Open the Service Account JSON file in a suitable text editor and put the values into Firebasetoken class

Remember to include BouncyCastle reference. In fact, here is a screenshot of the references you require to build this project correctly:

Find the source code in github - you are free to download and extend.

Here are a few screenshots of how it will look for Android:


  • 12th September, 2017: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

amartya mandal
United States United States
11+ yrs. of Architecture, Application Development and implementation experience in Microsoft Technologies.Involved in various stages of System Development Life Cycle including Analysis, Design, Development, and Maintenance.A technology enthusiast with proven ability to direct a wide range of technology & business critical projects and complex deployments.

Windows Azure Experience-
5+ years of experience on designing and implementing windows cloud (Azure) based applications & solutions. Defined cloud adoption road maps and runways for various clients, help to initialize adoption strategies based on existing governance, security & compliance policies.

Hands On - Azure IaaS, PaaS, storage, network and database.
Azure PaaS services like web sites, web/worker roles, SQL. Azure database, storage, service bus. Understanding of security requirements for cloud. Highly availability, DR solutions in Azure. Assessing applications for cloud adoption. Azure AD, AD Connect Claim based authentication with ACS.

High Performance Computing-HPC
Hands on experience of development and setting up HPC grid & cluster on azure as well as on premise to cloud hybrid mode with Microsoft HPC pack 2012 R2.
Provides consulting support to clients on HPC resources, which can include porting, palatalization, tuning, using software libraries, storage management, and optimization.
Collaborates with systems staff on the design, configuring, and support of a heterogeneous mix of multi-core compute clusters. Manages diagnosis and correction of applications issues causing poor performance; develops benchmarks.
Maintains close learning and working relationships with industry specialists, vendors, communities, working groups, etc. Collaborates with information technology staff to improve the performance of existing HPC resources.

You may also be interested in...


Comments and Discussions

Questionprofile picture Pin
agaha0811-Jan-18 12:20
memberagaha0811-Jan-18 12:20 
QuestionWhy firebase is required to login by facebook or linkedin Pin
Mou_kol12-Sep-17 22:52
memberMou_kol12-Sep-17 22:52 
GeneralRe: Why firebase is required to login by facebook or linkedin Pin
amartyaa13-Sep-17 1:53
memberamartyaa13-Sep-17 1:53 
Questionthoughts Pin
Nelek12-Sep-17 20:23
protectorNelek12-Sep-17 20:23 
PraiseRe: thoughts Pin
amartyaa13-Sep-17 1:33
memberamartyaa13-Sep-17 1:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180810.1 | Last Updated 12 Sep 2017
Article Copyright 2017 by amartya mandal
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid