Facebook And LinkedIn Login With Firebase And Xamarin

For folks who do not want to wait here is the link



While I was investigating on various authentication mechanism for one of my pet projects I picked Firebase for some of my basic needs. Firebase is a mobile app development framework from Google and provides various services and seamless integrations with the Google cloud.

On the other hand, I am not good at Java -- I  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.

So, to start with 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." Jsonfolks who do not know what it is you have lot to catch up on. Replace the Json file on 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 here.

FirebaseAuthQuickStart sample already has google sign in implemented with firebase.

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

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 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 has logged in or not and handle the Facebook access token. Just like the following a simple example, once an authentication credential is created it will make an entry to firebase table.

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 sis upposed 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,