I want to be able to do something like this:
from fastapi import FastAPI, Request
app = FastAPI()
def on_permissions(request: Request = Depends()):
pass
@app.get("/{user_id}", dependencies=[Depends(OnReadUser)]
def read_user(user_id: int):
return crud_user.get(id=user_id)
I need to use the request in a dependency function. The goal is to create a permission/access control list and use it to authorize the user to use an endpoint based on the request fields and the permissions.
If that's not possible, is there a way to get the endpoint path like what is described here: https://github.com/tiangolo/fastapi/issues/486 , but before sending it to the endpoint itself?
@Kludex Did you find a solution? Would want to use Request in dependency function too
@HarrySky You don't need to use Depends() on Request, just use like:
def on_permissions(request: Request):
pass
Because you're already passing the request from the endpoint :)
Thanks for reporting back and closing the issue :+1: :cake:
Most helpful comment
@HarrySky You don't need to use
Depends()onRequest, just use like:Because you're already passing the request from the endpoint :)