Flask Casbin Integration
Project description
Flask-Casbin
Flask-Casbin is an extension that provide Casbin ACL functionality to your Flask project
Installation
Install Flask-Casbin with pip:
pip install Flask-Casbin
Install Flask-Casbin with poetry:
poetry add Flask-Casbin
Example
This is an example Flask application:
from flask import Flask, abort
from flask_casbin import CasbinManager, IOAdapter, current_enforcer
app = Flask(__name__)
# config
app.config["CASBIN_MODEL_CONF"] = "./model.conf"
acl = CasbinManager(app)
@acl.policy_loader
def load_policy():
# some readable object for example based on current user
return IOAdapter(current_user.policy())
@app.route('/data/<id_:int>')
def get_data(id_):
# curent_user ist global authenticated user
current_enforcer.enforce(f"user:{current_user.name}", f"data:{id}", "read") or abort(401)
# Get data
data = db.get_data(id_)
return { data_id: data.id, data: data.payload }
Todo
- Decorators for ACL check
Policy adaptersDynamic Policy Adapter (Flask-SQLAlchemy)- More tests
Resources
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
Flask-Casbin-0.3.1.tar.gz
(7.2 kB
view details)
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-Casbin-0.3.1.tar.gz.
File metadata
- Download URL: Flask-Casbin-0.3.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.8.6 Linux/5.11.16-arch1-1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d192633415d4dce71398ef6df0de7e7e290629bdfb1093b92561e76c0556f143
|
|
| MD5 |
36fccc351ec46029b65654bb909a8da8
|
|
| BLAKE2b-256 |
bad3c617dd0940a860a6d795922ab92d4e95225826e0e854ad8152057fff89cb
|
File details
Details for the file Flask_Casbin-0.3.1-py3-none-any.whl.
File metadata
- Download URL: Flask_Casbin-0.3.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.8.6 Linux/5.11.16-arch1-1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dd0f5e098e9abc9d3c46e60bbcb0175758bdaaae6504a9a6e3cf9fa353f277d
|
|
| MD5 |
acca338a1a1e6465b3364ccfa3d38080
|
|
| BLAKE2b-256 |
dc8f3e980c7f3ec1ed41f847e0c6ed97250aed230ce7424a2444bff02336b99b
|