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
小さいから、全部わかる。— 常駐AI "xangi" のすすめ
sugupoko
0
190
Terraform 101 (初心者向け) 資料
shuadachi
0
120
Amazon Redshift zero-ETL 統合を活用した軽量なマルチプロダクトデータ可視化基盤 / Lightweight Multi-Product Data Visualization with Amazon Redshift Zero-ETL
kaminashi
0
130
コミュニティの有益性 ~JAWS Days 2026 での体験を通して~ / The Benefits of a Community ~Through My Experience at JAWS Days 2026~
seike460
PRO
0
310
プライバシー保護の理論と実践
lycorptech_jp
PRO
1
150
デジタル・デザイン構想 by Sayaka Ishizuka
y150saya
0
140
製造現場での生成AIの活用、およびエージェントAIの実装のあり方、AVEVAの取り組み
iotcomjpadmin
0
200
WebGIS AI Agentの紹介
_shimizu
0
600
どうして今サーバーサイドKotlinを選択したのか
nealle
0
150
起点・思考・出力で分解する 〜PM業務の自動化設計〜
kazu_kichi_67
2
1.2k
次世代ランサムウェア対策の考察 / 20260704 Mitsutoshi Matsuo
shift_evolve
PRO
5
1.3k
組織における AI-DLC 実践
askul
0
230
Featured
See All Featured
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
240
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
850
エンジニアに許された特別な時間の終わり
watany
107
250k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
Docker and Python
trallard
47
3.9k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
400
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
160
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
The Cost Of JavaScript in 2023
addyosmani
55
10k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
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