diff --git a/app/api/api_v1/routers/auth.py b/app/api/api_v1/routers/auth.py index b1a12f67..fb245baa 100644 --- a/app/api/api_v1/routers/auth.py +++ b/app/api/api_v1/routers/auth.py @@ -16,7 +16,9 @@ # TODO: We should use maybe use middleware for this see: PDCT-410 -def check_user_auth(request: Request, token: str = Depends(oauth2_scheme)) -> None: +async def check_user_auth( + request: Request, token: str = Depends(oauth2_scheme) +) -> None: """ Checks the current user (id'd by the token) is authorised for the request. @@ -28,6 +30,20 @@ def check_user_auth(request: Request, token: str = Depends(oauth2_scheme)) -> No entity = auth_service.path_to_endpoint(request.scope["path"]) operation = auth_service.http_method_to_operation(request.scope["method"]) + payload = await request.json() if len(await request.body()) > 0 else False + _LOGGER.info( + f"AUDIT: {user.email} is performing {operation} on {entity}", + extra={ + "props": { + "request": request.scope["path"], + "user": user.email, + "op": operation, + "entity": entity, + "payload": payload if payload else "null", + } + }, + ) + try: auth_service.is_authorised(user, entity, operation) except AuthorisationError as e: