Firebase for Flask
Project description
Flask Firebase Admin
Add Firebase (a Firebase Admin app) to a Flask application.
Installation
pip install flask-firebase-admin
Quickstart
In the simplest case, let's protect a route, specifically, we'll require a user to provide a firebase jwt to one of our routes:
from flask import Flask
from flask_firebase_admin import FirebaseAdmin
app = Flask(__name__)
firebase = FirebaseAdmin(app) # uses GOOGLE_APPLICATION_CREDENTIALS
@app.route("/unprotected")
def unprotected():
return {"message": "Hello from unprotected route!"}
@app.route("/protected")
@firebase.jwt_required # This route now requires authorization via firebase jwt
def protected():
return {"message": "Hello from protected route!"}
if __name__ == "__main__":
app.run(debug=True)
Assuming the code above is located in a module named app.py
, start the Flask application:
GOOGLE_APPLICATION_CREDENTIALS="/path/to/service_account.json" python app.py
And in a separate terminal window, ping the unprotected route:
$ curl http://127.0.0.1:5000/unprotected
{
"message": "Hello from unprotected route!"
}
Looks good. Now the protected route:
$ curl http://127.0.0.1:5000/protected
{
"error": {
"message": "No credentials provided"
}
}
OK, makes sense. Now with some credentials:
$ TOKEN="your-firebase-token ..."
$ curl -H "Authorization: JWT ${TOKEN}" http://127.0.0.1:5000/protected
{
"message": "Hello from protected route!"
}
Excellent. We now have a application with routes (one route) which require the user to provide their Firebase JWT!
request.user
- configuration
- sample with explicitly providing service account
- changing authorization scheme
- other config
- aliased modules
Project details
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
Close
Hashes for flask-firebase-admin-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62f4713aa453b0a38d9769861a4c88c2d30f0abda6cefe91904092252087cda3 |
|
MD5 | 5ddc77c48eb1592423b21c8a67b1c712 |
|
BLAKE2b-256 | dc18ee95eeb880c4aeab22a491552480c5a85dcce1d7deb3c4c08efba5937575 |
Close
Hashes for flask_firebase_admin-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 286e5d2f867889c93291a0e1669e6033cf63e92e537bc9a44d6645f0f0467029 |
|
MD5 | e7c76aeab2fc9a56c1354b45fc2e516d |
|
BLAKE2b-256 | 02f4c74e3593e9e6216f3577f4f59075e8fc1b1a71edb104bfb250d15d2cae59 |