In this project, the implementation of the following Firebase services is available
Getting started with Firebase on Android
Providers | Description |
---|---|
Email/password
In this method we can also authenticate without a password, but for that we need a dynamic link. To our happiness, Firebase also offers this service for free. In the side menu we have Dynamic Link. Create a link: Then on the Authentication / Sign-in method tab, authorize the domain you just created: In the Firebase console, open the Auth section. And of course don't forget to activate the Sign-in method in Firebase: |
|
Smartphone
When we want to authenticate a user using a phone number, we need to define SHA1 in the Firebase panel: In this case we will use the application test sha1 in Android Studio: In the Firebase console, open the Auth section. And of course don't forget to activate the Sign-in method in Firebase: we need google-services.json at our app's app level: |
|
Google
When we want to authenticate a user using Google, we need to create consent screen in: https://console.cloud.google.com/apis/credentials/consent?project=project_Id And of course we need to define SHA1 in the Firebase panel as we have done above When we want to authenticate a user using Google, we need to define SHA1 in the Firebase panel as we have done above: In this case we will use the application test sha1 in Android Studio: We need our OAuth 2.0 client IDs: https://console.cloud.google.com/apis/credentials/oauthclient we need google-services.json at our app's app level: In the Firebase console, open the Auth section. And of course don't forget to activate the Sign-in method in Firebase: If you haven't yet specified your app's SHA-1 fingerprint, do so now we need to define SHA1 in the Firebase panel as we have done above: In this case we will use the application test sha1 in Android Studio: |
|
Play Games
Before starting, in order to use the Play Games authentication method, we must have a google play developer account. Apps/PublishWe don't need to publish a game to test this method, just create one on the google play store. Create an app in the store and define it as a game. Now in Google Play game-related service settings. Yes, my game already uses Google APIs.
Select the same Google Cloud Project. And click USE, ready, now you can continue the configuration. When we want to authenticate a user using Play Games, we need to create consent screen in: https://console.cloud.google.com/apis/credentials/consent?project=project_Id And of course we need to define SHA1 in the Firebase panel as we have done above When we want to authenticate a user using Play Games, we need to define SHA1 in the Firebase panel as we have done above: In this case we will use the application test sha1 in Android Studio: We need our OAuth 2.0 client IDs: https://console.cloud.google.com/apis/credentials/oauthclient we need google-services.json at our app's app level: In the Firebase console, open the Auth section. And of course don't forget to activate the Sign-in method in Firebase: |
|
Facebook
Create an app on Developer Facebook, write down the app ID and complete the setup steps Developer FacebookAfter choosing the type of application that should be Android, go to part 3 and define the package name and the deep link and save, in our case it looks like this: click Use this package name. And continue 4. Add your development and launch key hashes You will need the following: Certificate and key management tool (keytool) from the Java Development Kit openssl-for-windowsopenssl library for Windows from Google Google Code ArchiveTo generate a development key hash, run the following command at a command prompt in the SDK for Java folder: After extract folder in C:/, go inside your jdk/bin folder, open CMD type cd C:\Program Files\Java\jdk1.8.0_144\bin keytool -exportcert -alias androiddebugkey -keystore "C:\Users\computerName\.android\debug.keystore" | "C:\openssl\bin\openssl" sha1 -binary | "C:\openssl\bin\openssl" base64 To find the debug.keystore.Go to drive C:\Users\computerName\.android Keystore name: "debug.keystore" Keystore password: "android" Key alias: "androiddebugkey" Key password: "android" Hashes of keys set Hash Save and continue In your Facebook dev panel settings/basic/ get the application ID and the Application Secret Key In the Firebase console, open the Auth section. In Facebook Login providers, we will need the application ID and the Application Secret Key and we’ll put the OAuth redirect URI to your Facebook app configuration. know moreand In your Facebook dev panel fb-login/settings/ Client OAuth settings set your OAuth redirect URI that you got on firebase You can test using test users or only with your administrator account If you haven't yet specified your app's SHA-1 fingerprint, do so now we need to define SHA1 in the Firebase panel as we have done above: In this case we will use the application test sha1 in Android Studio: |
|
Twitter
In the Firebase console, open the Auth section. and activate the Twitter login method, which will ask for two keys that we will get next from the Twitter developer panel, note the url provided by Firebase that we will use on Twitter Log in to your account and create a project, to add your callback URL to your Twitter application configuration and get both keys requested in Firebase Developer Twitterafter creating your application you will see a screen like this: find Authentication settings click on Keys and tokens select your keys and use in Firebase in the requested fields If you haven't yet specified your app's SHA-1 fingerprint, do so now we need to define SHA1 in the Firebase panel as we have done above: In this case we will use the application test sha1 in Android Studio: |
|
Github
In the Firebase console, open the Auth section. and activate the Github login method, which will ask for two keys that we will get next from the Github developer panel, note the url provided by Firebase that we will use on Github Log in to your Github account go to settings, to create an OAuth application after creating the application scroll down the page until you get to Identifying and authorizing users and set User authorization callback URL | Webhook URL that you got in Firebase and define the other mandatory parameters as you wish now go to Generate a new client secret, and get both keys that we will put in Firebase If you haven't yet specified your app's SHA-1 fingerprint, do so now we need to define SHA1 in the Firebase panel as we have done above: In this case we will use the application test sha1 in Android Studio: |
|
Yahoo
In the Firebase console, open the Auth section. On the Sign in method tab, enable the Yahoo provider. Add the Client ID and Client Secret from that provider's developer console to the provider configuration: note the url provided by Firebase that we will use on Yahoo In the Yahoo console, create app. Be sure to select the two OpenID Connect API permissions: profile and email When registering apps with these providers, be sure to register the url provided by Firebase domain for your project as the redirect domain for your app After creating the application, take the keys and place them in Firebase If you haven't yet specified your app's SHA-1 fingerprint, do so now we need to define SHA1 in the Firebase panel as we have done above: In this case we will use the application test sha1 in Android Studio: |
|
Microsoft
In the Firebase console, open the Auth section. On the Sign in method tab, enable the Microsoft provider. Add the Client ID and Client Secret from that provider's developer console to the provider configuration: note the url provided by Firebase that we will use on Microsoft In the Microsoft console, follow those steps to create an app to create app select Registers of application Fill in the requested fields and use your callback URL that you got in Firebase now write down the application ID (client) and let's create our Application Secret. Fill in the requested fields. write down the application secret now, you will not be able to see it again. now just put the application ID and the secret on the Sign Microsoft provider in Firebase |
|
Anonymous |
In the Firebase console, open the Cloud Firestore section.
and create a database
Enabling Cloud Firestore will prevent you from using Cloud Datastore in this project, especially in the application associated with App Engine
In the Firebase console, open the Realtime Database section.
and create a database
In the Firebase console, open the Storage section.
and copy path to use in app
In test mode enable the rules to read and write to Storage
The rules should only be like this in test mode, in production mode you must enable some type of authentication to protect data
We can use hosting for several purposes. In this case, we will use hosting and functions to create an end point API.
Download the hosting-android folder and follow the steps
In this step we will use nodeJS to create our API end point
Download and install NodeJS
Follow the steps in this documentation and watch the video if you still have questions
Install Firebase CLI if you haven't already
Consultation material on the Firebase CLI
Open the CMD command prompt and enter the functions folder.
Enter the command firebase init functions choose the project and DO NOT overwrite index.js and install NODE dependencies
Now install the express module
Enter the command npm i express
Okay, take the test to see if everything is correct
Enter the commandcd.. to access the hosting folder
Enter the commandfirebase serve --only functions,hosting
if everything went as expected we have a local server running on port 5000
You can now finish the server and deploy the role
Enter the command firebase deploy
In this model we will call a function of Cloud functions from the application
Call functions from your application
We will perform a function in two ways
A simple call that will return the current date
An advanced call, where we will pass data to the function to execute a currency conversion API
Download the functions-android folder and follow the steps
In this step we will use nodeJS to create a function end point
Download and install NodeJS
Install Firebase CLI if you haven't already
Consultation material on the Firebase CLI
Access functions-android folder through the CMD command prompt
Enter the command firebase init functions choose the project and DO NOT overwrite index.js and install NODE dependencies
Access the functions folder
Now install the get-json module
Enter the command npm i get-json
if everything went as expected you can deploy the role
Enter the command firebase deploy
To use Firebase Cloud Messaging, we will again rely on Cloud Functions.
Download the cloud_message-android folder and follow the steps
We will need firebase-admin to send notifications using Firebase Functions, for that we will need the credentials of one of a service account linked to the chosen project.
To obtain a credential linked to a project, follow the steps.
In the Firebase console choose the project, then Project overview, project settings, service accounts, click on Google Cloud Platform service accounts.
Now in the google cloud console, access the Firebase Admin SDK Service Agent.
Click on add key, create new JSON type key, the download is done automatically.
This file is secret, put it in the functions folder of the cloud_message-android folder.