fastapi-cloudauth
fastapi-cloudauth copied to clipboard
Multiple scope and or combined
Currently, it is only possible to define one scope to be checked.
@app.get("/access/")
def secure_access(scope=Depends(auth.scope("role_admin"))):
return f"Hello {scope}"
What i need is some way combine (and / or) multiple scopes.
cond = {"combinator": "or", "scopes": ["role_admin", "super_admin"]}
@app.get("/access/")
def secure_access(scope=Depends(auth.scope(cond))):
return f"Hello {scope}"
What do you think?
or even better use any
or all
:
cond = {"combinator": any, "scopes": ["role_admin", "super_admin"]}
@app.get("/access/")
def secure_access(scope=Depends(auth.scope(cond))):
return f"Hello {scope}"
Thank you for your nice proposal and PR @delijati. (Sorry for late response) I highly agree with this. Your PR is awesome but complicated for me, so, I implemented simplified feature at #43. Could you see whether this satisfy your need?
LGTM; I like it. Will try to use your implementation when i have the time to test it :/