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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
56
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
【2026年版】 ベクトル検索とEmbedding最前線
mocobeta
23
7.5k
Multi-Agent並列開発を 安全に回すための技術 / Technology for Safely Multi-Agent Parallel Development
tooppoo
0
130
生成 AI 実践ガイド (概略版) AIガバナンス編
asei
0
190
いまさら聞けない「仕様駆動開発入門」 〜AI活用時代の開発プロセスを考える〜
findy_eventslides
2
200
AIAU_UMEMOGU_ninomiya_slide
ninomiya_ii
0
260
「軸足」は 固定しなくていい - 熱量と強みで描く、しなやかなキャリアの形
kakehashi
PRO
1
260
5分でわかるDuckDB Quack
chanyou0311
2
250
秘密度ラベル初心者が第1歩でつまづかないための「設計・運用」ポイント
seafay
PRO
1
480
AIチャットの改善から見えた、良いAI体験とは / What Constitutes a Good AI Experience: Insights from Improving AI Chat
kubode
0
120
自宅LLMの話
jacopen
1
720
FPC(フレキシブル)基板にZephyr実装してみた。
iotengineer22
0
170
フィジカル版Github Onshapeの紹介
shiba_8ro
0
320
Featured
See All Featured
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
610
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
470
Designing for Performance
lara
611
70k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
330
Are puppies a ranking factor?
jonoalderson
1
3.6k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
370
It's Worth the Effort
3n
188
29k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
210
Raft: Consensus for Rubyists
vanstee
141
7.6k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
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