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?
- You need to create new project from your Firebase Account
- Enable Social Account Integration via Authentication > Sign Method
- Facebook: You need to create Facebook Application .Then you need to add the APP ID and APP Private from Facebook Developer
- Twitter: You need to create Twitter Application .Then you need to add APP ID and APP Private from Twitter panel.
- Download Project Server Configuration
- Go to Project Settings > Service Accounts > Admin SDK configuration snippet
- 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.