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
@app.route('/profile', methods=['GET']) | |
def access_restricted_content(): | |
session_cookie = flask.request.cookies.get('session') | |
try: | |
decoded_claims = auth.verify_session_cookie(session_cookie, check_revoked=True) | |
# Can access the same claims as the ID tokens. | |
return flask.render_template('profile.html', uid=decoded_claims['sub']) | |
except Exception: | |
return flask.redirect('/') |
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
@app.route('/sessionTerm', methods=['GET']) | |
def session_terminate(): | |
response = flask.make_response(flask.redirect('/')) | |
response.set_cookie('session', expires=0) | |
return response |
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 firebase_admin import auth | |
users = [ | |
auth.ImportUserRecord( | |
uid='some-uid', | |
display_name='John Doe', | |
email='[email protected]', | |
photo_url='http://www.example.com/photo.png', | |
email_verified=True, | |
provider_data=[ |
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
users = [ | |
auth.ImportUserRecord( | |
uid='uid1', | |
email='[email protected]', | |
password_hash=b'password_hash_1', | |
password_salt=b'salt1' | |
), | |
auth.ImportUserRecord( | |
uid='uid2', | |
email='[email protected]', |
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
result = auth.import_users(users) | |
print('Successfully imported {0} users. Failed to import {1} users.'.format( | |
result.success_count, result.failure_count)) | |
for err in result.errors: | |
print('Failed to import {0} due to {1}'.format(users[err.index].uid, err.reason)) |
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
const admin = require('firebase-admin'); | |
# Load the service account JSON file | |
const serviceAccount = require('./service_account.json'); | |
# Inject into the Admin SDK as a credential | |
admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount), | |
}); |
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
const admin = require('firebase-admin'); | |
admin.initializeApp(); |
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
const admin = require('firebase-admin'); | |
admin.initializeApp(); | |
admin.auth().createCustomToken('testuid').then((token) => { | |
console.log('Custom token created:', token); | |
}).catch((err) => { | |
console.log('Error:', err); | |
}); |
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: requirements.txt | |
firebase-admin |
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: main.py | |
import firebase_admin | |
from firebase_admin import db | |
import flask | |
firebase_admin.initialize_app(options={ | |
'databaseURL': 'https://<DB_NAME>.firebaseio.com', | |
}) | |
SUPERHEROES = db.reference('superheroes') |