-
Notifications
You must be signed in to change notification settings - Fork 226
Description
Have you already looked into this topic?
- I've reviewed the Vizro documentation for any relevant information
- I've searched through existing issues for similar questions
- I've already searched online (e.g., Dash documentation) but couldn’t find anything helpful
Question
Hi everyone 👋!
I am looking into authentification and role-based access control of my vizro apps. I went for dash-auth and it seems it has everything I need.
When it comes to group-based access control, dash-auth offers the protected and protected_callback functions and I am looking into how to integrate them nicely into vizro.
My idea on how to approach it is to do the following:
- Create a
vizroModal component wrappingdbc.Modal - Create two Modal instances at the
vm.Dashboardlevel to be opened whenever the user is unauthentified (with a login button) or missing permissions (with a logout / sign in with another account button). - Subclass
vm.Actioninto aProtectedActionthat will call theprotectedfunction to open the right modal based on the authorization error (or none of them if the user is authorized) - Use
ProtectedActionin place ofvm.Actionall over my app (by callingadd_typeappropriately)
I am having some issues with add_type (see below) for which I would really appreciate your help, but I would mostly like to know what you think about this approach.
Code/Examples
I have made a simple example of my ProtectedAction class on PyCafe that roughly implements the protection logic. There is no Modal in that example, so we expect the Show histogram button to not do anything if clicked without permissions.
However, I am running into a pydantic issue when calling add_type:
pydantic.errors.PydanticUserError: `Tag` not provided for choice {'type': 'definition-ref', 'schema_ref': 'app.ProtectedAction:153118520'} used with `Discriminator`
Note that before trying to write a ProtectedAction, I have tested that simply wrapping protected within the action worked:
@capture("action")
def show_plot_action():
def func():
return px.histogram(df, x="sepal_width", color="species")
return protected(unauthenticated_output=None, missing_permissions_output=None, groups=["Admin"])(func)()
Thanks a lot for your help! :)
Which package?
vizro
Code of Conduct
- I agree to follow the Code of Conduct.