Contact Info
43 Street 3, Hiep Binh Chanh Ward
Thu Duc District, HCM City, Vietnam
linh@zodinet.com
+84 908 543479
Support

How should we call you?

Follow Us

Zodinet Technology Co.,Ltd

g

Integrate Firebase Authenticate with Loopback

I. What is Firebase?

Firebase is a platform that will allow you to develop android apps quickly. It offers a number of different services built-in, including some basic analytics.

It includes a lot of helpful services for developers:

  • Authentication
  • Realtime database
  • Storage
  • Hosting

II. How to setup Firebase?

  1. You need to create new project from your Firebase Account
  2. Enable Social Account Integration via Authentication > Sign Method
    1. Facebook: You need to create Facebook Application .Then you need to add the APP ID and APP Private from Facebook Developer
    2. Google
    3. Twitter: You need to create Twitter Application .Then you need to add APP ID and APP Private from Twitter panel.
  3. Download Project Server Configuration
    1. Go to Project Settings > Service Accounts > Admin SDK configuration snippet
    2. Go to Project Settings > Service Accounts > Generate New Private Key

III. Setup Loopback & Firebase Intergration

Install NodeJS Firebase package

npm install --save firebase-admin

From private key in previous step, Let’s save your serviceAccountKey.json into server/serviceAccountKey.json.

Implement your Remote Method handler, the client (mobile or web client) will post into server a request with token that was used from Firebase’s client. Then you can use the token to parse and verify the information with Firebase from server side.

'use strict'; 
var admin = require('firebase-admin'); 
var serviceAccount = require('../../server/serviceAccountKey.json');
admin.initializeApp({ type: "service_account", credential:admin.credential.cert(serviceAccount) }); 
module.exports = function (Account) { 
Account.loginFirebase = function(token,callback){ 
    admin.auth().verifyIdToken(token).then(function (decodedToken) { 
    console.log(decodedToken); // Your logic here }); 
    } 
}

Then everything was finished, you can use decoded

Token to parse email and account information with your logic.


Comments

  • Esteban

    January 11, 2020

    CAN BE USED AS PART OF ACL? DO YOU HAVE A GIT SAMPLE PROJECT?

Sorry, the comment form is closed at this time.