This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "google.golang.org/api/iterator" | |
client, err := app.Auth(context.Background()) | |
if err != nil { | |
log.Fatal(err) | |
} | |
// Iterating by pages, 1000 users at a time. | |
pager := iterator.NewPager(client.Users(context.Background(), ""), 1000, "") | |
for { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean grantModeratorRole(String uid) throws Exception { | |
FirebaseAuth auth = FirebaseAuth.getInstance(); | |
UserRecord user = auth.getUserAsync(uid).get(); | |
if (user.isEmailVerified()) { | |
Map<String, Object> claims = new HashMap<>(); | |
claims.put("role", "moderator"); | |
claims.put("level", 5); | |
auth.setCustomUserClaimsAsync(uid, claims).get(); | |
return true; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rules": { | |
"moderators": { | |
".read": "auth.token.role === 'moderator'", | |
".write": "auth.token.role === 'moderator'" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
firebase.auth().currentUser.getIdToken() | |
.then((idToken) => { | |
// Parse the ID token. | |
const payload = JSON.parse(b64DecodeUnicode(idToken.split('.')[1])); | |
var role = payload['role']; | |
if (role == 'moderator') { | |
showModeratorUI(); | |
} else { | |
showArticleFeed(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File: superheroes.py | |
import firebase_admin | |
from firebase_admin import db | |
import flask | |
app = flask.Flask(__name__) | |
firebase_admin.initialize_app(options={ | |
'databaseURL': 'https://<DB_NAME>.firebaseio.com' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Spider-Man", | |
"realName": "Peter Parker", | |
"since": 1962, | |
"powers": [ | |
"wall crawling", | |
"web shooters", | |
"spider senses", | |
"super human stregth & agility" | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rooms": { | |
"one": { | |
"title": "Historical Tech Pioneers", | |
"createdAt": 1459361875666 | |
}, | |
"two": { }, | |
}, | |
"members": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import islice | |
import firebase_admin | |
from firebase_admin import credentials | |
from firebase_admin import db | |
from firebase_admin import firestore | |
def _split(data, size=500): | |
"""Splits a dictionary into a sequence of smaller dictionaries.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import firebase_admin | |
from firebase_admin import credentials | |
from firebase_admin import db | |
from firebase_admin import firestore | |
# Helper functions removed for brevity. | |
# Full implementation at: https://gist.github.com/hiranya911/7cb8408bc24cfda39473b09244bc906c | |
if __name__ == '__main__': | |
cred = credentials.Certificate('path/to/service_account.json') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var admin = require('firebase-admin'); | |
var serviceAccount = require('path/to/service_account.json'); | |
admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount), | |
databaseURL: 'https://database-name.firebaseio.com' | |
}); |