Google Firebase integration for flask. Forked from klokantech/flask-firebase
Project description
Flask-Firebase
Google Firebase integration for Flask. At this moment, only the authentication subsystem is supported.
The extension works in two modes: development and production.
In development, there is no communication with the Firebase
system, accounts sign-in with a simple email form. The mode
depends on the Flask.debug variable.
Configuration
FIREBASE_API_KEY: The API key.FIREBASE_PROJECT_ID: The project identifier, eg.foobar.FIREBASE_AUTH_SIGN_IN_OPTIONS: Comma-separated list of enabled providers.
Providers
emailfacebookgithubgoogletwitter
Sample code
from flask import Flask, request
from flask_firebase import FirebaseAuth
from flask_login import LoginManager, UserMixin, login_user, logout_user
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config.from_object(...)
db = SQLAlchemy(app)
auth = FirebaseAuth(app)
login_manager = LoginManager(app)
app.register_blueprint(auth.blueprint, url_prefix='/auth')
class Account(UserMixin, db.Model):
__tablename__ = 'accounts'
account_id = db.Column(db.Integer, primary_key=True)
firebase_user_id = db.Column(db.Text, unique=True)
email = db.Column(db.Text, unique=True, nullable=False)
email_verified = db.Column(db.Boolean, default=False, nullable=False)
name = db.Column(db.Text)
photo_url = db.Column(db.Text)
@auth.production_loader
def production_sign_in(token):
account = Account.query.filter_by(firebase_user_id=token['sub']).one_or_none()
if account is None:
account = Account(firebase_user_id=token['sub'])
db.session.add(account)
account.email = token['email']
account.email_verified = token['email_verified']
account.name = token.get('name')
account.photo_url = token.get('picture')
db.session.flush()
login_user(account)
db.session.commit()
@auth.development_loader
def development_sign_in(email):
login_user(Account.query.filter_by(email=email).one())
@auth.unloader
def sign_out():
logout_user()
@login_manager.user_loader
def load_user(account_id):
return Account.query.get(account_id)
@login_manager.unauthorized_handler
def authentication_required():
return auth.url_for('widget', mode='select', next=request.url)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_firebase-1.7.tar.gz.
File metadata
- Download URL: flask_firebase-1.7.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
756d1d2f2a7b7477a629eb6080c0124780bc60aa7575e843a1f4f54145a28b7c
|
|
| MD5 |
e9c17c8669a7297eefe35b406b002659
|
|
| BLAKE2b-256 |
365325db9e25ca1425ed04a63d603ddedd44a300fabd6e1e3122621710eb687a
|
File details
Details for the file flask_firebase-1.7-py3-none-any.whl.
File metadata
- Download URL: flask_firebase-1.7-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6c4aabb306da76c58437d4fb0c2905a385d0811c254ed7aa7fdec8775f674f5
|
|
| MD5 |
4930e6cdc1540112d4e76b48bfbf5a01
|
|
| BLAKE2b-256 |
54924257705a71f9af041a50e3b7743d354ef4f82aada29ce5b3e3a8248864cb
|