fastapi-cloudauth icon indicating copy to clipboard operation
fastapi-cloudauth copied to clipboard

Multiple scope and or combined

Open delijati opened this issue 3 years ago • 3 comments

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?

delijati avatar Apr 08 '21 16:04 delijati

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}"

delijati avatar Apr 12 '21 13:04 delijati

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?

tokusumi avatar May 24 '21 18:05 tokusumi

LGTM; I like it. Will try to use your implementation when i have the time to test it :/

delijati avatar May 25 '21 09:05 delijati