-
Hi, could you guide me how to implement fastapi-crudrouter with JWT scope? Or maybe a way to limit some CRUD routes to some roles? Thank you very much |
Beta Was this translation helpful? Give feedback.
Answered by
awtkns
Mar 25, 2021
Replies: 1 comment 4 replies
-
Hi there. Currently you can limit CRUD routes to some roles by adding a dependency (Docs) to your router. eg: from fastapi import FastAPI, testclient, Depends
from fastapi.security import OAuth2PasswordBearer
from fastapi_crudrouter import MemoryCRUDRouter
app = FastAPI()
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="auth/token")
def token_auth(token: str):
if not token:
raise HTTPException(401, "Invalid token")
router = MemoryCRUDRouter(schema=Potato, dependencies=[Depends(token_auth)])
app.include_router(router) If you are trying to limit just individual routes to certain scopes (eg: just the delete all route), there is currently no way to do that, However it will be available in a future release. |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
awtkns
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there. Currently you can limit CRUD routes to some roles by adding a dependency (Docs) to your router. eg:
If you are trying to limit just individual routes to certain scopes (eg: just the delete all route), there is currently no way to do that, However it will be ava…