Skip to content

About CRUD Permissions #47

Answered by awtkns
Faridalim asked this question in Q&A
Mar 24, 2021 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

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 ava…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@Faridalim
Comment options

@awtkns
Comment options

@awtkns
Comment options

@Faridalim
Comment options

Answer selected by awtkns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants