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 - Fi...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Henry Lim
October 07, 2018
Technology
210
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Bringing Firebase Admin SDK to your server - Firebase Dev Day Thailand 2018
Henry Lim
October 07, 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 - DevFest x BizFest Cebu 2018
limhenry
0
65
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
Zenoh on Zephyr on LiteX
takasehideki
2
110
4人目のSREはAgent
tanimuyk
0
120
When Platform Engineering Meets GenAI
sucitw
0
170
アジャイルな経理と Claude Code と経営の未来
kawaguti
PRO
3
190
AIに障害切り分けを全部やってもらった。 。 。 。
estie
0
100
AI-DLCを “そのまま導入しなかった”話 ~組織に合わせてアジャストした 私たちの実践共有~
hiroramos4
PRO
1
420
10年間のブログ発信を振り返って見えたWebアプリケーションエンジニアとしての軌跡
stefafafan
0
180
[AWS Summit Japan 2026]迷っているあなたへ_小さな一歩が、やがて自分を助けてくれる
sh_fk2
2
400
あなたの知らないPDFのアクセシビリティ
lycorptech_jp
PRO
0
240
SONiC Scale-Up Working Group から探る Scale-UpやUltraEthernet機能の実装方法
ebiken
PRO
2
480
新しいUbuntu/GNOMEが使いたいからXからWaylandへ移行頑張ってるの巻 2026-06-20
nobutomurata
0
160
サイバーエージェントにおけるAI推進戦略と変革への取り組み
shotatsuge
0
530
Featured
See All Featured
Become a Pro
speakerdeck
PRO
31
6k
Evolving SEO for Evolving Search Engines
ryanjones
0
220
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1.1k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
260
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Designing for Timeless Needs
cassininazir
1
260
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
370
How GitHub (no longer) Works
holman
316
150k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
400
Transcript
October 7th, 2018 at Glowfish Sathorn Bringing Firebase Admin SDK
to your server Henry Lim @henrylim96
#FirebaseDevDay สวัสดี ครับ, ผมชื่อ เฮนรี่ ลิม
#FirebaseDevDay
None
#FirebaseDevDay Firebase by Platform • Android • iOS • Web
• Flutter • And more ...
None
#FirebaseDevDay Firebase Admin SDK
#FirebaseDevDay Firebase has got you covered Firebase provides a suite
of SDKs, called Admin SDKs, for developing back-end software that interact with Firebase.
#FirebaseDevDay Firebase Admin SDKs Access Firebase from … • Servers
owned or managed by app developers • Cloud IaaS and PaaS environments • Serverless platforms
#FirebaseDevDay 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 ✓ ✓ ✓ ✓
None
#FirebaseDevDay Introducing Fire Tomyam firetomyam.firebaseapp.com
#FirebaseDevDay
#FirebaseDevDay
#FirebaseDevDay
#FirebaseDevDay Add the Firebase Admin SDK
// Download the SDK (NPM) npm install firebase-admin --save
#FirebaseDevDay 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' });
None
#FirebaseDevDay
// Initialize the SDK // Cloud Functions for Firebase const
functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase);
#FirebaseDevDay A custom permissions model We want to define two
classes of users - admin and regular users.
#FirebaseDevDay Control Access with Custom Claims and Security Rules
// Firebase Realtime Database Rules { "rules": { "items": {
".read": true, ".write": "auth.token.admin === true", } } }
#FirebaseDevDay
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); }) });
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); }) })
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); }) })
// Firebase Realtime Database Rules { "rules": { "items": {
".read": true, ".write": "auth.token.admin === true", } } }
#FirebaseDevDay
#FirebaseDevDay Send Messages to Topics
#FirebaseDevDay
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); }); }); };
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); }); }); };
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 FireTomyam', body: `We just added "${data.name}" to our collection. Enjoy!` } } return admin.messaging().send(msg) .then((resp) => { return resp; }) .catch(() => {}) })
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 FireTomyam', body: `We just added "${data.name}" to our collection. Enjoy!` } } return admin.messaging().send(msg) .then((resp) => { return resp; }) .catch(() => {}) })
#FirebaseDevDay
#FirebaseDevDay What else you can do with Firebase Admin SDK
#FirebaseDevDay
#FirebaseDevDay
Thank You! #FirebaseDevDay Helpful resources fb.com/FirebaseThailand fb.com/groups/FirebaseDevTH medium.com/FirebaseThailand Henry Lim
@henrylim96