DAuth
Python FastAPI ABAC Realization.
Getting started
Requirements:
redis- for cache supportdatabases- for database support
Install:
pip install dauth
After installing import main functions by
from dauth import auth
Library represents function
def Policy(
subject_call: Callable,
resource_type: Any,
method: str,
check_callback: Callable,
database: Optional[Database] = None,
cache: Optional[Redis] = None
)
subject_callback- Is function that library put in FastAPIDepends. Usually function returns user which tries to work withresourceresource_type- Isstrwhich on which User tries to get accessmethod- Is API method by which working endpointcheck_callback- Is function that realize Policy's check. Function take arguments:check_callback(subject, resource_type, item_id, method, db, cache)
-
subjectis result ofDepends(subject_callback)
-
resource_typeis argument ofPolicy()
-
item_id(by default '*') is providing by FastAPI decorator@app.get(/test/{item_id})
-
methodis argument ofPolicy()
-
dbis database connection
-
cacheis redis connection
database- Is a database connecioncache- Is a Redis connection
Examples
Simple usage
from fastapi import FastAPI, Depends
from dauth import auth
app = FastAPI()
def is_admin(subject, resource_type, item_id, method, db, cache):
if 'admin' not in subject.scopes:
raise auth.DENY
@app.get("/test")
# function get_user_auth returns User's object
def test(
user = Depends(auth.Policy(
get_user_auth,
'test',
'get',
is_admin
))
):
return {"message":"Good"}
@app.get("/test_with_db")
# function get_database returns Databases connection
def test_db(
user = Depends(auth.Policy(
get_user_auth,
'test',
'get',
is_admin,
database=Depends(get_database)
))
):
return {"message":"Good"}
@app.get("/test_with_cache")
# function get_cache returns Redis connection
def test_cache(
user = Depends(auth.Policy(
get_user_auth,
'test',
'get',
is_admin,
cache=Depends(get_cache)
))
):
return {"message":"Good"}
Developed by DenVilk
Metadata
Release files for dauth 0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dauth-0.7.tar.gz | 2.4 kB | Without provenance | Details |
Release files / dauth-0.7.tar.gz
| Download URL | dauth-0.7.tar.gz |
|---|---|
| Size | 2.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20bcf61e3fc91e041a2b8df3d031992f9078ba46ba08f5331e0867f08c34ae3d
|
|
BLAKE2b-256 checksum How to use checksums |
a3121ec127361426ea223c291130f73ca23c3b1cc1815bbf93236e25fc239192
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for dauth 0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.