Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Bringing Firebase Admin SDK to your server - Fi...
Search
Henry Lim
October 07, 2018
Technology
230
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
72
What's New in Web 2020
limhenry
0
670
Building a Better Website with Chrome DevTools
limhenry
0
220
Bringing your PWA to the Google Play Store with Trusted Web Activities
limhenry
0
1.3k
Building a better web for everyone - DevFest George Town 2018
limhenry
0
64
Building a better web for everyone - DevFest x BizFest Cebu 2018 / DevFest Bangkok 2018
limhenry
0
150
Bringing Firebase Admin SDK to your server - DevFest x BizFest Cebu 2018
limhenry
0
82
The Modern Web: State of the Union (I/O Extended '18 Kuala Lumpur)
limhenry
0
190
Building a better web with Web Components and Polymer 2.0
limhenry
0
72
Other Decks in Technology
See All in Technology
国際カードブランドルール変更に伴うクレジットカード決済取引仕様変更について
k1style
0
150
シンプルな設定ファイルで実現する AWS IAM Identity Center の ユーザー管理Terraformフレームワークを公開しました / Simplifying AWS IAM Identity Center User Management: An Open-Source Terraform Framework
yamaguchitk333
0
130
Tofu-Controller lightning talk @ Containerday 2026
gionn
0
180
こんにちは!SORACOM です & IoT とは【SORACOM UG 東北 in 八戸】
soracom
PRO
0
170
FinOps Agentが生んだ技術負債:コスト自動調査の落とし穴と解消までの道のり
oasis1994liveforever
3
250
AWS DevOps Agentはどこまで任せられるか 〜機能の現在地と、機能拡張の実践〜
nyankotaro
0
120
ポケモン対戦を自動で記録して振り返ろう
fufufukakaka
0
270
React改造してみた
tsukina_7mochi
0
150
CSS2026:OWS研究会・招待講演「世界観を、実装する」
atsush1_sada
2
210
OptunaHub: ブラックボックス最適化のためのプラットフォーム
pfn
PRO
0
150
AI × アーキテクト 第1・2章|生成AIの課題とアーキテクトの素養
daidaidai
1
230
Persisting Massive Data with Rails ~Designing for 60 billion rows, and fighting the bottlenecks~ Railsで挑む大量データ永続化 〜600億件を永続化するための設計とボトルネックとの戦い〜
occhi
0
780
Featured
See All Featured
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Evolving SEO for Evolving Search Engines
ryanjones
0
330
A Soul's Torment
seathinner
8
3.8k
Skip the Path - Find Your Career Trail
mkilby
1
260
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
630
Game over? The fight for quality and originality in the time of robots
wayneb77
1
310
GraphQLとの向き合い方2022年版
quramy
50
15k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
950
Thoughts on Productivity
jonyablonski
76
5.4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
720
Optimizing for Happiness
mojombo
378
71k
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