Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Bringing Firebase Admin SDK to your server - De...
Search
Henry Lim
October 27, 2018
Technology
65
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Bringing Firebase Admin SDK to your server - DevFest x BizFest Cebu 2018
Henry Lim
October 27, 2018
More Decks by Henry Lim
See All by Henry Lim
Building Malaysia Vaccine Tracker Twitter Bot
limhenry
0
57
What's New in Web 2020
limhenry
0
650
Building a Better Website with Chrome DevTools
limhenry
0
190
Bringing your PWA to the Google Play Store with Trusted Web Activities
limhenry
0
1.2k
Building a better web for everyone - DevFest George Town 2018
limhenry
0
47
Building a better web for everyone - DevFest x BizFest Cebu 2018 / DevFest Bangkok 2018
limhenry
0
140
Bringing Firebase Admin SDK to your server - Firebase Dev Day Thailand 2018
limhenry
0
210
The Modern Web: State of the Union (I/O Extended '18 Kuala Lumpur)
limhenry
0
180
Building a better web with Web Components and Polymer 2.0
limhenry
0
59
Other Decks in Technology
See All in Technology
MySQL & MySQL HeatWave Report - June 2026
freshdaz
0
240
スタートアップにAmazon EKSは早すぎる? マルチプロダクト戦略を加速する Platform Engineeringの実践 / Is Amazon EKS Too Soon for Startups? Practical Platform Engineering to Accelerate a Multi-Product Strategy
elmodev09
1
1.9k
BPaaSで進むAIオペレーションの現在地 AI実装が効く領域とスケーラビリティの選定と実装
kentarofujii
0
230
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.2k
攻撃者がいなくてもAIエージェントはインシデントを起こす
nomizone
0
170
秘密度ラベル初心者が第1歩でつまづかないための「設計・運用」ポイント
seafay
PRO
1
530
【FinOps】データドリブンな意思決定を目指して
z63d
3
540
フルAIで個人開発して学んだあれこれ / yuruai vol.1
isaoshimizu
0
160
Text-to-SQLをAgentCoreで実現し、生成されるSQLの精度を定量的に評価する
yakumo
2
210
認証認可だけじゃない! ID管理の構成要素と ライフサイクルを意識しよう
ritou
1
380
トークン最適化のためのユーザーストーリー分析 / User Story Analysis for Token Optimization
oomatomo
0
150
product engineering with qa
nealle
0
100
Featured
See All Featured
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
350
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
Bash Introduction
62gerente
615
220k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
450
YesSQL, Process and Tooling at Scale
rocio
174
15k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
870
Test your architecture with Archunit
thirion
1
2.3k
Evolving SEO for Evolving Search Engines
ryanjones
0
230
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
400
Transcript
Bringing Firebase Admin SDK to your server Henry Lim @henrylim96
Kamusta! Ako diay si Henry #DevFest18
#DevFest18
#DevFest18
#DevFest18 Firebase by Platform • Android • iOS • Web
• Flutter • And more ...
#DevFest18
#DevFest18 Firebase Admin SDK
#DevFest18 Firebase has got you covered Firebase provides a suite
of SDKs, called Admin SDKs, for developing back-end software that interact with Firebase.
#DevFest18 Firebase Admin SDKs Access Firebase from … • Servers
owned or managed by app developers • Cloud IaaS and PaaS environments • Serverless platforms
#DevFest18 What can you do with Firebase Admin SDK
Firebase Admin SDK Features Feature Node.js Java Python Go C#
Custom Token Minting ✓ ✓ ✓ ✓ ✓ ID Token Verification ✓ ✓ ✓ ✓ ✓ User Management ✓ ✓ ✓ ✓ Control Access With Custom Claims ✓ ✓ ✓ ✓ Refresh Token Revocation ✓ ✓ ✓ ✓ Import Users ✓ ✓ ✓ ✓ Session Cookie Management ✓ ✓ ✓ Realtime Database ✓ ✓ ✓ ✓ Cloud Messaging ✓ ✓ ✓ ✓ Manage Topic Subscriptions ✓ ✓ ✓ ✓ Cloud Storage ✓ ✓ ✓ ✓ Cloud Firestore ✓ ✓ ✓ ✓
#DevFest18
#DevFest18 Introducing Fire Lechon
#DevFest18
#DevFest18
#DevFest18
#DevFest18 Adding the Firebase Admin SDK
// Download the SDK (NPM) npm install firebase-admin --save
#DevFest18
#DevFest18 Initialize the Firebase Admin SDK
// Initialize the SDK const admin = require('firebase-admin'); const
serviceAccount = require('path/to/ serviceAccountKey.json'); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), databaseURL: 'https://<DATABASE_NAME>.firebaseio.com' }); #DevFest18
#DevFest18
#DevFest18
// Initialize the SDK // Cloud Functions for Firebase
const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); #DevFest18
#DevFest18 A custom permissions model We want to define two
classes of users - admin and regular users.
#DevFest18 Control Access with Custom Claims and Security Rules
// Firebase Realtime Database Rules { "rules": { "items":
{ ".read": true, ".write": "auth.token.admin === true", } } } #DevFest18
#DevFest18
document.querySelector('.form').addEventListener('submit', event => { event.preventDefault(); database.ref('admin').push(document.querySelector('.form #email').value) .then(() => {
alert('Added successfully!'); window.location.replace('/'); }) .catch(error => { alert(error); }) }); #DevFest18
exports.newAdmin = functions.database.ref(`admin/{email}`) .onCreate((snapshot, context) => { const email =
context.params.email; admin.auth().getUserByEmail(email) .then(userRecord => { return userRecord.uid; }) .then(uid => { return admin.auth().setCustomUserClaims(uid, {admin: true}); }) .catch(error => { console.log(error); }) }) #DevFest18
exports.newAdmin = functions.database.ref(`admin/{email}`) .onCreate((snapshot, context) => { const email =
context.params.email; admin.auth().getUserByEmail(email) .then(userRecord => { return userRecord.uid; }) .then(uid => { return admin.auth().setCustomUserClaims(uid, {admin: true}); }) .catch(error => { console.log(error); }) }) #DevFest18
// Firebase Realtime Database Rules { "rules": { "items":
{ ".read": true, ".write": "auth.token.admin === true", } } } #DevFest18
#DevFest18
#DevFest18 Send Messages to Topics
#DevFest18
var messaging = firebase.messaging(); var database = firebase.database(); if
('serviceWorker' in navigator) { window.addEventListener('load', () => { navigator.serviceWorker.register('/firebase-messaging-sw.js') .then((registration) => { messaging.useServiceWorker(registration); }) .then(() => { return messaging.requestPermission(); }) .then(() => { return messaging.getToken(); }) .then((token) => { database.ref('notification/' + token).set(true); }) .catch((err) => { console.log('ServiceWorker registration failed: ', err); }); }); #DevFest18
var messaging = firebase.messaging(); var database = firebase.database(); if
('serviceWorker' in navigator) { window.addEventListener('load', () => { navigator.serviceWorker.register('/firebase-messaging-sw.js') .then((registration) => { messaging.useServiceWorker(registration); }) .then(() => { return messaging.requestPermission(); }) .then(() => { return messaging.getToken(); }) .then((token) => { database.ref('notification/' + token).set(true); }) .catch((err) => { console.log('ServiceWorker registration failed: ', err); }); }); #DevFest18
exports.sendNotification = functions.database.ref(`items/{itemId}`) .onCreate((snapshot, context) => { const data =
snapshot.val(); const msg = admin.messaging.Message = { topic: 'new-restaurant', notification: { title: 'New Restaurant in FireLechon’, body: `We just added "${data.name}" to our collection. Enjoy!` } } return admin.messaging().send(msg) .then((resp) => { return resp; }) .catch(() => {}) }) #DevFest18
exports.sendNotification = functions.database.ref(`items/{itemId}`) .onCreate((snapshot, context) => { const data =
snapshot.val(); const msg = admin.messaging.Message = { topic: 'new-restaurant', notification: { title: 'New Restaurant in FireLechon’, body: `We just added "${data.name}" to our collection. Enjoy!` } } return admin.messaging().send(msg) .then((resp) => { return resp; }) .catch(() => {}) }) #DevFest18
#DevFest18
#DevFest18 What else you can do with Firebase Admin SDK
#DevFest18
#DevFest18
#DevFest18
Thank You Henry Lim @henrylim96