FastAPI ABAC authorization realization
Project description
DAuth
Python FastAPI ABAC Realization.
Getting started
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
)
subject_callback
- Is function that library put in FastAPIDepends
. Usually function returns user which tries to work withresource
resource_type
- Isstr
which 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)
-
subject
is result ofDepends(subject_callback)
-
resource_type
is argument ofPolicy()
-
item_id
(by default '*') is providing by FastAPI decorator@app.get(/test/{item_id})
-
method
is argument ofPolicy()
Examples
Simple usage
from fastapi import FastAPI, Depends
from dauth import auth
app = FastAPI()
def is_admin(subject, resource_type, item_id, method):
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"}
Developed by DenVilk
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
dauth-0.1.tar.gz
(2.2 kB
view hashes)