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
Metadata
Release files for flask-casbin 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| Flask-Casbin-0.3.1.tar.gz | 7.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Flask_Casbin-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.4 kB
Release files / Flask-Casbin-0.3.1.tar.gz
| Download URL | Flask-Casbin-0.3.1.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d192633415d4dce71398ef6df0de7e7e290629bdfb1093b92561e76c0556f143
|
|
BLAKE2b-256 checksum How to use checksums |
bad3c617dd0940a860a6d795922ab92d4e95225826e0e854ad8152057fff89cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.8.6 Linux/5.11.16-arch1-1
|
Release files / Flask_Casbin-0.3.1-py3-none-any.whl
| Download URL | Flask_Casbin-0.3.1-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1dd0f5e098e9abc9d3c46e60bbcb0175758bdaaae6504a9a6e3cf9fa353f277d
|
|
BLAKE2b-256 checksum How to use checksums |
dc8f3e980c7f3ec1ed41f847e0c6ed97250aed230ce7424a2444bff02336b99b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.8.6 Linux/5.11.16-arch1-1
|